제출 #885581

#제출 시각아이디문제언어결과실행 시간메모리
885581kokoueBigger segments (IZhO19_segments)C++14
0 / 100
1 ms2396 KiB
#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) { 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) { // printf("idx%d = %d; ",cntr,curr); if(curr>n) return 0; // 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); 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("\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]; } cout<<dfs(1,a[1],1)<<"\n"; }

컴파일 시 표준 에러 (stderr) 메시지

segments.cpp: In function 'int dfs(int, long long int, int)':
segments.cpp:29:15: warning: unused variable 'nsum' [-Wunused-variable]
   29 |     long long nsum=0;
      |               ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...