This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// BOI18_genetics
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const ll LINF = 1e18 + 100;
const int prm = 5009;
#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'
#define MAXN 4200
inline int ch(char c)
{
if (c == 'A') return 0;
if (c == 'C') return 1;
if (c == 'G') return 2;
return 3;
}
int n, m, k;
char s[MAXN][MAXN];
ll sum[MAXN][4];
ll fsum[MAXN];
ll id[MAXN];
ll idsum;
int32_t main(void)
{
fast_io;
cin >> n >> m >> k;
id[0] = 1;
FOR(i, 1, n + 10)
id[i] = id[i - 1] * prm % mod;
FOR(i, 0, n)
{
idsum = (idsum + id[i]) % mod;
cin >> s[i];
FOR(j, 0, m)
sum[j][ch(s[i][j])] += id[i];
}
FOR(i, 0, m) FOR(j, 0, 4) sum[i][j] %= mod, fsum[i] = (fsum[i] + sum[i][j]) % mod;
FOR(i, 0, n)
{
ll cur = 0;
FOR(j, 0, m)
cur += fsum[j] - sum[j][ch(s[i][j])];
cur = (mod + cur % mod) % mod;
ll rem = (idsum - id[i]) * k;
rem = (mod + rem % mod) % mod;
if (cur == rem)
return cout << i + 1 << endl, 0;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |