Submission #537417

#TimeUsernameProblemLanguageResultExecution timeMemory
537417maomao90Kpart (eJOI21_kpart)C++17
10 / 100
2085 ms720 KiB
// Hallelujah, praise the one who set me free // Hallelujah, death has lost its grip on me // You have broken every chain, There's salvation in your name // Jesus Christ, my living hope #include <bits/stdc++.h> using namespace std; template <class T> inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;} template <class T> inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;} #define REP(i, s, e) for (int i = s; i < e; i++) #define RREP(i, s, e) for (int i = s; i >= e; i--) typedef long long ll; typedef long double ld; #define MP make_pair #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; #define MT make_tuple typedef tuple<int, int, int> iii; #define ALL(_a) _a.begin(), _a.end() #define pb push_back typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; #ifndef DEBUG #define cerr if (0) cerr #endif #define INF 1000000005 #define LINF 1000000000000000005ll #define MAXN 1005 #define MAXA 100005 int t; int n; int a[MAXN]; bool valid[MAXN]; int dp[MAXA]; int main() { #ifndef DEBUG ios::sync_with_stdio(0), cin.tie(0); #endif cin >> t; while (t--) { cin >> n; REP (i, 0, n) { cin >> a[i]; } REP (i, 1, n + 1) { valid[i] = 0; } REP (k, 2, n + 1) { if (valid[k]) continue; int sm = 0; REP (i, 0, k) { sm += a[i]; } if (sm % 2 == 1) { continue; } bool pos = 1; REP (i, k, n) { if (a[i] % 2 != a[i % k] % 2) { pos = 0; break; } } if (!pos) continue; cerr << k << '\n'; memset(dp, 0, sizeof dp); dp[0] = 1; sm = 0; auto add = [&] (int x) { sm += x; RREP (i, MAXA - 1, x) { dp[i] += dp[i - x]; } }; auto remove = [&] (int x) { sm -= x; REP (i, x, MAXA) { dp[i] -= dp[i - x]; } }; REP (i, 0, k) { add(a[i]); } REP (i, 0, n - k + 1) { if (!dp[sm / 2]) { pos = 0; break; } if (i == n - k) continue; remove(a[i]); add(a[i + k]); } if (!pos) continue; for (int i = k; i <= n; i += k) { valid[i] = 1; } } vi ans; REP (k, 2, n + 1) { if (valid[k]) { ans.pb(k); } } cout << ans.size(); for (int i : ans) { cout << ' ' << i; } cout << '\n'; } return 0; } /* 2 7 7 3 5 1 3 3 5 6 1 2 3 5 8 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...