Submission #1188513

#TimeUsernameProblemLanguageResultExecution timeMemory
1188513kl0989eGenetics (BOI18_genetics)C++20
100 / 100
1235 ms94908 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() const int maxn=4110; vector<bitset<4*maxn>> ss(maxn); 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=m-(ss[i]&ss[j]).count(); 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]; for (int j=0; j<m; j++) { if (s[i][j]=='A') { ss[i].set(j); } else if (s[i][j]=='C') { ss[i].set(j+m); } else if (s[i][j]=='G') { ss[i].set(j+2*m); } else { ss[i].set(j+3*m); } } } 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...