답안 #51759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51759 2018-06-21T03:29:45 Z model_code 도넛 (JOI14_ho_t3) C++17
100 / 100
314 ms 3836 KB
// O(N log^2 N) solution
#include<cstdio>
#include<algorithm>
using namespace std;

const int MAXN = 1000010;
typedef long long i64;

int N;
i64 A[MAXN];
i64 S[MAXN*4];

int find_next(int pos, i64 C)
{
	return upper_bound(S, S+(N*3), S[pos]+C-1) - S;
}

bool check(i64 C)
{
	for(int i=0;i<N;i++){
		int pos = i;
		pos = find_next(pos, C); if(pos > i+N) continue;
		pos = find_next(pos, C); if(pos > i+N) continue;
		pos = find_next(pos, C); if(pos > i+N) continue;
		return true;
	}

	return false;
}

int main()
{
	scanf("%d", &N);
	for(int i=1;i<=N;i++) scanf("%lld", A+i);
	S[0] = 0;
	for(int i=1;i<=N;i++) S[i] = S[i+N] = S[i+2*N] = A[i];
	for(int i=1;i<=3*N;i++) S[i] += S[i-1];

	i64 left=1, right=S[N]/3;
	while(left < right){
		i64 mid = (left+right+1)/2;

		if(check(mid)){
			left = mid;
		}else{
			right = mid-1;
		}
	}

	printf("%lld\n", left);

	return 0;
}

Compilation message

2014_ho_t3.cpp: In function 'int main()':
2014_ho_t3.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
2014_ho_t3.cpp:34:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=N;i++) scanf("%lld", A+i);
                        ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 2 ms 544 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 2 ms 544 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 3 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 2 ms 544 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 3 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 10 ms 764 KB Output is correct
22 Correct 8 ms 860 KB Output is correct
23 Correct 9 ms 860 KB Output is correct
24 Correct 8 ms 860 KB Output is correct
25 Correct 9 ms 860 KB Output is correct
26 Correct 21 ms 860 KB Output is correct
27 Correct 24 ms 860 KB Output is correct
28 Correct 22 ms 860 KB Output is correct
29 Correct 23 ms 860 KB Output is correct
30 Correct 23 ms 860 KB Output is correct
31 Correct 15 ms 860 KB Output is correct
32 Correct 16 ms 860 KB Output is correct
33 Correct 16 ms 860 KB Output is correct
34 Correct 16 ms 860 KB Output is correct
35 Correct 14 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 2 ms 544 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 3 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 10 ms 764 KB Output is correct
22 Correct 8 ms 860 KB Output is correct
23 Correct 9 ms 860 KB Output is correct
24 Correct 8 ms 860 KB Output is correct
25 Correct 9 ms 860 KB Output is correct
26 Correct 21 ms 860 KB Output is correct
27 Correct 24 ms 860 KB Output is correct
28 Correct 22 ms 860 KB Output is correct
29 Correct 23 ms 860 KB Output is correct
30 Correct 23 ms 860 KB Output is correct
31 Correct 15 ms 860 KB Output is correct
32 Correct 16 ms 860 KB Output is correct
33 Correct 16 ms 860 KB Output is correct
34 Correct 16 ms 860 KB Output is correct
35 Correct 14 ms 860 KB Output is correct
36 Correct 279 ms 3748 KB Output is correct
37 Correct 288 ms 3752 KB Output is correct
38 Correct 265 ms 3752 KB Output is correct
39 Correct 172 ms 3836 KB Output is correct
40 Correct 245 ms 3836 KB Output is correct
41 Correct 314 ms 3836 KB Output is correct
42 Correct 292 ms 3836 KB Output is correct
43 Correct 271 ms 3836 KB Output is correct
44 Correct 259 ms 3836 KB Output is correct
45 Correct 217 ms 3836 KB Output is correct
46 Correct 198 ms 3836 KB Output is correct
47 Correct 220 ms 3836 KB Output is correct
48 Correct 180 ms 3836 KB Output is correct