답안 #172988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172988 2020-01-02T23:00:38 Z FieryPhoenix 쌀 창고 (IOI11_ricehub) C++11
100 / 100
32 ms 2680 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <chrono>
#include <ctime>
#include <random>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <iterator>
#include <climits>
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
#define INF 2001001001
#define MOD 1000000007

int besthub(int R, int L, int x[], ll B){
  ll X[R+1];
  int ans=1;
  for (int i=1;i<=R;i++)
    X[i]=x[i-1];
  int r=1,mid=1;
  ll cost=0;
  for (int i=1;i<=R;i++){
    while (r<=R && cost<=B){
      r++;
      if (r>R)
	break;
      int newMid=(i+r)/2;
      //cout<<mid<<' '<<newMid<<endl;
      if (newMid==mid)
	cost+=X[r]-X[mid];
      else{
        ll diff=X[newMid]-X[mid];
	cost+=(mid-i+1)*diff;
	cost-=(r-1-newMid+1)*diff;
	cost+=X[r]-X[newMid];
	mid=newMid;
      }
    }
    ans=max(ans,r-i);
    //cout<<"RANGE "<<i<<' '<<r<<" cost "<<cost<<endl;
    int newMid=(i+1+r)/2;
    //cout<<mid<<' '<<newMid<<endl;
    if (newMid==mid)
      cost-=(X[mid]-X[i]);
    else{
      ll diff=X[newMid]-X[mid];
      cost+=(mid-(i+1)+1)*diff;
      cost-=(min(r,R)-newMid+1)*diff;
      cost-=(X[mid]-X[i]);
      mid=newMid;
    }
  }
  return ans;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 252 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 252 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 252 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 380 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 248 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 760 KB Output is correct
2 Correct 5 ms 760 KB Output is correct
3 Correct 18 ms 2552 KB Output is correct
4 Correct 18 ms 2680 KB Output is correct
5 Correct 9 ms 1272 KB Output is correct
6 Correct 8 ms 1272 KB Output is correct
7 Correct 32 ms 2296 KB Output is correct
8 Correct 15 ms 2296 KB Output is correct
9 Correct 8 ms 1272 KB Output is correct
10 Correct 8 ms 1272 KB Output is correct
11 Correct 20 ms 2552 KB Output is correct
12 Correct 20 ms 2552 KB Output is correct
13 Correct 9 ms 1272 KB Output is correct
14 Correct 9 ms 1272 KB Output is correct
15 Correct 17 ms 1912 KB Output is correct
16 Correct 15 ms 2040 KB Output is correct
17 Correct 18 ms 2308 KB Output is correct
18 Correct 18 ms 2296 KB Output is correct
19 Correct 19 ms 2424 KB Output is correct
20 Correct 22 ms 2424 KB Output is correct