Search is not available for this dataset
name
stringlengths
2
88
description
stringlengths
31
8.62k
public_tests
dict
private_tests
dict
solution_type
stringclasses
2 values
programming_language
stringclasses
5 values
solution
stringlengths
1
983k
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long inf = 1000000; const int N = 300000; vector<int> tree(2 * N + 4); vector<int> ranks(2 * N + 4, 0); char str[N + 4]; int find(int x) { return x == tree[x] ? x : tree[x] = find(tree[x]); } void link(int x, int y) { if (ranks[x] > ranks[y]) { tree[y] = x; } e...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long ans = 0; long long val[600010]; int have[600010][2], fa[600010]; char str[600010]; int n, k; int find(int x) { return x == fa[x] ? x : (fa[x] = find(fa[x])); } int other(int u) { return u <= k ? u + k : u - k; } void update(int u, long long x, long long y) { ans...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline int read() { int w = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { w = (w << 3) + (w << 1) + ch - 48; ch = getchar(); } return w * f; } int n, m, f...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, k, s, x, op[N][2]; char ch[N]; int p[N << 1], val[N << 1]; int find(int u) { return p[u] == u ? p[u] : p[u] = find(p[u]); } void uni(int a, int b) { if (a == b) return; val[b] += val[a]; p[a] = b; } int main() { scanf("%d%d%s...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 7; using ll = long long; string s; int n, k; int fa[maxn]; vector<int> st[maxn]; const int inf = 0x3f3f3f3f; ll sz[maxn]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } void Union(int x, int y) { x = find(x), y = find(y); if (x !...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; int dp[maxn][2], fa[maxn * 2], cnt[maxn * 2], n, k; char buf[maxn]; int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); } int calc(int x) { int y = (x <= k ? x + k : x - k); x = Find(x), y = Find(y); if (x == 0 || y == 0) return cnt...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] == u ? fa[u] : fa[u] = find(fa[u]); } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)]...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9 + 5; const int N = 600010; class DSU { public: int p[N], cost[N]; int n; int ans = 0; DSU(int _n) : n(_n) { for (int i = 0; i < n; i++) { cost[2 * i + 1] = 1; cost[2 * i] = 0; } cost[2 * n] = inf; cost[2 * n + 1]...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 10; int f[maxn], n, k, w[maxn]; vector<int> v[maxn]; int Find(int x) { return f[x] == x ? x : f[x] = Find(f[x]); } int ask(int x) { int y = (x <= k) ? x + k : x - k; x = Find(x); y = Find(y); if (x == 0) return w[y]; else if (y == 0) ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct DS { int rank, cost, parent; bool forced; } ds[4 * 300100]; int ans; char status[300100]; vector<int> subs[300100]; int neg(int n) { return n + 300100; } int find(int n) { if (n == ds[n].parent) return n; return ds[n].parent = find(ds[n].parent); } void join(...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long llINF = 2e18, llMOD = 1e9 + 7; const int INF = 2e9, MOD = 1e9 + 7, P = 179, N = 2e3 + 1, K = 23000, L = 18; const long double EPS = 1e-6, ldINF = 1e18, PI = acos(-1); template <typename T> inline void sort_uniq(vector<T>& v) { sort(v.begin(), v.end()); v...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long MX = 1e6, INF = 1e9 + 10; vector<long long> v[MX]; long long par[MX], s0[MX], s1[MX], col[MX], ans = 0; pair<long long, long long> GETPAR(long long v) { if (par[v] == v) return {v, 0}; pair<long long, long long> ans = GETPAR(par[v]); return {par[v] = a...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int test = 0; const int MAXN = 300009; const long long MOD = 119 << 23 | 1; class { public: vector<int> V[MAXN]; int fa[MAXN * 2], cnt[MAXN * 2]; int n, m; int findfa(int x) { if (fa[x] == x) return x; return fa[x] = findfa(fa[x]); } void merge(int x, i...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-10; const int MOD = 998857459; const int INF = 0x3f3f3f3f; const int maxn = 3e5 + 10; const int maxm = 5e6 + 10; int n, k, op[maxn][2], p[maxn << 2]; long long val[maxn << 2]; char str[maxn]; int find(int first) { return...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9 + 7; class DSU { private: vector<int> comp, siz; vector<int> tp; vector<int> onc, offc; public: DSU(int n) : comp(n), siz(n, 1), tp(n, 0), onc(n, 0), offc(n, 1) { for (int i = 0; i < n; ++i) comp[i] = i; offc[n - 1] = INF; } p...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] == u ? fa[u] : fa[u] = find(fa[u]); } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)]...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool umax(T& a, const T& b) { return a < b ? a = b, true : false; } template <long long sz> using tut = array<long long, sz>; const long long N = 3e5 + 5; const lon...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 7; int n, k; string s; int l[maxn][2], r[maxn], cnt[maxn]; int getroot(int x) { return r[x] == x ? x : r[x] = getroot(r[x]); } int calc(int x) { int y = x <= k ? x + k : x - k; x = getroot(x); y = getroot(y); if (x == 0 || y == 0) { return...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; vector<int> g[maxn]; int f[maxn], d[maxn], L[maxn], R[maxn], fix[maxn], gt[maxn], ans = 0; int n, k; char str[maxn]; int calc(int x) { if (fix[x]) return gt[x] ? R[x] : L[x]; else return min(L[x], R[x]); } int find(int x) { if (f[x] ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using ll = long long; using namespace std; const int maxn = 6e5 + 5; int fa[maxn], val[maxn], ans; vector<int> V[maxn]; int n, k; string s; void init() { for (int i = 0; i < maxn; ++i) fa[i] = i; } int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); } void merge(int x, int y) { ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> enum class LampConstraint { Distinct, Same }; enum class LampSetState { On, Off, PhantomA, PhantomB }; bool isLampSetStateKnown(LampSetState st) { return st == LampSetState::On || st == LampSetState::Off; } typedef struct Edge { int nodeId; LampConstraint cons; Edge(int nodeId_, LampCon...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct perem { int t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); int n, k, m, c, vas, vvas, cc = 1000000, kl; string s; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> n >> k >> s; vector<vector<int>> la(n, v...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct DS { int n; vector<int> s; vector<int> count; DS(int n) : n(n), s(n, -1), count(n, 0) {} int find(int i) { return s[i] < 0 ? i : (s[i] = find(s[i])); } int counted(int i) { return count[find(i)]; } void mark(int i, int x) { count[find(i)] += x; } int ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int inf = 0x3f3f3f3f; const int MAXN = 0x7fffffff; const long long INF = 0x3f3f3f3f3f3f3f3fLL; void file() {} const int N = 3e5 + 5; int fat[N * 2], Size[N * 2], n, k; vector<int> vec[N]; int find(int x) { return fat[x] == x ? x : fat[x] ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int lim = 1000 * 1000 + 5; int nbElem, nbSub; vector<int> subset[lim]; int side[lim]; int isIn[lim][2]; string ini; int rep = 0; int drepr[lim]; int dsz[lim]; int cnt[lim][2]; int dfind(int x) { if (drepr[x] != x) drepr[x] = dfind(drepr[x...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 5; int pre[N], si[N], num[N / 2], n, m; bool vis[N]; char s[N]; vector<vector<int> > v(N / 2); int findd(int x) { if (pre[x] == x) return x; pre[x] = findd(pre[x]); if (vis[x]) vis[pre[x]] = 1; return pre[x]; } inline int id(int x) { return x > m...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; int dp[maxn][2], fa[maxn * 2], cnt[maxn * 2], n, k; char buf[maxn]; int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); } int calc(int x) { int y; if (x <= k) y = x + k; else y = x - k; x = Find(x), y = Find(y); if (x ==...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<int> v[600005]; int k; int mx[600005], a[300005], fa[600005]; int find(int x) { if (fa[x] != x) { fa[x] = find(fa[x]); } return fa[x]; } void mer(int x, int y) { int fx = find(x), fy = find(y); if (fx != fy) { mx[fx] += mx[fy]; fa[fy] = fx; } ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 10; const long long inf = 1e9 + 10; int f[N], vist[N]; char s[N]; long long val[N]; vector<int> vec[N]; int find(int x) { if (f[x] == x) return x; f[x] = find(f[x]); return f[x]; } void myunion(int x, int y) { if (x < y) { f[y] = x; val[x...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] ? fa[u] = find(fa[u]) : u; } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)] = find(b...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, m, k, x; vector<int> vec[300010]; char c[300010]; int fa[300010 << 1], sz[300010 << 1]; int lim[300010 << 1]; int find(int x) { if (fa[x] == x) return x; return fa[x] = find(fa[x]); } int main() { scanf("%d%d%s", &n, &k, c + 1); for (int i = 1; i <= k; i++) {...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int val[300000 + 100], sum[300000 + 100][2], head[300000 + 100]; int f[300000 + 100]; vector<int> V[300000 + 100]; int n, k; int ans; int findd(int x) { if (f[x] == x) return x; int F = f[x]; f[x] = findd(f[x]); val[x] = val[x] ^ val[F]; return f[x]; } char s[3000...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, k; string s; vector<int> a[300001]; int p[1000001]; long long f[1000001]; const int Max = 6e5; const int T = 3e5; int root(int u) { if (u == p[u]) return u; return p[u] = root(p[u]); } void Merge(int u, int v) { u = root(u); v = root(v); int ru = root(u); ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 6E5 + 10; int n, k, l[N][2]; int fa[N], sc[N]; string s; int find(int x) { if (x == fa[x]) return x; return fa[x] = find(fa[x]); } int cal(int x) { int y = x <= k ? x + k : x - k; int xx = find(x), yy = find(y); if (xx == 0 || yy == 0) return sc[xx +...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
java
import java.util.*; import java.io.*; import java.math.*; public class Solution { public static void main(String[] args) throws IOException { //PrintWriter out = new PrintWriter(new File("out.txt")); PrintWriter out = new PrintWriter(System.out); //Reader in = new Reader(new FileInputStrea...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 300000 + 10; const int apsz = 26; const int INF = 10000007; const unsigned long long mod = 97; const int maxm = 10000 + 10; struct rev { int c0, c1, tag; void maintain() { c0 = min(c0, INF); c1 = min(c1, INF); } }; rev info[maxn]; int dsu[maxn...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] == u ? fa[u] : fa[u] = find(fa[u]); } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)]...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] == u ? fa[u] : fa[u] = find(fa[u]); } void uni(int a, int b) { if (a == b) return; val[b] += val[a]; fa[a] = b; } int mix(int a) { retur...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAXN = 810000; int fa[MAXN], val[MAXN], vec[MAXN][3]; int n, k, ans; char str[MAXN]; int getfa(int x) { if (fa[x] == x) return x; return fa[x] = getfa(fa[x]); } void merge(int x, int y) { int p = getfa(x), q = getfa(y); if (p == q) return; fa[p] = q; v...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 69; int n, k; string initial; int dsu[N]; int sz[N]; int szsame[N]; int parity[N]; int restrict[N]; vector<int> belong[N]; int curr = 0; int getVal(int u) { if (restrict[u] == 0) return szsame[u]; if (restrict[u] == 1) return (sz[u] - szsame[u]); r...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } inline long long read1(...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long n, k, pa[600010], ct[600010], siz[600010], ans = 0; vector<long long> g[300010]; string s; long long find(long long x) { if (x == pa[x]) return x; pa[x] = find(pa[x]); ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = (int)3e5 + 10; int par[maxn << 1], num[maxn << 1]; inline void makeSet(int size) { for (int i = 1; i <= size; i++) { par[i] = i; } } inline int find(int x) { int k, j, r; r = x; while (r != par[r]) { r = par[r]; } k = x; while (k != ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10, inf = 0x3f3f3f3f; int n, K, m, x, pos[N][2], ans, fa[N], val[N]; char s[N]; int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); } void add(int x, int y) { int fx = getfa(x), fy = getfa(y); if (fx != fy) fa[fx] = fy, val[fy] += val[fx...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct perem { long long t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); long long n, k, m, c, vas, cc = 1000000; vector<long long> vv; string s; vector<vector<long long>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.ti...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { x = 0; char c = getchar(); bool f = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void wr...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] ? fa[u] = find(fa[u]) : u; } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)] = find(b...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 300000 + 10; char s[N]; int par[N], diff[N]; pair<int, int> find(int x) { if (par[x] == x) return {x, 0}; auto r = find(par[x]); par[x] = r.first, diff[x] ^= r.second; return {par[x], diff[x]}; } int f[N][2], col[N], ans; int get(int x) { if (col[x] ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
python3
from sys import stdin input = stdin.readline n , k = [int(i) for i in input().split()] pairs = [i + k for i in range(k)] + [i for i in range(k)] initial_condition = list(map(lambda x: x == '1',input().strip())) data = [i for i in range(2*k)] constrain = [-1] * (2*k) h = [0] * (2*k) L = [1] * k + [0] * k dp1 = [-1 for...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int test = 0; const int MAXN = 300009; const long long MOD = 119 << 23 | 1; class { public: vector<int> V[MAXN]; int fa[MAXN * 2], cnt[MAXN * 2]; int n, m; int curset[MAXN * 2], ans; int findfa(int x) { if (fa[x] == x) return x; return fa[x] = findfa(fa[x...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct perem { int t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); int n, k, m, c, vas, cc = 1000000, kl; vector<int> vv; string s; vector<vector<int>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0);...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; const int INF = 1e9 + 7; struct node { int l, r; node(int _l = 0, int _r = 0) : l(_l), r(_r){}; void operator+=(node x) { l = min(l + x.l, INF); r = min(r + x.r, INF); } int get() { return min(l, r); } } val[N]; int root[N], rev[N];...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] ? fa[u] = find(fa[u]) : u; } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)] = find(b...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> template <class V> int get_p(V& p, int j) { if (p[j] == j) return j; if (p[j] < 0) return p[j] = -get_p(p, -p[j]); return p[j] = get_p(p, p[j]); } int get_min(bool a_j, int S_j, bool coa_j, int coS_j) { if (!coa_j) return S_j; if (!a_j) return coS_j; return std::min(S_j, coS_j); } v...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long maxn = 300005; const long long inf = 1ll << 50; int ans = 0; bool init[maxn]; int par[maxn], sz[maxn], cnt[maxn][2], col[maxn]; vector<int> vec[maxn]; int find(int x) { if (par[x] == x) { return x; } par[x] = find(...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct perem { int t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); int n, k, m, c, vas, cc = 1000000, kl; vector<int> vv; string s; vector<vector<int>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0);...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9 + 5; const int N = 600010; class DSU { public: int p[N], cost[N]; int n; int ans = 0; DSU(int _n) : n(_n) { for (int i = 0; i < N / 2; i++) { cost[2 * i + 1] = 1; cost[2 * i] = 0; } cost[2 * n] = inf; cost[2 * n ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct perem { long long t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); long long n, k, m, c, vas, cc = 1000000; vector<long long> vv; string s; vector<vector<long long>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.ti...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e6 + 100; const int mod = (int)1e9 + 7; int n, k, fa[maxn], tot[maxn], ans; char s[maxn]; vector<int> v[maxn]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } void join(int x, int y) { x = find(x); y = find(y); if (x != y) fa[x]...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct UF { vector<int> e; UF(int n) : e(n, -1) {} int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); } bool join(int a, int b) { a = find(a), b = find(b); if (a == b) return false; if (e[a] > e[b]) swap(a, b); e[a] += e[b]; e[b] = a; ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long sz[300009], par[300009]; long long res; long long n, k; std::vector<long long> pos[300009]; long long getparent(long long x) { if (par[x] == x) return x; return par[x] = getparent(par[x]); } void merge(long long x, long long y) { long long p1 = getparent(x);...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 5; int pre[N], si[N], num[N / 2], n, m; bool vis[N]; char s[N]; vector<vector<int> > v(N / 2); int findd(int x) { if (pre[x] == x) return x; return pre[x] = findd(pre[x]); } inline int id(int x) { return x > m ? x - m : x; } int un(int a, int b) { ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, m, k, x; vector<int> vec[300010]; char c[300010]; int fa[300010 << 1], sz[300010 << 1]; int lim[300010]; int find(int x) { if (fa[x] == x) return x; return fa[x] = find(fa[x]); } int main() { scanf("%d%d%s", &n, &k, c + 1); for (int i = 1; i <= k; i++) { ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct perem { int t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); long long n, k, m, c, vas, cc = 10000000; vector<long long> vv; string s; vector<vector<long long>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct perem { long long t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); long long n, k, m, c, vas, kl, cc = 1000000; vector<long long> vv; string s; vector<vector<long long>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cou...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, m; char s[630000]; int fa[630000]; int val[630000]; vector<int> belong[630000]; int Push(int x) { return x; } int Unpush(int x) { return m + x; } int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } void merge(int x, int y) { int u = find(x), v = find(y...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long llINF = 2e18, llMOD = 1e9 + 7; const int INF = 2e9, MOD = 1e9 + 7, P = 179, N = 2e3 + 1, K = 23000, L = 18; const long double EPS = 1e-6, ldINF = 1e18, PI = acos(-1); template <typename T> inline void sort_uniq(vector<T>& v) { sort(v.begin(), v.end()); v...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long sz[300009], par[300009]; long long res; long long n, k; std::vector<long long> pos[300009]; long long getparent(long long x) { if (par[x] == x) return x; return par[x] = getparent(par[x]); } void merge(long long x, long long y) { long long p1 = getparent(x);...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] ? fa[u] = find(fa[u]) : u; } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)] = find(b...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long llINF = 2e18, llMOD = 1e9 + 7; const int INF = 2e9, MOD = 1e9 + 7, P = 179, N = 2e3 + 1, K = 23000, L = 18; const long double EPS = 1e-6, ldINF = 1e18, PI = acos(-1); template <typename T> inline void sort_uniq(vector<T>& v) { sort(v.begin(), v.end()); v...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long inf = 1000000; const int N = 300000; vector<int> tree(2 * N); vector<int> ranks(2 * N, 0); char str[N]; int find(int x) { return x == tree[x] ? x : tree[x] = find(tree[x]); } void link(int x, int y) { if (ranks[x] > ranks[y]) { tr...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9 + 5; const int N = 600010; class DSU { public: int p[N], cost[N]; int n; int ans = 0; DSU(int _n) : n(_n) { for (int i = 0; i < n; i++) { cost[2 * i + 1] = 1; cost[2 * i] = 0; } cost[2 * n] = inf; cost[2 * n + 1]...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 5; int pre[N], si[N], num[N / 2], n, m; bool vis[N]; char s[N]; vector<vector<int> > v(N / 2); int findd(int x) { if (pre[x] == x) return x; pre[x] = findd(pre[x]); if (vis[x]) vis[pre[x]] = 1; return pre[x]; } inline int id(int x) { return x > m...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> template <class V> int get_p(V& p, int j) { if (p[j] == j) return j; if (p[j] < 0) return p[j] = -get_p(p, -p[j]); return p[j] = get_p(p, p[j]); } int get_min(bool a_j, int S_j, bool coa_j, int coS_j) { if (!coa_j) return S_j; if (!a_j) return coS_j; return std::min(S_j, coS_j); } t...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct UF { vector<int> e; UF(int n) : e(n, -1) {} int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); } bool join(int a, int b) { a = find(a), b = find(b); if (a == b) return false; if (e[a] > e[b]) swap(a, b); e[a] += e[b]; e[b] = a; ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define endl '\n' #define pb push_back #define ub upper_bound #define lb lower_bound...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct DS { int rank, cost, parent; bool forced; } ds[4 * 300100]; int ans; char status[300100]; vector<int> subs[300100]; int neg(int n) { return n + 300100; } int find(int n) { if (n == ds[n].parent) return n; return ds[n].parent = find(ds[n].parent); } void join(...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct perem { long long t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); long long n, k, m, c, vas, cc = 1000000; vector<long long> vv; string s; vector<vector<long long>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); fin.tie(0); cout.ti...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; char op[300005]; int n, k, fa[300005], v[300005], num[300005], sz[300005], ans, gx[300005]; vector<int> vec[300005]; int ff(int x) { if (fa[x] == x) return x; int f = ff(fa[x]); v[x] ^= v[fa[x]]; return fa[x] = f; } inline void merge(int x, int y, int p) { if (ff(...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long inf = 1000000; const int N = 300002; vector<int> tree(2 * N); vector<int> ranks(2 * N, 0); char str[N]; int find(int x) { return x == tree[x] ? x : tree[x] = find(tree[x]); } void link(int x, int y) { if (ranks[x] > ranks[y]) { tree[y] = x; } else { tr...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; char op[300005]; int n, k, fa[300005], v[300005], num[300005], sz[300005], ans, gx[300005]; vector<int> vec[300005]; int ff(int x) { if (fa[x] == x) return x; int f = ff(fa[x]); v[x] ^= v[fa[x]]; return fa[x] = f; } inline void merge(int x, int y, int p) { if (ff(...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; const int INF = 1e9 + 7; struct node { int l, r; node(int _l = 0, int _r = 0) : l(_l), r(_r){}; void operator+=(node x) { l = min(l + x.l, INF); r = min(r + x.r, INF); } }; node val[N]; pair<int, int> root[N]; void build(int n = 0) { ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAXN = 900000; int papa[MAXN], peso[MAXN], custo[MAXN]; int k; bool obg[MAXN]; int find(int a) { if (papa[a] == -1) return a; return papa[a] = find(papa[a]); } bool juntos(int a, int b) { return find(a) == find(b); } void uni(int a, int b) { a = find(a); b...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct perem { int t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); long long n, k, m, c, vas, cc = 1000000000; vector<long long> vv; string s; vector<vector<long long>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T& x) { x = 0; int fl = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') fl = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); } x ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 10, inf = 0x3f3f3f3f; vector<int> v[maxn]; int fa[maxn], cnt[maxn]; int n, k; string s; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void merge(int u, int v) { u = find(u), v = find(v); if (u == v) return; cnt[u] += cnt[v]; ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 7; int n, k, fa[maxn], val[maxn], big; char a[maxn]; vector<int> E[maxn]; int fid(int x) { return fa[x] == x ? x : fa[x] = fid(fa[x]); } int uni(int x, int y) { int fx = fid(x), fy = fid(y); if (fx != fy) { fa[fx] = fy; val[fy] += val[fx];...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
python3
from sys import stdin input = stdin.readline n , k = [int(i) for i in input().split()] pairs = [i + n for i in range(n)] + [i for i in range(n)] initial_condition = list(map(lambda x: x == '1',input().strip())) data = [i for i in range(2*n)] constrain = [-1] * (2*n) h = [0] * (2*n) L = [1] * n + [0] * n dp1 = [-1 for...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, m, k, x; vector<int> vec[300010]; char c[300010]; int fa[300010 << 1], sz[300010 << 1]; int lim[300010]; int find(int x) { if (fa[x] == x) return x; return fa[x] = find(fa[x]); } int main() { scanf("%d%d%s", &n, &k, c + 1); for (int i = 1; i <= k; i++) { ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long maxn = 300005; const long long inf = 1ll << 50; int ans = 0; bool init[maxn]; int par[maxn], sz[maxn], cnt[maxn][2], col[maxn]; vector<int> vec[maxn]; int find(int x) { if (par[x] == x) { return x; } par[x] = find(...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct DS { int rank, cost, parent; bool forced; } ds[4 * 300100]; int ans; char status[300100]; vector<int> subs[300100]; int neg(int n) { return n + 300100; } int find(int n) { if (n == ds[n].parent) return n; return ds[n].parent = find(ds[n].parent); } void join(...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, k; string s; vector<int> a[300001]; int p[1000001]; int f[1000001]; const int Max = 6e5; const int T = 3e5; int root(int u) { if (u == p[u]) return u; return p[u] = root(p[u]); } void Merge(int u, int v) { u = root(u); v = root(v); int ru = root(u); int r...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long llINF = 2e18, llMOD = 1e9 + 7; const int INF = 2e9, MOD = 1e9 + 7, P = 179, N = 2e3 + 1, K = 23000, L = 18; const long double EPS = 1e-6, ldINF = 1e18, PI = acos(-1); template <typename T> inline void sort_uniq(vector<T>& v) { sort(v.begin(), v.end()); v...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> template <class V> int get_p(V& p, int j) { if (p[j] == j) return j; if (p[j] < 0) return p[j] = -get_p(p, -p[j]); return p[j] = get_p(p, p[j]); } int get_min(bool a_j, int S_j, bool coa_j, int coS_j) { if (!coa_j) return S_j; if (!a_j) return coS_j; return std::min(S_j, coS_j); } t...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct perem { int t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); long long n, k, m, c, vas, cc = 250000; vector<long long> vv; string s; vector<vector<long long>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct perem { int t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); int n, k, m, c, vas, cc = 1000000000; vector<int> vv; string s; vector<vector<int>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); ...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long ans = 0; long long val[600010]; int have[600010][2], fa[600010]; char str[600010]; int n, k; int find(int x) { return x == fa[x] ? x : (fa[x] = find(fa[x])); } int other(int u) { return u <= k ? u + k : u - k; } void update(int u, long long x, long long y) { ans...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> template <class V> int get_p(V& p, int j) { if (p[j] == j) return j; if (p[j] < 0) return p[j] = -get_p(p, -p[j]); return p[j] = get_p(p, p[j]); } int get_min(bool a_j, int S_j, bool coa_j, int coS_j) { if (!coa_j) return S_j; if (!a_j) return coS_j; return std::min(S_j, coS_j); } t...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long MAX = 3e5 + 5; long long inf = (long long)30000; long long mod = (long long)998244353; long long ans = 0, vert; long long n, k, par[MAX], sz[MAX], cnt[MAX][2], clr[MAX], pos[MAX]; vector<long long> sets[MAX]; vector<long long> b[MAX]; void x_or(long long dad...
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you ...
{ "input": [ "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n" ], "output": [ "1\n1\n1\n1\n1\n", "1...
{ "input": [ "1 1\n1\n1\n1\n" ], "output": [ "0\n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; int N, K, a[MAXN]; vector<int> V[MAXN]; char S[MAXN]; int f1[MAXN], v1[MAXN], f2[MAXN], chs[MAXN], ans; int get1(int x) { if (f1[x] != x) f1[x] = get1(f1[x]); return f1[x]; } void merge1(int x, int y) { x = get1(x), y = get1(y); if (x != y) ...