Submission #954202

#TimeUsernameProblemLanguageResultExecution timeMemory
954202AlanGenetics (BOI18_genetics)C++17
0 / 100
2033 ms119260 KiB
#include <bits/stdc++.h> using namespace std; string s[4105], t[4105]; map<string, int> mp; bool bad[4105]; int n, m, k, id[4105]; mt19937 r (chrono::high_resolution_clock().now().time_since_epoch().count()); int rnd (int mn, int mx) { return uniform_int_distribution<int> (mn, mx) (r); } int diff (int x, int y) { int cnt = 0; for (int i = 0; i < (int) s[x].size(); i++) cnt += s[x][i] != s[y][i]; return cnt; } int solve () { for (int i = n; i >= 1; i--) { int swp = rnd(1, i); swap(s[i], s[swp]); swap(id[i], id[swp]); } for (int i = 1; i <= n; i++) bad[i] = mp[s[i]] > 1; deque<int> dq; for (int i = 1; i <= n; i++) if (!bad[i]) { while (i <= n && !dq.empty() && diff(dq.back(), i) != k) { i++; dq.pop_back(); } if (i > n) break; dq.push_back(i); } while ((int) dq.size() > 2) { if (diff(dq.front(), dq.back()) == k) return solve(); dq.pop_front(); dq.pop_back(); } if ((int) dq.size() > 1) { for (int i = 1; i <= n; i++) if (i != dq[0] && diff(i, dq[0]) != k) { dq.pop_front(); break; } if ((int) dq.size() > 1) dq.pop_back(); } return id[dq[0]]; } int main () { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> s[i]; id[i] = i; mp[s[i]]++; } cout << solve() << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...