Submission #635761

# Submission time Handle Problem Language Result Execution time Memory
635761 2022-08-26T19:07:19 Z deme_bz Kpart (eJOI21_kpart) C++14
100 / 100
1545 ms 197316 KB
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define eb emplace_back
#define sz(x) (int)x.size()
using namespace std;
const int N=1e3+1,MAX=5e4;
 
vector <int> pre(N+1,0);
vector < vector<int> > ind(N+1,vector <int> (MAX+1, 0));
void test_case(){
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		int a;
		cin >> a;
		pre[i]=pre[i-1]+a;
		for(int j=0;j<=MAX;j++){
			ind[i][j]=ind[i-1][j];
			if(j==a){
				ind[i][j]=i;
			}
			else
			if(j>a){
				ind[i][j]=max(ind[i][j],ind[i-1][j-a]);
			}
		}
	}
	vector <int> ans;
	for(int k=1;k<=n;k++){
		bool B=true;
		for(int l=1;l<=n-k+1;l++){
			int r=l+k-1;
			int sum=pre[r]-pre[l-1];
			if(sum%2!=0 || ind[r][sum/2]<l){
				B=false;
				break;
			}
		}
		if(B){
			ans.pb(k);
		}
	}
	//cout << endl;
	cout << ans.size() << " ";
	for(auto to : ans){
		cout << to << " ";
	}
	cout << endl;
}

int main(){

    int T = 1;
    cin >> T;
    while(T--){
        test_case();
    }
}

Compilation message

Main.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 104 ms 197224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 197188 KB Output is correct
2 Correct 266 ms 197196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 398 ms 197228 KB Output is correct
2 Correct 643 ms 197196 KB Output is correct
3 Correct 642 ms 197232 KB Output is correct
4 Correct 868 ms 197264 KB Output is correct
5 Correct 1260 ms 197296 KB Output is correct
6 Correct 1545 ms 197316 KB Output is correct
7 Correct 1468 ms 197192 KB Output is correct