Submission #1188362

#TimeUsernameProblemLanguageResultExecution timeMemory
1188362kl0989eGenetics (BOI18_genetics)C++20
74 / 100
2093 ms86700 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define pb push_back #define vi vector<int> #define vl vector<ll> #define pi pair<int, int> #define pl pair<ll,ll> #define all(x) (x).begin(),(x).end() vector<string> s; vector<vi> dif; vi ok; int n,m,k; int diff(int i, int j) { if (dif[i][j]!=-1) { return dif[i][j]; } int cnt=0; for (int l=0; l<m; l++) { if (s[i][l]!=s[j][l]) { cnt++; } } dif[i][j]=cnt; dif[j][i]=cnt; if (cnt!=k) { ok[i]=0; ok[j]=0; } return cnt; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k; s.resize(n); dif.resize(n,vi(n,-1)); ok.resize(n,1); for (int i=0; i<n; i++) { cin >> s[i]; } vector<map<char,int>> cnts(m); for (int i=0; i<n; i++) { for (int j=0; j<m; j++) { cnts[j][s[i][j]]++; } } mt19937 rnd(time(0)); vi ord1(n); iota(all(ord1),0); shuffle(all(ord1),rnd); for (auto i:ord1) { if (!ok[i]) { continue; } int tot=0; for (int j=0; j<m; j++) { tot+=n-cnts[j][s[i][j]]; } if (tot!=k*(n-1)) { continue; } vi ord(n); iota(all(ord),0); shuffle(all(ord),rnd); for (auto j:ord) { if (i==j) { continue; } if (diff(i,j)!=k) { break; } } if (ok[i]) { cout << i+1 << '\n'; return 0; } } 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...