답안 #885592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885592 2023-12-10T09:05:55 Z kokoue Bigger segments (IZhO19_segments) C++14
13 / 100
1500 ms 2396 KB
#include<bits/stdc++.h>
#define MAXN 500010
using namespace std;
long long a[MAXN];
long long pre[1000000];
int n;
int binary(int l,int goal)
{
    int r=n;
    int start=l;
    int mid;
    while(l!=r && l<r)
    {
        mid=(l+r)/2;
        if(pre[mid]-pre[start]==goal) return mid;
        if(pre[mid]-pre[start]<goal)
        {
            l=mid+1;
        }
        else r=mid;
    }
    return r;
}
int dfs(int curr, long long sum, int cntr)
{
  //  for(int i=0;i<cntr;i++) printf("  ");
    //printf("in--> cntr(%d)=idx(%d), sum=%d; ",cntr,curr,sum);
    if(curr>n) return 0;
 //   printf("in--> cntr(%d)=idx(%d), sum=%d; \n",cntr,curr,sum);
  //  printf("in curr=%d,sum=%d,cntr=%d\n ",curr,sum,cntr);
    long long nsum=0;
    int ans=cntr;
    ans=max(ans,dfs(curr+1,sum+a[curr+1],cntr));
    int idx=binary(curr,sum);
    if(idx>curr)
    {
  //      printf("idx%d = %d ",cntr,idx);
        if(pre[idx]-pre[curr]>=sum)ans=max(ans,dfs(idx,pre[idx]-pre[curr],cntr+1));
       // ans=max(ans,dfs(idx+1,pre[idx+1]-pre[curr-1],cntr+1));
    }
   // printf("out\n");
  //  printf("in curr=%d,sum=%d,cntr=%d -> ans=%d\n",curr,sum,cntr,ans);
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        pre[i]=pre[i-1]+a[i];
    }/*
    for(int i=0;i<=n;i++)
    {
        printf("%d ",pre[i]);
    }
    printf("\n");*/
    cout<<dfs(1,a[1],1)<<"\n";
}

Compilation message

segments.cpp: In function 'int dfs(int, long long int, int)':
segments.cpp:31:15: warning: unused variable 'nsum' [-Wunused-variable]
   31 |     long long nsum=0;
      |               ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Execution timed out 1547 ms 2396 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Execution timed out 1547 ms 2396 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Execution timed out 1547 ms 2396 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Execution timed out 1547 ms 2396 KB Time limit exceeded
18 Halted 0 ms 0 KB -