#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
const int N = 4105, K = 4, B = 63, STUFF = 50;
string s[N], let = "ACGT";
int a[N], b[N][K], mem[N][N];
bool banned[N], used[K];
ll w[K][N][N];
vector<int> v[K][N];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, k, let_cnt = 0;
cin >> n >> m >> k;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int bl_cnt = (m - 1) / B + 1;
for (int i = 0; i < n; i++) {
a[i] = i;
while (s[i].empty())
getline(cin, s[i]);
for (int j = 0; j < m; j++) {
s[i][j] = find(all(let), s[i][j]) - let.begin();
b[j][s[i][j]]++;
w[s[i][j]][i][j / B] |= 1ll << (j % B);
used[s[i][j]] = 1;
v[s[i][j]][i].push_back(j);
}
}
for (int i = 0; i < K; i++)
let_cnt += used[i];
for (int i = 0; i < m; i++) {
int sum = 0;
for (int j = 0; j < K; j++) {
sum += b[i][j];
}
for (int j = 0; j < K; j++) {
b[i][j] = sum - b[i][j];
}
}
shuffle(a, a + n, rng);
memset(mem, -1, sizeof(mem));
for (int h = 0; h < n; h++) {
int i = a[h];
if (banned[i])
continue;
ll sum = 0;
for (int j = 0; j < m; j++) {
sum += b[j][s[i][j]];
}
if (sum != k * (n - 1))
continue;
bool ok = true;
for (int j = 0; j < n; j++) {
if (i != j) {
int &d = mem[i][j];
if (d == -1) {
d = m;
for (int h = 0; h < let_cnt; h++) {
if (v[h][i].size() < STUFF) {
for (int &x : v[h][i]) {
if (s[j][x] == h)
d--;
}
}
else if (v[h][j].size() < STUFF) {
for (int &x : v[h][j]) {
if (s[i][x] == h)
d--;
}
}
else {
for (int z = 0; z < bl_cnt; z++) {
d -= __builtin_popcountll(w[h][i][z] & w[h][j][z]);
}
}
}
mem[j][i] = d;
}
if (d != k) {
banned[j] = 1;
ok = false;
break;
}
}
}
if (ok) {
cout << i + 1;
return 0;
}
}
return 0;
}
Compilation message
genetics.cpp: In function 'int main()':
genetics.cpp:36:25: warning: array subscript has type 'char' [-Wchar-subscripts]
b[j][s[i][j]]++;
^
genetics.cpp:37:22: warning: array subscript has type 'char' [-Wchar-subscripts]
w[s[i][j]][i][j / B] |= 1ll << (j % B);
^
genetics.cpp:38:25: warning: array subscript has type 'char' [-Wchar-subscripts]
used[s[i][j]] = 1;
^
genetics.cpp:39:22: warning: array subscript has type 'char' [-Wchar-subscripts]
v[s[i][j]][i].push_back(j);
^
genetics.cpp:68:32: warning: array subscript has type 'char' [-Wchar-subscripts]
sum += b[j][s[i][j]];
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
67576 KB |
Output is correct |
2 |
Correct |
41 ms |
68472 KB |
Output is correct |
3 |
Correct |
39 ms |
66936 KB |
Output is correct |
4 |
Correct |
39 ms |
67704 KB |
Output is correct |
5 |
Correct |
40 ms |
68472 KB |
Output is correct |
6 |
Correct |
47 ms |
67704 KB |
Output is correct |
7 |
Correct |
39 ms |
67448 KB |
Output is correct |
8 |
Correct |
41 ms |
66812 KB |
Output is correct |
9 |
Correct |
40 ms |
67960 KB |
Output is correct |
10 |
Correct |
41 ms |
68472 KB |
Output is correct |
11 |
Correct |
41 ms |
67576 KB |
Output is correct |
12 |
Correct |
41 ms |
68472 KB |
Output is correct |
13 |
Correct |
39 ms |
67704 KB |
Output is correct |
14 |
Correct |
39 ms |
68088 KB |
Output is correct |
15 |
Correct |
39 ms |
68472 KB |
Output is correct |
16 |
Correct |
41 ms |
67960 KB |
Output is correct |
17 |
Correct |
40 ms |
66936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
95064 KB |
Output is correct |
2 |
Correct |
159 ms |
100472 KB |
Output is correct |
3 |
Correct |
161 ms |
99064 KB |
Output is correct |
4 |
Correct |
72 ms |
82040 KB |
Output is correct |
5 |
Correct |
161 ms |
100576 KB |
Output is correct |
6 |
Correct |
164 ms |
100476 KB |
Output is correct |
7 |
Correct |
92 ms |
81144 KB |
Output is correct |
8 |
Correct |
92 ms |
81272 KB |
Output is correct |
9 |
Correct |
162 ms |
99064 KB |
Output is correct |
10 |
Correct |
235 ms |
99064 KB |
Output is correct |
11 |
Correct |
179 ms |
95100 KB |
Output is correct |
12 |
Correct |
139 ms |
95224 KB |
Output is correct |
13 |
Correct |
153 ms |
95096 KB |
Output is correct |
14 |
Correct |
149 ms |
91128 KB |
Output is correct |
15 |
Correct |
132 ms |
91384 KB |
Output is correct |
16 |
Correct |
128 ms |
94200 KB |
Output is correct |
17 |
Correct |
164 ms |
99064 KB |
Output is correct |
18 |
Correct |
153 ms |
98808 KB |
Output is correct |
19 |
Correct |
162 ms |
99064 KB |
Output is correct |
20 |
Correct |
161 ms |
98680 KB |
Output is correct |
21 |
Correct |
160 ms |
98936 KB |
Output is correct |
22 |
Correct |
155 ms |
98728 KB |
Output is correct |
23 |
Correct |
158 ms |
99064 KB |
Output is correct |
24 |
Correct |
160 ms |
98936 KB |
Output is correct |
25 |
Correct |
159 ms |
98680 KB |
Output is correct |
26 |
Correct |
160 ms |
98940 KB |
Output is correct |
27 |
Correct |
158 ms |
98808 KB |
Output is correct |
28 |
Correct |
162 ms |
98680 KB |
Output is correct |
29 |
Correct |
157 ms |
98936 KB |
Output is correct |
30 |
Correct |
168 ms |
100472 KB |
Output is correct |
31 |
Correct |
158 ms |
100472 KB |
Output is correct |
32 |
Correct |
166 ms |
100600 KB |
Output is correct |
33 |
Correct |
39 ms |
66936 KB |
Output is correct |
34 |
Correct |
40 ms |
67832 KB |
Output is correct |
35 |
Correct |
38 ms |
66936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
95064 KB |
Output is correct |
2 |
Correct |
159 ms |
100472 KB |
Output is correct |
3 |
Correct |
161 ms |
99064 KB |
Output is correct |
4 |
Correct |
72 ms |
82040 KB |
Output is correct |
5 |
Correct |
161 ms |
100576 KB |
Output is correct |
6 |
Correct |
164 ms |
100476 KB |
Output is correct |
7 |
Correct |
92 ms |
81144 KB |
Output is correct |
8 |
Correct |
92 ms |
81272 KB |
Output is correct |
9 |
Correct |
162 ms |
99064 KB |
Output is correct |
10 |
Correct |
235 ms |
99064 KB |
Output is correct |
11 |
Correct |
179 ms |
95100 KB |
Output is correct |
12 |
Correct |
139 ms |
95224 KB |
Output is correct |
13 |
Correct |
153 ms |
95096 KB |
Output is correct |
14 |
Correct |
149 ms |
91128 KB |
Output is correct |
15 |
Correct |
132 ms |
91384 KB |
Output is correct |
16 |
Correct |
128 ms |
94200 KB |
Output is correct |
17 |
Correct |
164 ms |
99064 KB |
Output is correct |
18 |
Correct |
153 ms |
98808 KB |
Output is correct |
19 |
Correct |
162 ms |
99064 KB |
Output is correct |
20 |
Correct |
161 ms |
98680 KB |
Output is correct |
21 |
Correct |
160 ms |
98936 KB |
Output is correct |
22 |
Correct |
155 ms |
98728 KB |
Output is correct |
23 |
Correct |
158 ms |
99064 KB |
Output is correct |
24 |
Correct |
160 ms |
98936 KB |
Output is correct |
25 |
Correct |
159 ms |
98680 KB |
Output is correct |
26 |
Correct |
160 ms |
98940 KB |
Output is correct |
27 |
Correct |
158 ms |
98808 KB |
Output is correct |
28 |
Correct |
162 ms |
98680 KB |
Output is correct |
29 |
Correct |
157 ms |
98936 KB |
Output is correct |
30 |
Correct |
168 ms |
100472 KB |
Output is correct |
31 |
Correct |
158 ms |
100472 KB |
Output is correct |
32 |
Correct |
166 ms |
100600 KB |
Output is correct |
33 |
Correct |
39 ms |
66936 KB |
Output is correct |
34 |
Correct |
40 ms |
67832 KB |
Output is correct |
35 |
Correct |
38 ms |
66936 KB |
Output is correct |
36 |
Execution timed out |
2078 ms |
199776 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
67576 KB |
Output is correct |
2 |
Correct |
41 ms |
68472 KB |
Output is correct |
3 |
Correct |
39 ms |
66936 KB |
Output is correct |
4 |
Correct |
39 ms |
67704 KB |
Output is correct |
5 |
Correct |
40 ms |
68472 KB |
Output is correct |
6 |
Correct |
47 ms |
67704 KB |
Output is correct |
7 |
Correct |
39 ms |
67448 KB |
Output is correct |
8 |
Correct |
41 ms |
66812 KB |
Output is correct |
9 |
Correct |
40 ms |
67960 KB |
Output is correct |
10 |
Correct |
41 ms |
68472 KB |
Output is correct |
11 |
Correct |
41 ms |
67576 KB |
Output is correct |
12 |
Correct |
41 ms |
68472 KB |
Output is correct |
13 |
Correct |
39 ms |
67704 KB |
Output is correct |
14 |
Correct |
39 ms |
68088 KB |
Output is correct |
15 |
Correct |
39 ms |
68472 KB |
Output is correct |
16 |
Correct |
41 ms |
67960 KB |
Output is correct |
17 |
Correct |
40 ms |
66936 KB |
Output is correct |
18 |
Correct |
217 ms |
95064 KB |
Output is correct |
19 |
Correct |
159 ms |
100472 KB |
Output is correct |
20 |
Correct |
161 ms |
99064 KB |
Output is correct |
21 |
Correct |
72 ms |
82040 KB |
Output is correct |
22 |
Correct |
161 ms |
100576 KB |
Output is correct |
23 |
Correct |
164 ms |
100476 KB |
Output is correct |
24 |
Correct |
92 ms |
81144 KB |
Output is correct |
25 |
Correct |
92 ms |
81272 KB |
Output is correct |
26 |
Correct |
162 ms |
99064 KB |
Output is correct |
27 |
Correct |
235 ms |
99064 KB |
Output is correct |
28 |
Correct |
179 ms |
95100 KB |
Output is correct |
29 |
Correct |
139 ms |
95224 KB |
Output is correct |
30 |
Correct |
153 ms |
95096 KB |
Output is correct |
31 |
Correct |
149 ms |
91128 KB |
Output is correct |
32 |
Correct |
132 ms |
91384 KB |
Output is correct |
33 |
Correct |
128 ms |
94200 KB |
Output is correct |
34 |
Correct |
164 ms |
99064 KB |
Output is correct |
35 |
Correct |
153 ms |
98808 KB |
Output is correct |
36 |
Correct |
162 ms |
99064 KB |
Output is correct |
37 |
Correct |
161 ms |
98680 KB |
Output is correct |
38 |
Correct |
160 ms |
98936 KB |
Output is correct |
39 |
Correct |
155 ms |
98728 KB |
Output is correct |
40 |
Correct |
158 ms |
99064 KB |
Output is correct |
41 |
Correct |
160 ms |
98936 KB |
Output is correct |
42 |
Correct |
159 ms |
98680 KB |
Output is correct |
43 |
Correct |
160 ms |
98940 KB |
Output is correct |
44 |
Correct |
158 ms |
98808 KB |
Output is correct |
45 |
Correct |
162 ms |
98680 KB |
Output is correct |
46 |
Correct |
157 ms |
98936 KB |
Output is correct |
47 |
Correct |
168 ms |
100472 KB |
Output is correct |
48 |
Correct |
158 ms |
100472 KB |
Output is correct |
49 |
Correct |
166 ms |
100600 KB |
Output is correct |
50 |
Correct |
39 ms |
66936 KB |
Output is correct |
51 |
Correct |
40 ms |
67832 KB |
Output is correct |
52 |
Correct |
38 ms |
66936 KB |
Output is correct |
53 |
Execution timed out |
2078 ms |
199776 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |