Submission #1533260


Source Code Expand

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>

#define MOD 1000000007
#define ll long long
#define ld long double

using namespace std;

//l<rは必ず成り立つ、
ll cal(int l, int r, int mid){
  //mid < l < r
  if(mid<=l && l<=r){//l~rまでの和
    ll left = l-mid;
    ll right = r-mid;
    ll re = 0;
    for(ll i = left; i<= right;i++){
      re+=i;
    }
    return re;
  }

  //l < mid < r
  else if(l<=mid && mid<=r){
    ll left = mid-l;
    ll right = r-mid;
    ll re = 0;
    for(ll i = 0;i<= left ; i++){
      re+=i;
    }
    for(ll i =0;i<=right; i++){
      re+=i;
    }

    return re;
  }

  //l < r < mdi
  else if(l<=r && r<=mid){
    ll left = mid-l;
    ll right = mid-r;
    ll re=0;
    for(ll i = right;i<= left;i++){
      re+=i;
    }
    return re;
  }

}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int R,G,B;
  cin >> R >> G >> B;//左、真ん中、右
  if(B>R) swap(B,R);//左の数が常に右より多くなる
  int rl,rr, gl,gr, bl,br;//それぞれの色の左、右側

  //真ん中を自分(0)中心に、配置する。
  //偶数の場合、右が一つ多くなる(自分の中心にも一つはおいてるはず。)
  gl = (0-(G-1)/2);
  gr = gl+G-1;

  //次に、重い左の部分を自分(-100)中心に、配置する.
  rl = (-100-(R-1)/2);
  rr = rl+R-1;
  //ただし、中央と重なる時もありうる
  if(rr>=gl){//重なると
    //RとGの総数を足して、両方の中心を中心に、配置する。
    rl = (-50-(R+G-1)/2);
    rr = rl+R-1;
    gl = rr+1;
    gr = gl+G-1;
  }

  //最後に、右を自分(100)中心に、配置する。
  bl = (100-(B-1)/2);
  br = bl+B-1;
  //同じく、右がもし中央と重なったら、全体再配置する。
  //この時、右が少なめになってるので、重なってるなら、左も必ず重なってる。左も再配置しましょう
  if(gr>=bl){
    rl = (0-(R+G+B-1)/2);
    rr = rl+R-1;
    gl = rr+1;
    gr = gl+G-1;
    bl = gr+1;
    br = bl + B -1;
  }
  ll re = 10e8;

  for(ll i = -1000;i<=1000;i++){
    ll result = 0;
    result += cal(rl+i, rr+i, -100);
    result += cal(gl+i, gr+i,    0);
    result += cal(bl+i, br+i,  100);
    if(result < re) re = result;
  }
  cout << re << endl;


  
  return 0;
}

Submission Info

Submission Time
Task A - 流行
User ukohank517
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2492 Byte
Status WA
Exec Time 1228 ms
Memory 256 KB

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
WA × 28
Set Name Test Cases
All 00_sample_00.txt, max_1000000.txt, min_0.txt, rand_133007.txt, rand_171937.txt, rand_172717.txt, rand_232508.txt, rand_242450.txt, rand_246841.txt, rand_269046.txt, rand_320433.txt, rand_435534.txt, rand_50616.txt, rand_537196.txt, rand_565439.txt, rand_601980.txt, rand_622146.txt, rand_624081.txt, rand_678601.txt, rand_696476.txt, rand_762274.txt, rand_798714.txt, rand_821336.txt, rand_85323.txt, rand_859632.txt, rand_921203.txt, rand_934508.txt, rand_993594.txt
Case Name Status Exec Time Memory
00_sample_00.txt WA 2 ms 256 KB
max_1000000.txt WA 1228 ms 256 KB
min_0.txt WA 1 ms 256 KB
rand_133007.txt WA 163 ms 256 KB
rand_171937.txt WA 211 ms 256 KB
rand_172717.txt WA 212 ms 256 KB
rand_232508.txt WA 286 ms 256 KB
rand_242450.txt WA 298 ms 256 KB
rand_246841.txt WA 303 ms 256 KB
rand_269046.txt WA 331 ms 256 KB
rand_320433.txt WA 394 ms 256 KB
rand_435534.txt WA 535 ms 256 KB
rand_50616.txt WA 61 ms 256 KB
rand_537196.txt WA 662 ms 256 KB
rand_565439.txt WA 695 ms 256 KB
rand_601980.txt WA 740 ms 256 KB
rand_622146.txt WA 765 ms 256 KB
rand_624081.txt WA 768 ms 256 KB
rand_678601.txt WA 834 ms 256 KB
rand_696476.txt WA 857 ms 256 KB
rand_762274.txt WA 935 ms 256 KB
rand_798714.txt WA 983 ms 256 KB
rand_821336.txt WA 1006 ms 256 KB
rand_85323.txt WA 104 ms 256 KB
rand_859632.txt WA 1057 ms 256 KB
rand_921203.txt WA 1132 ms 256 KB
rand_934508.txt WA 1145 ms 256 KB
rand_993594.txt WA 1217 ms 256 KB