Submission #887694

#TimeUsernameProblemLanguageResultExecution timeMemory
887694nnhzzzGenetics (BOI18_genetics)C++14
100 / 100
1319 ms85336 KiB
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2") #include<bits/stdc++.h> using namespace std; #define REP(i,a,b) for(int i = (a); i<=(b); ++i) #define REPD(i,a,b) for(int i = (a); i>=(b); --i) #define REPDIS(i,a,b,c) for(int i = (a); i<=(b); i += c) #define ALL(x) (x).begin(),(x).end() #define SZ(x) (int)(x).size() #define MASK(x) (1LL<<(x)) #define BIT(x,i) (((x)>>(i))&1LL) #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define pii pair<int,int> #define vpii vector<pii> #define vvpii vector<vpii> #define fi first #define se second #define gcd __gcd #define ld long double #define ll long long #define ull unsigned long long #define MP make_pair #define endl "\n" //#define int ll //-------------------------------------------------------------------------------------------------------// int readInt(){ char c; do{ c = getchar(); }while(c!='-' && !isdigit(c)); bool neg = (c=='-'); int res = neg?0:c-'0'; while(isdigit(c=getchar())) res = (res<<3)+(res<<1)+(c-'0'); return neg?-res:res; } //-------------------------------------------------------------------------------------------------------// template<typename T> bool mini(T &a, const T &b){if(a>b){a=b;return true;}return false;} template<typename T> bool maxi(T &a, const T &b){if(a<b){a=b;return true;}return false;} //-------------------------------------------------------------------------------------------------------// const int MAXN = 4e3+123; const int MOD = 1e9+7; const int INF = 1e9; const int LOG = 16; const ll LINF = 5e17; const ld EPS = 1e-9; const ld PI = acos(-1); //-------------------------------------------------------------------------------------------------------// int a[MAXN][MAXN]; int n,m,k; namespace sub1{ void solve(){ REP(l,1,n){ int ok = 1; REP(i,1,n){ if(i==l) continue; int cnt = 0; REP(j,1,m) if(a[l][j]!=a[i][j]) ++cnt; if(cnt!=k){ ok = 0; break; } } if(ok){ cout << l; return ; } } } } mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); namespace sub2{ bitset<MAXN> f[MAXN]; int idx[MAXN]; void solve(){ srand(time(0)); REP(i,1,n) idx[i] = i; shuffle(idx+1,idx+n+1,rd); REP(i,1,n) REP(j,1,m) f[i][j] = a[i][j]-1; REP(l,1,n){ int ok = 1; REP(i,1,n){ if(i==idx[l]) continue; if((f[idx[l]]^f[i]).count()!=k){ ok = 0; break; } } if(ok){ cout << idx[l]; return ; } } } } namespace sub4{ ll s[MAXN][5],rnd[MAXN]; ll tot = 0; void solve(){ srand(time(0)); REP(i,1,n){ rnd[i] = rd(); tot += rnd[i]; REP(j,1,m) s[j][a[i][j]] += rnd[i]; } REP(i,1,n){ ll hsh = 0; REP(j,1,m) hsh += tot-s[j][a[i][j]]; if(hsh==1LL*k*(tot-rnd[i])){ cout << i; return ; } } } } void solve(){ cin >> n >> m >> k; int s2 = 1; REP(i,1,n){ REP(j,1,m){ char ch; cin >> ch; if(ch=='A') a[i][j] = 1; if(ch=='C') a[i][j] = 2; if(ch=='G') a[i][j] = 3; if(ch=='T') a[i][j] = 4; if(a[i][j]>2) s2 = 0; } } // sub4::solve(); return ; if(n<=100){ sub1::solve(); return ; } if(s2){ sub2::solve(); return ; } sub4::solve(); } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "test" if(fopen(task".inp","r")){ freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } #define task1 "nothing" if(fopen(task1".inp","r")){ freopen(task1".inp","r",stdin); freopen(task1".out","w",stdout); } int test = 1; while(test--){ solve(); cout << endl; } return 0; }

Compilation message (stderr)

genetics.cpp: In function 'void sub2::solve()':
genetics.cpp:95:44: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   95 |                 if((f[idx[l]]^f[i]).count()!=k){
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~^~~
genetics.cpp: In function 'int main()':
genetics.cpp:160:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  160 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
genetics.cpp:161:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  161 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
genetics.cpp:165:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  165 |         freopen(task1".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
genetics.cpp:166:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  166 |         freopen(task1".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...