# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1089160 |
2024-09-16T06:32:52 Z |
vjudge1 |
Kpart (eJOI21_kpart) |
C++17 |
|
2000 ms |
468 KB |
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll int
#define F first
#define S second
#define ull unsigned long long
#define db double
#define ldb long double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int N = 100001;
using namespace std;
using namespace __gnu_pbds;
ll n, m, a, b, c, d, e, p[N], pr[N], dp[N];
vector <ll> ans, v;
ll gcd (ll a, ll b){while (a > 0 && b > 0){if (a >= b){a %= b;}else{b %= a;}}return a + b;}
ll binpow (ll a, ll b){
a %= mod;if (b == 0){return 1;}
else if (b % 2 == 1){
return binpow (a, b - 1) % mod * a % mod;
}
else{
ll t = binpow (a, b / 2) % mod;
return t * t % mod;
}
}
signed main (){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll tt = 1;
cin >> tt;
while (tt--){
cin >> n;
for (int i = 1; i <= n; i++){
cin >> p[i];
pr[i] = pr[i - 1] + p[i];
}
dp[0] = 1;
for (int i = 2; i <= n; i++){
b = 0;
for (int y = 1; y <= n - i + 1; y++){
if ((pr[y + i - 1] - pr[y - 1]) % 2 == 0){
a = (pr[y + i - 1] - pr[y - 1]) / 2;
v.clear();
for (int j = y; j <= y + i - 1; j++){
if (p[j] <= a)v.pb (p[j]);
}
for (int j = 0; j < v.size(); j++){
for (int k = a - v[j]; k >= 0; k--){
if (dp[k]){
dp[k + v[j]] = 1;
}
}
}
b += dp[a];
for (int k = 1; k <= a; k++){
dp[k] = 0;
}
}
else{
break;
}
}
if (b == n - i + 1){
ans.pb(i);
}
}
cout << ans.size() << ' ';
for (auto i: ans){
cout << i << ' ';
}
cout << '\n';
ans.clear();
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:62:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int j = 0; j < v.size(); j++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
312 ms |
468 KB |
Output is correct |
2 |
Execution timed out |
2032 ms |
344 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2032 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |