#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], trash[N];
ll w[K][N][N];
vector<int> v[K][N];
map<string, int> mp;
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);
}
mp[s[i]]++;
}
for (int i = 0; i < n; i++) {
if (mp[s[i]] > 1)
banned[i] = 1;
}
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:37:25: warning: array subscript has type 'char' [-Wchar-subscripts]
b[j][s[i][j]]++;
^
genetics.cpp:38:22: warning: array subscript has type 'char' [-Wchar-subscripts]
w[s[i][j]][i][j / B] |= 1ll << (j % B);
^
genetics.cpp:39:25: warning: array subscript has type 'char' [-Wchar-subscripts]
used[s[i][j]] = 1;
^
genetics.cpp:40:22: warning: array subscript has type 'char' [-Wchar-subscripts]
v[s[i][j]][i].push_back(j);
^
genetics.cpp:77: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 |
67576 KB |
Output is correct |
2 |
Correct |
40 ms |
68472 KB |
Output is correct |
3 |
Correct |
39 ms |
66936 KB |
Output is correct |
4 |
Correct |
39 ms |
67832 KB |
Output is correct |
5 |
Correct |
41 ms |
68472 KB |
Output is correct |
6 |
Correct |
44 ms |
67704 KB |
Output is correct |
7 |
Correct |
39 ms |
67448 KB |
Output is correct |
8 |
Correct |
39 ms |
66808 KB |
Output is correct |
9 |
Correct |
39 ms |
67964 KB |
Output is correct |
10 |
Correct |
40 ms |
68472 KB |
Output is correct |
11 |
Correct |
40 ms |
67576 KB |
Output is correct |
12 |
Correct |
40 ms |
68472 KB |
Output is correct |
13 |
Correct |
41 ms |
67704 KB |
Output is correct |
14 |
Correct |
39 ms |
68088 KB |
Output is correct |
15 |
Correct |
41 ms |
68600 KB |
Output is correct |
16 |
Correct |
41 ms |
67960 KB |
Output is correct |
17 |
Correct |
39 ms |
66936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
260 ms |
98172 KB |
Output is correct |
2 |
Correct |
168 ms |
102392 KB |
Output is correct |
3 |
Correct |
170 ms |
102392 KB |
Output is correct |
4 |
Correct |
77 ms |
82552 KB |
Output is correct |
5 |
Correct |
173 ms |
103160 KB |
Output is correct |
6 |
Correct |
170 ms |
103288 KB |
Output is correct |
7 |
Correct |
96 ms |
82808 KB |
Output is correct |
8 |
Correct |
95 ms |
82680 KB |
Output is correct |
9 |
Correct |
173 ms |
102740 KB |
Output is correct |
10 |
Correct |
185 ms |
102648 KB |
Output is correct |
11 |
Correct |
169 ms |
98168 KB |
Output is correct |
12 |
Correct |
151 ms |
98296 KB |
Output is correct |
13 |
Correct |
183 ms |
98168 KB |
Output is correct |
14 |
Correct |
138 ms |
93816 KB |
Output is correct |
15 |
Correct |
164 ms |
94072 KB |
Output is correct |
16 |
Correct |
131 ms |
97144 KB |
Output is correct |
17 |
Correct |
166 ms |
102520 KB |
Output is correct |
18 |
Correct |
168 ms |
102392 KB |
Output is correct |
19 |
Correct |
166 ms |
102648 KB |
Output is correct |
20 |
Correct |
164 ms |
102264 KB |
Output is correct |
21 |
Correct |
165 ms |
102520 KB |
Output is correct |
22 |
Correct |
165 ms |
102264 KB |
Output is correct |
23 |
Correct |
167 ms |
102392 KB |
Output is correct |
24 |
Correct |
167 ms |
102392 KB |
Output is correct |
25 |
Correct |
167 ms |
102136 KB |
Output is correct |
26 |
Correct |
165 ms |
102392 KB |
Output is correct |
27 |
Correct |
165 ms |
102136 KB |
Output is correct |
28 |
Correct |
168 ms |
102136 KB |
Output is correct |
29 |
Correct |
166 ms |
102392 KB |
Output is correct |
30 |
Correct |
170 ms |
102772 KB |
Output is correct |
31 |
Correct |
172 ms |
104184 KB |
Output is correct |
32 |
Correct |
170 ms |
104056 KB |
Output is correct |
33 |
Correct |
39 ms |
66936 KB |
Output is correct |
34 |
Correct |
40 ms |
67704 KB |
Output is correct |
35 |
Correct |
40 ms |
66936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
260 ms |
98172 KB |
Output is correct |
2 |
Correct |
168 ms |
102392 KB |
Output is correct |
3 |
Correct |
170 ms |
102392 KB |
Output is correct |
4 |
Correct |
77 ms |
82552 KB |
Output is correct |
5 |
Correct |
173 ms |
103160 KB |
Output is correct |
6 |
Correct |
170 ms |
103288 KB |
Output is correct |
7 |
Correct |
96 ms |
82808 KB |
Output is correct |
8 |
Correct |
95 ms |
82680 KB |
Output is correct |
9 |
Correct |
173 ms |
102740 KB |
Output is correct |
10 |
Correct |
185 ms |
102648 KB |
Output is correct |
11 |
Correct |
169 ms |
98168 KB |
Output is correct |
12 |
Correct |
151 ms |
98296 KB |
Output is correct |
13 |
Correct |
183 ms |
98168 KB |
Output is correct |
14 |
Correct |
138 ms |
93816 KB |
Output is correct |
15 |
Correct |
164 ms |
94072 KB |
Output is correct |
16 |
Correct |
131 ms |
97144 KB |
Output is correct |
17 |
Correct |
166 ms |
102520 KB |
Output is correct |
18 |
Correct |
168 ms |
102392 KB |
Output is correct |
19 |
Correct |
166 ms |
102648 KB |
Output is correct |
20 |
Correct |
164 ms |
102264 KB |
Output is correct |
21 |
Correct |
165 ms |
102520 KB |
Output is correct |
22 |
Correct |
165 ms |
102264 KB |
Output is correct |
23 |
Correct |
167 ms |
102392 KB |
Output is correct |
24 |
Correct |
167 ms |
102392 KB |
Output is correct |
25 |
Correct |
167 ms |
102136 KB |
Output is correct |
26 |
Correct |
165 ms |
102392 KB |
Output is correct |
27 |
Correct |
165 ms |
102136 KB |
Output is correct |
28 |
Correct |
168 ms |
102136 KB |
Output is correct |
29 |
Correct |
166 ms |
102392 KB |
Output is correct |
30 |
Correct |
170 ms |
102772 KB |
Output is correct |
31 |
Correct |
172 ms |
104184 KB |
Output is correct |
32 |
Correct |
170 ms |
104056 KB |
Output is correct |
33 |
Correct |
39 ms |
66936 KB |
Output is correct |
34 |
Correct |
40 ms |
67704 KB |
Output is correct |
35 |
Correct |
40 ms |
66936 KB |
Output is correct |
36 |
Execution timed out |
2095 ms |
210168 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
67576 KB |
Output is correct |
2 |
Correct |
40 ms |
68472 KB |
Output is correct |
3 |
Correct |
39 ms |
66936 KB |
Output is correct |
4 |
Correct |
39 ms |
67832 KB |
Output is correct |
5 |
Correct |
41 ms |
68472 KB |
Output is correct |
6 |
Correct |
44 ms |
67704 KB |
Output is correct |
7 |
Correct |
39 ms |
67448 KB |
Output is correct |
8 |
Correct |
39 ms |
66808 KB |
Output is correct |
9 |
Correct |
39 ms |
67964 KB |
Output is correct |
10 |
Correct |
40 ms |
68472 KB |
Output is correct |
11 |
Correct |
40 ms |
67576 KB |
Output is correct |
12 |
Correct |
40 ms |
68472 KB |
Output is correct |
13 |
Correct |
41 ms |
67704 KB |
Output is correct |
14 |
Correct |
39 ms |
68088 KB |
Output is correct |
15 |
Correct |
41 ms |
68600 KB |
Output is correct |
16 |
Correct |
41 ms |
67960 KB |
Output is correct |
17 |
Correct |
39 ms |
66936 KB |
Output is correct |
18 |
Correct |
260 ms |
98172 KB |
Output is correct |
19 |
Correct |
168 ms |
102392 KB |
Output is correct |
20 |
Correct |
170 ms |
102392 KB |
Output is correct |
21 |
Correct |
77 ms |
82552 KB |
Output is correct |
22 |
Correct |
173 ms |
103160 KB |
Output is correct |
23 |
Correct |
170 ms |
103288 KB |
Output is correct |
24 |
Correct |
96 ms |
82808 KB |
Output is correct |
25 |
Correct |
95 ms |
82680 KB |
Output is correct |
26 |
Correct |
173 ms |
102740 KB |
Output is correct |
27 |
Correct |
185 ms |
102648 KB |
Output is correct |
28 |
Correct |
169 ms |
98168 KB |
Output is correct |
29 |
Correct |
151 ms |
98296 KB |
Output is correct |
30 |
Correct |
183 ms |
98168 KB |
Output is correct |
31 |
Correct |
138 ms |
93816 KB |
Output is correct |
32 |
Correct |
164 ms |
94072 KB |
Output is correct |
33 |
Correct |
131 ms |
97144 KB |
Output is correct |
34 |
Correct |
166 ms |
102520 KB |
Output is correct |
35 |
Correct |
168 ms |
102392 KB |
Output is correct |
36 |
Correct |
166 ms |
102648 KB |
Output is correct |
37 |
Correct |
164 ms |
102264 KB |
Output is correct |
38 |
Correct |
165 ms |
102520 KB |
Output is correct |
39 |
Correct |
165 ms |
102264 KB |
Output is correct |
40 |
Correct |
167 ms |
102392 KB |
Output is correct |
41 |
Correct |
167 ms |
102392 KB |
Output is correct |
42 |
Correct |
167 ms |
102136 KB |
Output is correct |
43 |
Correct |
165 ms |
102392 KB |
Output is correct |
44 |
Correct |
165 ms |
102136 KB |
Output is correct |
45 |
Correct |
168 ms |
102136 KB |
Output is correct |
46 |
Correct |
166 ms |
102392 KB |
Output is correct |
47 |
Correct |
170 ms |
102772 KB |
Output is correct |
48 |
Correct |
172 ms |
104184 KB |
Output is correct |
49 |
Correct |
170 ms |
104056 KB |
Output is correct |
50 |
Correct |
39 ms |
66936 KB |
Output is correct |
51 |
Correct |
40 ms |
67704 KB |
Output is correct |
52 |
Correct |
40 ms |
66936 KB |
Output is correct |
53 |
Execution timed out |
2095 ms |
210168 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |