답안 #151419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151419 2019-09-02T19:47:15 Z TadijaSebez 도넛 (JOI14_ho_t3) C++11
100 / 100
270 ms 3804 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200050;
int a[N];
ll sum[N];
int main()
{
	int n;
	scanf("%i",&n);
	for(int i=1;i<=n;i++) scanf("%i",&a[i]),a[i+n]=a[i];
	for(int i=1;i<=2*n;i++) sum[i]=sum[i-1]+a[i];
	ll all=sum[n],ans=0;
	function<ll(int,ll)> GetR=[&](int i, ll need)
	{
		int top=i+n-1,bot=i,mid,ans;
		while(top>=bot)
		{
			mid=top+bot>>1;
			if(sum[mid]-sum[i-1]>=need) ans=mid,top=mid-1;
			else bot=mid+1;
		}
		return sum[ans]-sum[i-1];
	};
	function<ll(int,ll)> GetL=[&](int i, ll need)
	{
		int top=i,bot=i-n+1,mid,ans;
		while(top>=bot)
		{
			mid=top+bot>>1;
			if(sum[i]-sum[mid-1]>=need) ans=mid,bot=mid+1;
			else top=mid-1;
		}
		return sum[i]-sum[ans-1];
	};
	for(int i=1,j=n;i<=n;i++)
	{
		ll top=all/3,bot=ans+1,mid;
		while(top>=bot)
		{
			mid=top+bot>>1;
			if(all-GetR(i,mid)-GetL(j,mid)>=mid) ans=mid,bot=mid+1;
			else top=mid-1;
		}
		j=i+n;
	}
	printf("%lld\n",ans);
	return 0;
}

Compilation message

2014_ho_t3.cpp: In lambda function:
2014_ho_t3.cpp:19:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    mid=top+bot>>1;
        ~~~^~~~
2014_ho_t3.cpp: In lambda function:
2014_ho_t3.cpp:30:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    mid=top+bot>>1;
        ~~~^~~~
2014_ho_t3.cpp: In function 'int main()':
2014_ho_t3.cpp:41:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    mid=top+bot>>1;
        ~~~^~~~
2014_ho_t3.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
2014_ho_t3.cpp:11:41: 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("%i",&a[i]),a[i+n]=a[i];
                        ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
2014_ho_t3.cpp: In static member function 'static _Res std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Res = long long int; _Functor = main()::<lambda(int, long long int)>; _ArgTypes = {int, long long int}]':
2014_ho_t3.cpp:23:17: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   return sum[ans]-sum[i-1];
          ~~~~~~~^
2014_ho_t3.cpp:16:27: note: 'ans' was declared here
   int top=i+n-1,bot=i,mid,ans;
                           ^~~
2014_ho_t3.cpp: In static member function 'static _Res std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Res = long long int; _Functor = main()::<lambda(int, long long int)>; _ArgTypes = {int, long long int}]':
2014_ho_t3.cpp:34:24: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   return sum[i]-sum[ans-1];
                     ~~~^~
2014_ho_t3.cpp:27:27: note: 'ans' was declared here
   int top=i,bot=i-n+1,mid,ans;
                           ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 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 3 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 376 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 3 ms 376 KB Output is correct
11 Correct 3 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 380 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 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 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 376 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 3 ms 376 KB Output is correct
11 Correct 3 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 380 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 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 6 ms 504 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 13 ms 632 KB Output is correct
27 Correct 13 ms 632 KB Output is correct
28 Correct 12 ms 764 KB Output is correct
29 Correct 13 ms 632 KB Output is correct
30 Correct 13 ms 632 KB Output is correct
31 Correct 19 ms 504 KB Output is correct
32 Correct 19 ms 504 KB Output is correct
33 Correct 19 ms 504 KB Output is correct
34 Correct 19 ms 508 KB Output is correct
35 Correct 19 ms 504 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 376 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 3 ms 376 KB Output is correct
11 Correct 3 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 380 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 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 6 ms 504 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 13 ms 632 KB Output is correct
27 Correct 13 ms 632 KB Output is correct
28 Correct 12 ms 764 KB Output is correct
29 Correct 13 ms 632 KB Output is correct
30 Correct 13 ms 632 KB Output is correct
31 Correct 19 ms 504 KB Output is correct
32 Correct 19 ms 504 KB Output is correct
33 Correct 19 ms 504 KB Output is correct
34 Correct 19 ms 508 KB Output is correct
35 Correct 19 ms 504 KB Output is correct
36 Correct 156 ms 3804 KB Output is correct
37 Correct 136 ms 3668 KB Output is correct
38 Correct 143 ms 3776 KB Output is correct
39 Correct 153 ms 3704 KB Output is correct
40 Correct 156 ms 3716 KB Output is correct
41 Correct 144 ms 3704 KB Output is correct
42 Correct 154 ms 3576 KB Output is correct
43 Correct 152 ms 3576 KB Output is correct
44 Correct 154 ms 3692 KB Output is correct
45 Correct 154 ms 3664 KB Output is correct
46 Correct 269 ms 2908 KB Output is correct
47 Correct 268 ms 2808 KB Output is correct
48 Correct 270 ms 2808 KB Output is correct