Submission #581530

# Submission time Handle Problem Language Result Execution time Memory
581530 2022-06-22T17:35:02 Z TimDee Kpart (eJOI21_kpart) C++14
10 / 100
2000 ms 432 KB
#include <bits/stdc++.h>
using namespace std;

#define paiu return
#define moment 0;
 
#define int long long
#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 forrr(i,j,x) for (int i=j; i<x; i++)
 
#define di(a,n) deque<int> a(n,0)
#define dll(a,n) deque<ll> a(n,0)
#define vi(a,n) vector<int> a(n,0)
#define vll(a,n) vector<ll> 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 = 3e5+1;
const int inf = INT_MAX;
const ll linf = LLONG_MAX;
const ll mmod = 998244353;

vector<vector<int>> ks(deque<int> a, int s) {

    int n = a.size();

    vector<vector<int>> dp(n+1);
    forn(i,n+1) dp[i].assign(s/2+3,0);

    dp[0][0]=1;

    for (int i=1; i<=n; i++) {
        for (int j=1; j<=s/2; j++) {
            dp[i][j]|=dp[i-1][j];
            if (j-a[i-1]>=0) dp[i][j]|=dp[i-1][j-a[i-1]];
        }
    }

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

    return dp;

}

int check(deque<int>&a, int S) {

    //if (S%2) return 0;

    set<int> s;
    s.insert(0);

    vector<int> k;
    //cout<<(s.begin()==s.end());
    forn(i,a.size()) {
        for (auto it=s.begin(); it!=s.end(); it++) {
            //cout<<*it+a[i]<<' ';
            if (s.find(*it+a[i])==s.end() && *it+a[i]<=S/2) k.pb(*it+a[i]);
        }
        //cout<<'\n';
        forn(i,k.size()) s.insert(k[i]);
        //forn(i,k.size()) cout<<k[i]<<' ';
        k.clear();
    }
    //cout<<'\n';

    if (s.find(S/2)!=s.end()) return 1;
    return 0;

}

void solve() {
    
    int n; cin>>n;
    vii(a,n);

    vector<int> ans;

    for (int k=1; k<=n; k++) {

        deque<int> b;
        int s=0;
        forn(i,k) { b.pb(a[i]); s+=a[i]; }
        int foo=1;

        //cout<<s<<' '<<b[0]<<' '<<b[max(1ll*b.size()-1,1ll)]<<'\n';

        if (s%2 || check(b,s)==0) {
            continue;
        }

        for (int i=k; i<n; i++) {
            
            b.pb(a[i]);
            s+=a[i];
            b.pop_front();
            s-=a[i-k];

            if (s%2 || check(b,s)==0) {
                foo=0;
                break;
            }

        }

        if (foo) ans.pb(k);

    }

    n=ans.size(); cout<<n<<' ';
    forn(i,n) 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 'long long int check(std::deque<long long int>&, long long int)':
Main.cpp:11:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 | #define forn(i,x) for (int i=0; i<x; i++)
......
   84 |     forn(i,a.size()) {
      |          ~~~~~~~~~~               
Main.cpp:84:5: note: in expansion of macro 'forn'
   84 |     forn(i,a.size()) {
      |     ^~~~
Main.cpp:11: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]
   11 | #define forn(i,x) for (int i=0; i<x; i++)
......
   90 |         forn(i,k.size()) s.insert(k[i]);
      |              ~~~~~~~~~~           
Main.cpp:90:9: note: in expansion of macro 'forn'
   90 |         forn(i,k.size()) s.insert(k[i]);
      |         ^~~~
Main.cpp: In function 'void solve()':
Main.cpp:11:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   11 | #define forn(i,x) for (int i=0; i<x; i++)
      |                   ^~~
Main.cpp:140:5: note: in expansion of macro 'forn'
  140 |     forn(i,n) cout<<ans[i]<<' '; cout<<'\n';
      |     ^~~~
Main.cpp:140:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  140 |     forn(i,n) cout<<ans[i]<<' '; cout<<'\n';
      |                                  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 276 ms 372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2083 ms 432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2082 ms 412 KB Time limit exceeded
2 Halted 0 ms 0 KB -