답안 #229581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229581 2020-05-05T08:07:44 Z monus1042 쌀 창고 (IOI11_ricehub) C++17
17 / 100
34 ms 1280 KB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define ll long long

int besthub(int R, int L, int X[], long long B)	{
	int ans=1;
	ll cost=0;

	int l=0,r=0;
	for (int i=1; i<R; i++){
		if (cost + (ll)(X[i] - X[0]) <= B){
			ans++;
			cost += (ll)(X[i] - X[0]);
			r++;
		}else break;
	}
	int forward[R];
	for (int i=0; i<R; i++){
		int curr=X[i];
		int j, cnt=1;
		for (j=i; j<R && X[j] == curr; j++){
			forward[j]=cnt;
			cnt++;
		}
		j--;
		i=j;
	}

	for (int i=1; i<R; i++){
		ll dist=X[i] - X[i-1];
		if (r<i){
			r=i;
		}else{
			cost -= dist * (ll)(r-(i-1));
		}
		cost += dist * (ll)(i-l - forward[i-1] + 1);
		cost += dist * (ll)(forward[i-1] -1);
		if (cost == B) {}
		else if (cost < B){
			while(1){
				if (r+1 < R && cost + (ll)(X[r+1] - X[i]) <= B){
					cost += (ll)(X[r+1] - X[i]);
					r++;
				}else break;
			}
		}else{ // cost > B
			while(1){
				if (cost <= B) break;
				cost -= (ll)(X[i] - X[l]);
				l++;
			}
			//try to expand
			while(1){
				if (r+1 < R && cost + (ll)(X[r+1] - X[i]) <= B){
					cost += (ll)(X[r+1] - X[i]);
					r++;
				}else break;
			}
		}
		ans=max(ans, r-l+1);
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Incorrect 5 ms 256 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 360 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Incorrect 5 ms 384 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
3 Correct 20 ms 1152 KB Output is correct
4 Correct 20 ms 1152 KB Output is correct
5 Correct 11 ms 640 KB Output is correct
6 Correct 11 ms 640 KB Output is correct
7 Correct 17 ms 1280 KB Output is correct
8 Correct 18 ms 1152 KB Output is correct
9 Correct 10 ms 640 KB Output is correct
10 Correct 11 ms 640 KB Output is correct
11 Correct 24 ms 1152 KB Output is correct
12 Correct 34 ms 1184 KB Output is correct
13 Incorrect 12 ms 640 KB Output isn't correct
14 Halted 0 ms 0 KB -