#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
const int N = 4105, K = 2, B = 63;
string s[N], let = "ACGT";
int a[N], b[N][K], mem[N][N];
bool banned[N];
ll w[4][N][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;
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);
}
}
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) {
if (mem[i][j] == -1) {
mem[i][j] = m;
for (int h = 0; h < K; h++) {
for (int z = 0; z < bl_cnt; z++) {
mem[i][j] -= __builtin_popcountll(w[h][i][z] & w[h][j][z]);
}
}
mem[j][i] = mem[i][j];
}
if (mem[i][j] != k) {
banned[j] = 1;
ok = false;
}
}
}
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:63:32: warning: array subscript has type 'char' [-Wchar-subscripts]
sum += b[j][s[i][j]];
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
67192 KB |
Output is correct |
2 |
Incorrect |
39 ms |
68088 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
82168 KB |
Output is correct |
2 |
Correct |
100 ms |
85240 KB |
Output is correct |
3 |
Correct |
106 ms |
84472 KB |
Output is correct |
4 |
Correct |
57 ms |
76664 KB |
Output is correct |
5 |
Correct |
107 ms |
85240 KB |
Output is correct |
6 |
Correct |
114 ms |
85244 KB |
Output is correct |
7 |
Correct |
68 ms |
74488 KB |
Output is correct |
8 |
Correct |
68 ms |
74488 KB |
Output is correct |
9 |
Correct |
219 ms |
84344 KB |
Output is correct |
10 |
Correct |
240 ms |
84344 KB |
Output is correct |
11 |
Correct |
194 ms |
82168 KB |
Output is correct |
12 |
Correct |
148 ms |
82168 KB |
Output is correct |
13 |
Correct |
99 ms |
82040 KB |
Output is correct |
14 |
Correct |
148 ms |
79864 KB |
Output is correct |
15 |
Correct |
96 ms |
80120 KB |
Output is correct |
16 |
Correct |
91 ms |
81272 KB |
Output is correct |
17 |
Correct |
104 ms |
84472 KB |
Output is correct |
18 |
Correct |
102 ms |
84344 KB |
Output is correct |
19 |
Correct |
104 ms |
84472 KB |
Output is correct |
20 |
Correct |
105 ms |
84240 KB |
Output is correct |
21 |
Correct |
104 ms |
84372 KB |
Output is correct |
22 |
Correct |
104 ms |
84216 KB |
Output is correct |
23 |
Correct |
109 ms |
84344 KB |
Output is correct |
24 |
Correct |
104 ms |
84344 KB |
Output is correct |
25 |
Correct |
104 ms |
84472 KB |
Output is correct |
26 |
Correct |
105 ms |
84412 KB |
Output is correct |
27 |
Correct |
107 ms |
84216 KB |
Output is correct |
28 |
Correct |
105 ms |
84216 KB |
Output is correct |
29 |
Correct |
105 ms |
84344 KB |
Output is correct |
30 |
Correct |
105 ms |
85240 KB |
Output is correct |
31 |
Correct |
103 ms |
85368 KB |
Output is correct |
32 |
Correct |
107 ms |
85240 KB |
Output is correct |
33 |
Correct |
38 ms |
66552 KB |
Output is correct |
34 |
Correct |
40 ms |
67192 KB |
Output is correct |
35 |
Correct |
39 ms |
66552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
82168 KB |
Output is correct |
2 |
Correct |
100 ms |
85240 KB |
Output is correct |
3 |
Correct |
106 ms |
84472 KB |
Output is correct |
4 |
Correct |
57 ms |
76664 KB |
Output is correct |
5 |
Correct |
107 ms |
85240 KB |
Output is correct |
6 |
Correct |
114 ms |
85244 KB |
Output is correct |
7 |
Correct |
68 ms |
74488 KB |
Output is correct |
8 |
Correct |
68 ms |
74488 KB |
Output is correct |
9 |
Correct |
219 ms |
84344 KB |
Output is correct |
10 |
Correct |
240 ms |
84344 KB |
Output is correct |
11 |
Correct |
194 ms |
82168 KB |
Output is correct |
12 |
Correct |
148 ms |
82168 KB |
Output is correct |
13 |
Correct |
99 ms |
82040 KB |
Output is correct |
14 |
Correct |
148 ms |
79864 KB |
Output is correct |
15 |
Correct |
96 ms |
80120 KB |
Output is correct |
16 |
Correct |
91 ms |
81272 KB |
Output is correct |
17 |
Correct |
104 ms |
84472 KB |
Output is correct |
18 |
Correct |
102 ms |
84344 KB |
Output is correct |
19 |
Correct |
104 ms |
84472 KB |
Output is correct |
20 |
Correct |
105 ms |
84240 KB |
Output is correct |
21 |
Correct |
104 ms |
84372 KB |
Output is correct |
22 |
Correct |
104 ms |
84216 KB |
Output is correct |
23 |
Correct |
109 ms |
84344 KB |
Output is correct |
24 |
Correct |
104 ms |
84344 KB |
Output is correct |
25 |
Correct |
104 ms |
84472 KB |
Output is correct |
26 |
Correct |
105 ms |
84412 KB |
Output is correct |
27 |
Correct |
107 ms |
84216 KB |
Output is correct |
28 |
Correct |
105 ms |
84216 KB |
Output is correct |
29 |
Correct |
105 ms |
84344 KB |
Output is correct |
30 |
Correct |
105 ms |
85240 KB |
Output is correct |
31 |
Correct |
103 ms |
85368 KB |
Output is correct |
32 |
Correct |
107 ms |
85240 KB |
Output is correct |
33 |
Correct |
38 ms |
66552 KB |
Output is correct |
34 |
Correct |
40 ms |
67192 KB |
Output is correct |
35 |
Correct |
39 ms |
66552 KB |
Output is correct |
36 |
Correct |
1014 ms |
116344 KB |
Output is correct |
37 |
Correct |
362 ms |
122616 KB |
Output is correct |
38 |
Correct |
376 ms |
121848 KB |
Output is correct |
39 |
Correct |
167 ms |
102268 KB |
Output is correct |
40 |
Correct |
369 ms |
122744 KB |
Output is correct |
41 |
Correct |
212 ms |
94584 KB |
Output is correct |
42 |
Correct |
208 ms |
94456 KB |
Output is correct |
43 |
Correct |
1583 ms |
110584 KB |
Output is correct |
44 |
Correct |
1634 ms |
123128 KB |
Output is correct |
45 |
Correct |
605 ms |
123132 KB |
Output is correct |
46 |
Correct |
1687 ms |
123256 KB |
Output is correct |
47 |
Correct |
1424 ms |
116244 KB |
Output is correct |
48 |
Correct |
645 ms |
116216 KB |
Output is correct |
49 |
Correct |
594 ms |
108920 KB |
Output is correct |
50 |
Correct |
1451 ms |
109032 KB |
Output is correct |
51 |
Correct |
347 ms |
113784 KB |
Output is correct |
52 |
Correct |
360 ms |
121848 KB |
Output is correct |
53 |
Correct |
364 ms |
121720 KB |
Output is correct |
54 |
Correct |
353 ms |
120696 KB |
Output is correct |
55 |
Correct |
354 ms |
120568 KB |
Output is correct |
56 |
Correct |
355 ms |
120568 KB |
Output is correct |
57 |
Correct |
380 ms |
121976 KB |
Output is correct |
58 |
Correct |
369 ms |
121848 KB |
Output is correct |
59 |
Correct |
368 ms |
121720 KB |
Output is correct |
60 |
Correct |
369 ms |
121976 KB |
Output is correct |
61 |
Correct |
362 ms |
121720 KB |
Output is correct |
62 |
Correct |
369 ms |
121336 KB |
Output is correct |
63 |
Correct |
363 ms |
121976 KB |
Output is correct |
64 |
Correct |
376 ms |
121848 KB |
Output is correct |
65 |
Correct |
371 ms |
121720 KB |
Output is correct |
66 |
Correct |
369 ms |
121720 KB |
Output is correct |
67 |
Correct |
380 ms |
122104 KB |
Output is correct |
68 |
Correct |
373 ms |
121976 KB |
Output is correct |
69 |
Correct |
368 ms |
121720 KB |
Output is correct |
70 |
Correct |
367 ms |
121976 KB |
Output is correct |
71 |
Correct |
362 ms |
121720 KB |
Output is correct |
72 |
Correct |
365 ms |
121976 KB |
Output is correct |
73 |
Correct |
369 ms |
121720 KB |
Output is correct |
74 |
Correct |
39 ms |
66552 KB |
Output is correct |
75 |
Correct |
40 ms |
67192 KB |
Output is correct |
76 |
Correct |
39 ms |
66552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
67192 KB |
Output is correct |
2 |
Incorrect |
39 ms |
68088 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |