# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
173596 | 2020-01-04T16:55:42 Z | juggernaut | Bigger segments (IZhO19_segments) | C++14 | 301 ms | 94676 KB |
//Just try and the idea will come #include<bits/stdc++.h> #define int long long int #define fr first #define sc second using namespace std; int pref[500001],i,n,l,r,m,sp[500001][20],logs[500001],j; pair<int,int>dp[500001]; int get(int l,int r){ int len=logs[r-l+1]; return min(sp[l][len],sp[r-(1ll<<len)+1][len]); } main(){ for(i=2;i<500001;i++)logs[i]=logs[i>>1]+1; for(i=1;i<500001;i++) for(j=0;j<20;j++)sp[i][j]=1e15; scanf("%lld",&n); for(i=1;i<=n;i++){ scanf("%lld",&pref[i]); pref[i]+=pref[i-1]; } for(i=1;i<=n;i++){ l=0,r=i-1; while(l<r){ m=(l+r+1)>>1; if(pref[i]>=get(m,i-1))l=m; else r=m-1; } dp[i]={dp[l].fr+1,pref[i]-pref[l]}; j=1; sp[i][0]=dp[i].sc+pref[i]; while(i-(1ll<<j)+1>=0){ sp[i-(1ll<<j)+1][j]=min(sp[i-(1ll<<(j-1))+1][j-1],sp[i-(1ll<<j)+1][j-1]); j++; } } printf("%lld",dp[n].fr); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 82552 KB | Output is correct |
2 | Correct | 68 ms | 82556 KB | Output is correct |
3 | Correct | 68 ms | 82556 KB | Output is correct |
4 | Correct | 68 ms | 82552 KB | Output is correct |
5 | Correct | 69 ms | 82652 KB | Output is correct |
6 | Correct | 68 ms | 82552 KB | Output is correct |
7 | Correct | 68 ms | 82652 KB | Output is correct |
8 | Correct | 68 ms | 82524 KB | Output is correct |
9 | Correct | 69 ms | 82552 KB | Output is correct |
10 | Correct | 69 ms | 82556 KB | Output is correct |
11 | Correct | 68 ms | 82552 KB | Output is correct |
12 | Correct | 69 ms | 82552 KB | Output is correct |
13 | Correct | 67 ms | 82484 KB | Output is correct |
14 | Correct | 68 ms | 82552 KB | Output is correct |
15 | Correct | 69 ms | 82552 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 82552 KB | Output is correct |
2 | Correct | 68 ms | 82556 KB | Output is correct |
3 | Correct | 68 ms | 82556 KB | Output is correct |
4 | Correct | 68 ms | 82552 KB | Output is correct |
5 | Correct | 69 ms | 82652 KB | Output is correct |
6 | Correct | 68 ms | 82552 KB | Output is correct |
7 | Correct | 68 ms | 82652 KB | Output is correct |
8 | Correct | 68 ms | 82524 KB | Output is correct |
9 | Correct | 69 ms | 82552 KB | Output is correct |
10 | Correct | 69 ms | 82556 KB | Output is correct |
11 | Correct | 68 ms | 82552 KB | Output is correct |
12 | Correct | 69 ms | 82552 KB | Output is correct |
13 | Correct | 67 ms | 82484 KB | Output is correct |
14 | Correct | 68 ms | 82552 KB | Output is correct |
15 | Correct | 69 ms | 82552 KB | Output is correct |
16 | Correct | 68 ms | 82552 KB | Output is correct |
17 | Correct | 69 ms | 82552 KB | Output is correct |
18 | Correct | 68 ms | 82552 KB | Output is correct |
19 | Correct | 70 ms | 82528 KB | Output is correct |
20 | Correct | 68 ms | 82552 KB | Output is correct |
21 | Correct | 68 ms | 82680 KB | Output is correct |
22 | Correct | 68 ms | 82680 KB | Output is correct |
23 | Correct | 68 ms | 82592 KB | Output is correct |
24 | Correct | 72 ms | 82564 KB | Output is correct |
25 | Correct | 68 ms | 82552 KB | Output is correct |
26 | Correct | 68 ms | 82552 KB | Output is correct |
27 | Correct | 69 ms | 82612 KB | Output is correct |
28 | Correct | 69 ms | 82552 KB | Output is correct |
29 | Correct | 68 ms | 82552 KB | Output is correct |
30 | Correct | 69 ms | 82552 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 82552 KB | Output is correct |
2 | Correct | 68 ms | 82556 KB | Output is correct |
3 | Correct | 68 ms | 82556 KB | Output is correct |
4 | Correct | 68 ms | 82552 KB | Output is correct |
5 | Correct | 69 ms | 82652 KB | Output is correct |
6 | Correct | 68 ms | 82552 KB | Output is correct |
7 | Correct | 68 ms | 82652 KB | Output is correct |
8 | Correct | 68 ms | 82524 KB | Output is correct |
9 | Correct | 69 ms | 82552 KB | Output is correct |
10 | Correct | 69 ms | 82556 KB | Output is correct |
11 | Correct | 68 ms | 82552 KB | Output is correct |
12 | Correct | 69 ms | 82552 KB | Output is correct |
13 | Correct | 67 ms | 82484 KB | Output is correct |
14 | Correct | 68 ms | 82552 KB | Output is correct |
15 | Correct | 69 ms | 82552 KB | Output is correct |
16 | Correct | 68 ms | 82552 KB | Output is correct |
17 | Correct | 69 ms | 82552 KB | Output is correct |
18 | Correct | 68 ms | 82552 KB | Output is correct |
19 | Correct | 70 ms | 82528 KB | Output is correct |
20 | Correct | 68 ms | 82552 KB | Output is correct |
21 | Correct | 68 ms | 82680 KB | Output is correct |
22 | Correct | 68 ms | 82680 KB | Output is correct |
23 | Correct | 68 ms | 82592 KB | Output is correct |
24 | Correct | 72 ms | 82564 KB | Output is correct |
25 | Correct | 68 ms | 82552 KB | Output is correct |
26 | Correct | 68 ms | 82552 KB | Output is correct |
27 | Correct | 69 ms | 82612 KB | Output is correct |
28 | Correct | 69 ms | 82552 KB | Output is correct |
29 | Correct | 68 ms | 82552 KB | Output is correct |
30 | Correct | 69 ms | 82552 KB | Output is correct |
31 | Correct | 69 ms | 82536 KB | Output is correct |
32 | Correct | 69 ms | 82592 KB | Output is correct |
33 | Correct | 79 ms | 82600 KB | Output is correct |
34 | Correct | 80 ms | 82552 KB | Output is correct |
35 | Correct | 69 ms | 82680 KB | Output is correct |
36 | Correct | 69 ms | 82552 KB | Output is correct |
37 | Correct | 70 ms | 82552 KB | Output is correct |
38 | Correct | 68 ms | 82552 KB | Output is correct |
39 | Correct | 69 ms | 82524 KB | Output is correct |
40 | Correct | 68 ms | 82556 KB | Output is correct |
41 | Correct | 69 ms | 82588 KB | Output is correct |
42 | Correct | 69 ms | 82680 KB | Output is correct |
43 | Correct | 68 ms | 82552 KB | Output is correct |
44 | Correct | 69 ms | 82612 KB | Output is correct |
45 | Correct | 68 ms | 82552 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 82552 KB | Output is correct |
2 | Correct | 68 ms | 82556 KB | Output is correct |
3 | Correct | 68 ms | 82556 KB | Output is correct |
4 | Correct | 68 ms | 82552 KB | Output is correct |
5 | Correct | 69 ms | 82652 KB | Output is correct |
6 | Correct | 68 ms | 82552 KB | Output is correct |
7 | Correct | 68 ms | 82652 KB | Output is correct |
8 | Correct | 68 ms | 82524 KB | Output is correct |
9 | Correct | 69 ms | 82552 KB | Output is correct |
10 | Correct | 69 ms | 82556 KB | Output is correct |
11 | Correct | 68 ms | 82552 KB | Output is correct |
12 | Correct | 69 ms | 82552 KB | Output is correct |
13 | Correct | 67 ms | 82484 KB | Output is correct |
14 | Correct | 68 ms | 82552 KB | Output is correct |
15 | Correct | 69 ms | 82552 KB | Output is correct |
16 | Correct | 68 ms | 82552 KB | Output is correct |
17 | Correct | 69 ms | 82552 KB | Output is correct |
18 | Correct | 68 ms | 82552 KB | Output is correct |
19 | Correct | 70 ms | 82528 KB | Output is correct |
20 | Correct | 68 ms | 82552 KB | Output is correct |
21 | Correct | 68 ms | 82680 KB | Output is correct |
22 | Correct | 68 ms | 82680 KB | Output is correct |
23 | Correct | 68 ms | 82592 KB | Output is correct |
24 | Correct | 72 ms | 82564 KB | Output is correct |
25 | Correct | 68 ms | 82552 KB | Output is correct |
26 | Correct | 68 ms | 82552 KB | Output is correct |
27 | Correct | 69 ms | 82612 KB | Output is correct |
28 | Correct | 69 ms | 82552 KB | Output is correct |
29 | Correct | 68 ms | 82552 KB | Output is correct |
30 | Correct | 69 ms | 82552 KB | Output is correct |
31 | Correct | 69 ms | 82536 KB | Output is correct |
32 | Correct | 69 ms | 82592 KB | Output is correct |
33 | Correct | 79 ms | 82600 KB | Output is correct |
34 | Correct | 80 ms | 82552 KB | Output is correct |
35 | Correct | 69 ms | 82680 KB | Output is correct |
36 | Correct | 69 ms | 82552 KB | Output is correct |
37 | Correct | 70 ms | 82552 KB | Output is correct |
38 | Correct | 68 ms | 82552 KB | Output is correct |
39 | Correct | 69 ms | 82524 KB | Output is correct |
40 | Correct | 68 ms | 82556 KB | Output is correct |
41 | Correct | 69 ms | 82588 KB | Output is correct |
42 | Correct | 69 ms | 82680 KB | Output is correct |
43 | Correct | 68 ms | 82552 KB | Output is correct |
44 | Correct | 69 ms | 82612 KB | Output is correct |
45 | Correct | 68 ms | 82552 KB | Output is correct |
46 | Correct | 94 ms | 84932 KB | Output is correct |
47 | Correct | 99 ms | 84856 KB | Output is correct |
48 | Correct | 100 ms | 84856 KB | Output is correct |
49 | Correct | 103 ms | 84828 KB | Output is correct |
50 | Correct | 102 ms | 84984 KB | Output is correct |
51 | Correct | 104 ms | 84856 KB | Output is correct |
52 | Correct | 86 ms | 83704 KB | Output is correct |
53 | Correct | 78 ms | 83192 KB | Output is correct |
54 | Correct | 97 ms | 84884 KB | Output is correct |
55 | Correct | 100 ms | 84856 KB | Output is correct |
56 | Correct | 96 ms | 84984 KB | Output is correct |
57 | Correct | 98 ms | 84856 KB | Output is correct |
58 | Correct | 97 ms | 84864 KB | Output is correct |
59 | Correct | 97 ms | 84856 KB | Output is correct |
60 | Correct | 98 ms | 84856 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 82552 KB | Output is correct |
2 | Correct | 68 ms | 82556 KB | Output is correct |
3 | Correct | 68 ms | 82556 KB | Output is correct |
4 | Correct | 68 ms | 82552 KB | Output is correct |
5 | Correct | 69 ms | 82652 KB | Output is correct |
6 | Correct | 68 ms | 82552 KB | Output is correct |
7 | Correct | 68 ms | 82652 KB | Output is correct |
8 | Correct | 68 ms | 82524 KB | Output is correct |
9 | Correct | 69 ms | 82552 KB | Output is correct |
10 | Correct | 69 ms | 82556 KB | Output is correct |
11 | Correct | 68 ms | 82552 KB | Output is correct |
12 | Correct | 69 ms | 82552 KB | Output is correct |
13 | Correct | 67 ms | 82484 KB | Output is correct |
14 | Correct | 68 ms | 82552 KB | Output is correct |
15 | Correct | 69 ms | 82552 KB | Output is correct |
16 | Correct | 68 ms | 82552 KB | Output is correct |
17 | Correct | 69 ms | 82552 KB | Output is correct |
18 | Correct | 68 ms | 82552 KB | Output is correct |
19 | Correct | 70 ms | 82528 KB | Output is correct |
20 | Correct | 68 ms | 82552 KB | Output is correct |
21 | Correct | 68 ms | 82680 KB | Output is correct |
22 | Correct | 68 ms | 82680 KB | Output is correct |
23 | Correct | 68 ms | 82592 KB | Output is correct |
24 | Correct | 72 ms | 82564 KB | Output is correct |
25 | Correct | 68 ms | 82552 KB | Output is correct |
26 | Correct | 68 ms | 82552 KB | Output is correct |
27 | Correct | 69 ms | 82612 KB | Output is correct |
28 | Correct | 69 ms | 82552 KB | Output is correct |
29 | Correct | 68 ms | 82552 KB | Output is correct |
30 | Correct | 69 ms | 82552 KB | Output is correct |
31 | Correct | 69 ms | 82536 KB | Output is correct |
32 | Correct | 69 ms | 82592 KB | Output is correct |
33 | Correct | 79 ms | 82600 KB | Output is correct |
34 | Correct | 80 ms | 82552 KB | Output is correct |
35 | Correct | 69 ms | 82680 KB | Output is correct |
36 | Correct | 69 ms | 82552 KB | Output is correct |
37 | Correct | 70 ms | 82552 KB | Output is correct |
38 | Correct | 68 ms | 82552 KB | Output is correct |
39 | Correct | 69 ms | 82524 KB | Output is correct |
40 | Correct | 68 ms | 82556 KB | Output is correct |
41 | Correct | 69 ms | 82588 KB | Output is correct |
42 | Correct | 69 ms | 82680 KB | Output is correct |
43 | Correct | 68 ms | 82552 KB | Output is correct |
44 | Correct | 69 ms | 82612 KB | Output is correct |
45 | Correct | 68 ms | 82552 KB | Output is correct |
46 | Correct | 94 ms | 84932 KB | Output is correct |
47 | Correct | 99 ms | 84856 KB | Output is correct |
48 | Correct | 100 ms | 84856 KB | Output is correct |
49 | Correct | 103 ms | 84828 KB | Output is correct |
50 | Correct | 102 ms | 84984 KB | Output is correct |
51 | Correct | 104 ms | 84856 KB | Output is correct |
52 | Correct | 86 ms | 83704 KB | Output is correct |
53 | Correct | 78 ms | 83192 KB | Output is correct |
54 | Correct | 97 ms | 84884 KB | Output is correct |
55 | Correct | 100 ms | 84856 KB | Output is correct |
56 | Correct | 96 ms | 84984 KB | Output is correct |
57 | Correct | 98 ms | 84856 KB | Output is correct |
58 | Correct | 97 ms | 84864 KB | Output is correct |
59 | Correct | 97 ms | 84856 KB | Output is correct |
60 | Correct | 98 ms | 84856 KB | Output is correct |
61 | Correct | 255 ms | 94284 KB | Output is correct |
62 | Correct | 286 ms | 94540 KB | Output is correct |
63 | Correct | 290 ms | 94588 KB | Output is correct |
64 | Correct | 285 ms | 94588 KB | Output is correct |
65 | Correct | 275 ms | 94568 KB | Output is correct |
66 | Correct | 301 ms | 94532 KB | Output is correct |
67 | Correct | 254 ms | 92104 KB | Output is correct |
68 | Correct | 147 ms | 87416 KB | Output is correct |
69 | Correct | 260 ms | 94632 KB | Output is correct |
70 | Correct | 284 ms | 94500 KB | Output is correct |
71 | Correct | 251 ms | 94540 KB | Output is correct |
72 | Correct | 271 ms | 94492 KB | Output is correct |
73 | Correct | 266 ms | 94584 KB | Output is correct |
74 | Correct | 262 ms | 94456 KB | Output is correct |
75 | Correct | 272 ms | 94676 KB | Output is correct |