제출 #1280619

#제출 시각아이디문제언어결과실행 시간메모리
1280619bahaktlKpart (eJOI21_kpart)C++20
100 / 100
848 ms8324 KiB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define int long long

const int N = 1e6+10;
const int inf = 1e18;

int dp[N];

signed main() {         
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int T;
    cin>>T;
    while(T--) {
        int n;
        cin>>n;
        int a[n+1];
        int pref[n+1];
        pref[0]=0;
        int ans[n+1];
        int x=0;
        for(int i=1;i<=n;i++) {
            cin>>a[i];
            pref[i]=pref[i-1]+a[i];
            ans[i]=1;
            x+=a[i];
        }
        dp[0]=0;
        for(int i=1;i<=n;i++) {
            for(int j=pref[n];j>=a[i];j--) {
                dp[j]=max(dp[j],dp[j-a[i]]);
            }
            dp[a[i]]=i;
            for(int j=1;j<=i;j++) {
                int sum=pref[i]-pref[j-1];
                if(sum%2==1) {
                    ans[i-j+1]=false;
                }
                ans[i-j+1] &= (dp[sum/2] >= j);
            }
        }
        vector<int>res;
        for(int i=2;i<=n;i++) {
            if(ans[i]) res.pb(i);
        }
        for(int i=0;i<=N;i++) dp[i]=0;
        cout<<res.size()<<' ';
        for(auto it:res) cout<<it<<' ';
        cout<<endl;
    }
}

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

Main.cpp: In function 'int main()':
Main.cpp:48:36: warning: iteration 1000010 invokes undefined behavior [-Waggressive-loop-optimizations]
   48 |         for(int i=0;i<=N;i++) dp[i]=0;
      |                               ~~~~~^~
Main.cpp:48:22: note: within this loop
   48 |         for(int i=0;i<=N;i++) dp[i]=0;
      |                     ~^~~
Main.cpp:48:36: warning: 'void* __builtin_memset(void*, int, long unsigned int)' writing 8000088 bytes into a region of size 8000080 overflows the destination [-Wstringop-overflow=]
   48 |         for(int i=0;i<=N;i++) dp[i]=0;
      |                               ~~~~~^~
Main.cpp:10:5: note: destination object 'dp' of size 8000080
   10 | int dp[N];
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...