답안 #173578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173578 2020-01-04T16:23:38 Z juggernaut Bigger segments (IZhO19_segments) C++14
73 / 100
1500 ms 15460 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,tree[2000001];
pair<int,int>dp[500001];
void update(int v,int l,int r,int pos,int val){
      if(l==pos&&r==pos){
            tree[v]=val;
            return;
      }
      int mid=(l+r)>>1;
      if(pos<=mid)update((v<<1),l,mid,pos,val);
      else update((v<<1)+1,mid+1,r,pos,val);
      tree[v]=min(tree[(v<<1)],tree[(v<<1)+1]);
}
int get(int v,int l,int r,int ql,int qr){
      if(ql<=l&&r<=qr)return tree[v];
      if(r<ql||qr<l)return 1e15;
      int mid=(l+r)>>1;
      return min(get((v<<1),l,mid,ql,qr),get((v<<1)+1,mid+1,r,ql,qr));
}
main(){
    scanf("%lld",&n);
    for(i=1;i<=n;i++){
        scanf("%lld",&pref[i]);
        pref[i]+=pref[i-1];
    }
    for(i=1;i<=n;i++){
        /*for(j=1;j<=i;j++)
            if(pref[i]-pref[j-1]>=dp[j-1].sc)dp[i]={dp[j-1].fr+1,pref[i]-pref[j-1]};*/
        l=0,r=i-1;
        while(l<r){
            m=(l+r+1)>>1;
            if(pref[i]>=get(1,0,n,m,i-1))l=m;
            else r=m-1;
        }
        dp[i]={dp[l].fr+1,pref[i]-pref[l]};
        update(1,0,n,i,dp[i].sc+pref[i]);
    }
    printf("%lld",dp[n].fr);
}

Compilation message

segments.cpp:25:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
segments.cpp: In function 'int main()':
segments.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
segments.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&pref[i]);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 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 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 372 KB Output is correct
23 Correct 2 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
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 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 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 372 KB Output is correct
23 Correct 2 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
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 14 ms 504 KB Output is correct
32 Correct 8 ms 504 KB Output is correct
33 Correct 8 ms 476 KB Output is correct
34 Correct 8 ms 496 KB Output is correct
35 Correct 8 ms 504 KB Output is correct
36 Correct 8 ms 504 KB Output is correct
37 Correct 7 ms 504 KB Output is correct
38 Correct 6 ms 376 KB Output is correct
39 Correct 8 ms 504 KB Output is correct
40 Correct 8 ms 504 KB Output is correct
41 Correct 8 ms 504 KB Output is correct
42 Correct 8 ms 504 KB Output is correct
43 Correct 8 ms 504 KB Output is correct
44 Correct 8 ms 504 KB Output is correct
45 Correct 8 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 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 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 372 KB Output is correct
23 Correct 2 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
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 14 ms 504 KB Output is correct
32 Correct 8 ms 504 KB Output is correct
33 Correct 8 ms 476 KB Output is correct
34 Correct 8 ms 496 KB Output is correct
35 Correct 8 ms 504 KB Output is correct
36 Correct 8 ms 504 KB Output is correct
37 Correct 7 ms 504 KB Output is correct
38 Correct 6 ms 376 KB Output is correct
39 Correct 8 ms 504 KB Output is correct
40 Correct 8 ms 504 KB Output is correct
41 Correct 8 ms 504 KB Output is correct
42 Correct 8 ms 504 KB Output is correct
43 Correct 8 ms 504 KB Output is correct
44 Correct 8 ms 504 KB Output is correct
45 Correct 8 ms 504 KB Output is correct
46 Correct 363 ms 4904 KB Output is correct
47 Correct 382 ms 4960 KB Output is correct
48 Correct 377 ms 4992 KB Output is correct
49 Correct 375 ms 4984 KB Output is correct
50 Correct 375 ms 5112 KB Output is correct
51 Correct 380 ms 5136 KB Output is correct
52 Correct 166 ms 2808 KB Output is correct
53 Correct 90 ms 1912 KB Output is correct
54 Correct 371 ms 4984 KB Output is correct
55 Correct 377 ms 5112 KB Output is correct
56 Correct 373 ms 5068 KB Output is correct
57 Correct 385 ms 4984 KB Output is correct
58 Correct 377 ms 5004 KB Output is correct
59 Correct 372 ms 4988 KB Output is correct
60 Correct 374 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 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 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 372 KB Output is correct
23 Correct 2 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
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 14 ms 504 KB Output is correct
32 Correct 8 ms 504 KB Output is correct
33 Correct 8 ms 476 KB Output is correct
34 Correct 8 ms 496 KB Output is correct
35 Correct 8 ms 504 KB Output is correct
36 Correct 8 ms 504 KB Output is correct
37 Correct 7 ms 504 KB Output is correct
38 Correct 6 ms 376 KB Output is correct
39 Correct 8 ms 504 KB Output is correct
40 Correct 8 ms 504 KB Output is correct
41 Correct 8 ms 504 KB Output is correct
42 Correct 8 ms 504 KB Output is correct
43 Correct 8 ms 504 KB Output is correct
44 Correct 8 ms 504 KB Output is correct
45 Correct 8 ms 504 KB Output is correct
46 Correct 363 ms 4904 KB Output is correct
47 Correct 382 ms 4960 KB Output is correct
48 Correct 377 ms 4992 KB Output is correct
49 Correct 375 ms 4984 KB Output is correct
50 Correct 375 ms 5112 KB Output is correct
51 Correct 380 ms 5136 KB Output is correct
52 Correct 166 ms 2808 KB Output is correct
53 Correct 90 ms 1912 KB Output is correct
54 Correct 371 ms 4984 KB Output is correct
55 Correct 377 ms 5112 KB Output is correct
56 Correct 373 ms 5068 KB Output is correct
57 Correct 385 ms 4984 KB Output is correct
58 Correct 377 ms 5004 KB Output is correct
59 Correct 372 ms 4988 KB Output is correct
60 Correct 374 ms 4992 KB Output is correct
61 Execution timed out 1542 ms 15460 KB Time limit exceeded
62 Halted 0 ms 0 KB -