Submission #636388

#TimeUsernameProblemLanguageResultExecution timeMemory
636388TranGiaHuy1508Genetics (BOI18_genetics)C++17
46 / 100
2053 ms29344 KiB
/* Unknown's C++ Template (v3.2) */ #include "bits/stdc++.h" using namespace std; #define int long long using ll = long long; using ld = long double; using ii = pair<int, int>; using vi = vector<int>; using vii = vector<ii>; using vvi = vector<vi>; using vvii = vector<vii>; template <class T> using maxpq = priority_queue<T>; template <class T> using minpq = priority_queue<T, vector<T>, greater<T>>; #define pb push_back #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define mid ((l+r)>>1) #define fi first #define se second #ifdef LOCAL #define debug(x) cout << #x << " = " << x << "\n"; #else #define debug(x) ; #endif template <class A, class B> ostream& operator << (ostream& out, pair<A, B> x) { out << "(" << x.first << ", " << x.second << ")"; return out; } template <class T> ostream& operator << (ostream& out, vector<T> x){ out << "["; for (int i=0; i<sz(x); i++) { out << (i ? ", " : "") << x[i]; } out << "]"; return out; } template <class T> istream& operator >> (istream& in, vector<T> &x){ for (auto &i: x) in >> i; return in; } const ld PI = acos(-1.0); const int allmod[3] = {(int)1e9+7, 998244353, (int)1e9+9}; const int mod = allmod[0]; const int maxn = 4105; const ll inf = 1e18; const ld eps = 1e-6; const int multitest = 0; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int dp[maxn][4]; string inp[maxn]; int n, m, k; void main_program(){ cin >> n >> m >> k; for (int i = 0; i < n; i++){ string s; cin >> s; inp[i] = s; for (int j = 0; j < m; j++){ int c; if (s[j] == 'A') c = 0; else if (s[j] == 'C') c = 1; else if (s[j] == 'T') c = 2; else c = 3; dp[j][c]++; } } vi cand; for (int i = 0; i < n; i++){ int s = n * m; for (int j = 0; j < m; j++){ int c; if (inp[i][j] == 'A') c = 0; else if (inp[i][j] == 'C') c = 1; else if (inp[i][j] == 'T') c = 2; else c = 3; s -= dp[j][c]; } if (s == k * (n - 1)) cand.pb(i); } shuffle(all(cand), rng); debug(cand); for (int i = 0; i < sz(cand) - 1; i++){ int idx = cand[i]; bool valid = true; for (int j = 0; j < n; j++){ if (j == idx) continue; int s = 0; for (int x = 0; x < m; x++){ s += (inp[idx][x] != inp[j][x]); } if (s != k){ valid = false; break; } } if (valid){ cout << idx + 1 << "\n"; return; } } cout << cand.back() + 1 << "\n"; } void pre_main(){ } signed main(){ #ifdef LOCAL auto stime = chrono::high_resolution_clock::now(); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE if (fopen(".inp", "r")){ freopen(".inp", "r", stdin); freopen(".out", "w", stdout); } #endif int t = 1; if (multitest) cin >> t; pre_main(); while (t--) main_program(); #ifdef LOCAL auto etime = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(etime-stime).count(); cout << "\n[" << duration << "ms]\n"; #endif }

Compilation message (stderr)

genetics.cpp: In function 'int main()':
genetics.cpp:129:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |    freopen(".inp", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~
genetics.cpp:130:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |    freopen(".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...