Submission #592947

# Submission time Handle Problem Language Result Execution time Memory
592947 2022-07-09T21:40:06 Z TimDee Kpart (eJOI21_kpart) C++14
30 / 100
2000 ms 221128 KB
#include <bits/stdc++.h>
using namespace std;
 
#define paiu return
#define moment 0;
 
#define int long long
#define double long double
#define ll long long

#define forr(i,x) for (int i=0; i<x; i++)
#define forn(i,x) for (int i=0; i<x; i++)

#define vi(a,n) vector<int> a(n,0)
 
//cringe define
#define vii(a,n) vi(a,n); forr(i,n) cin>>a[i];
vector<int> ___makeprefsum(vector<int>&a) {
    int n=a.size();
    vi(pr,n+1);
    forn(i,n) pr[i+1]=pr[i]+a[i];
    return pr;
}
#define prefsum(pr,a) vector<int> pr=___makeprefsum(a);
 
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
 
#define pb(x) push_back(x)
#define pf pop_front();
#define last(c) c[c.size()-1]
 
#define f first
#define s second
 
#define pi pair<int, int>
#define mp(x,y) make_pair(x, y)
 
const ll mod = 1000000007;
const double ppi = acos(0) * 2;
     
const int maxn = 2e5;
const int inf = INT_MAX;
const ll linf = LLONG_MAX;
const ll mmod = 998244353;

bool foo(pair<pi,int>&a, pair<pi,int>&b) {
    if (a.f.f>b.f.f) return 1;
    else if (a.f.f<b.f.f) return 0;
    else return a.f.s>b.f.s;
}

void solve() {
    
    int n; cin>>n; vii(a,n);
    vector<vector<int>> dp(n,vector<int>(5e4+3,-1));
    forn(i,n) dp[i][a[i]]=i;

    //forn(i,n) {
    //    forn(j,30) cout<<dp[i][j]<<' '; cout<<'\n';
    //}

    for (int i=1; i<n; ++i) {
        for (int j=1; j<=5e4; ++j) {
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
            if (j-a[i]>=0) dp[i][j]=max(dp[i][j],dp[i-1][j-a[i]]);
        }
    }

    //forn(i,n) {
    //    forn(j,30) cout<<dp[i][j]<<' '; cout<<'\n';
    //}

    vector<int> ans;
    vector<int> pr = ___makeprefsum(a);
    for (int k=2; k<=n; ++k) {
        int foo=1;
        for (int i=0; i+k<=n; ++i) {
            int s = pr[i+k]-pr[i];
            if (s%2) {foo=0; break;}
            if (dp[i+k-1][s/2]<i) {foo=0; break;}
        }
        if (foo) ans.pb(k);
    }
    cout<<ans.size()<<' ';
    forn(i,ans.size()) cout<<ans[i]<<' '; cout<<'\n';
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
    //init_primes();
    
    int t=1;
    cin>>t;
    while(t--) solve();
    
    paiu moment
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:12:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define forn(i,x) for (int i=0; i<x; i++)
......
   86 |     forn(i,ans.size()) cout<<ans[i]<<' '; cout<<'\n';
      |          ~~~~~~~~~~~~             
Main.cpp:86:5: note: in expansion of macro 'forn'
   86 |     forn(i,ans.size()) cout<<ans[i]<<' '; cout<<'\n';
      |     ^~~~
Main.cpp:12:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   12 | #define forn(i,x) for (int i=0; i<x; i++)
      |                   ^~~
Main.cpp:86:5: note: in expansion of macro 'forn'
   86 |     forn(i,ans.size()) cout<<ans[i]<<' '; cout<<'\n';
      |     ^~~~
Main.cpp:86:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   86 |     forn(i,ans.size()) cout<<ans[i]<<' '; cout<<'\n';
      |                                           ^~~~
# Verdict Execution time Memory Grader output
1 Correct 101 ms 12544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 273 ms 26936 KB Output is correct
2 Correct 505 ms 46528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 968 ms 100816 KB Output is correct
2 Correct 1723 ms 150708 KB Output is correct
3 Correct 1782 ms 170248 KB Output is correct
4 Execution timed out 2085 ms 221128 KB Time limit exceeded
5 Halted 0 ms 0 KB -