This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <string>
#include <iostream>
#include <random>
#include <time.h>
#define int int64_t
using namespace std;
int getchar(char c)
{
if (c == 'A') return 0;
else if (c == 'C') return 1;
else if (c == 'G') return 2;
else return 3;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int N_attemps = 3;
int MOD = 1e9 + 7;
int n, m, k;
cin >> n >> m >> k;
mt19937 rng(time(0));
uniform_int_distribution<int> uni(0, 1e7);
vector<string> ip(n);
for (int i = 0; i < n; i++)
{
cin >> ip[i];
}
vector<int> res(n, 0);
for (int z = 0; z < N_attemps; z++)
{
int s = 0;
vector<int> svals(n);
for (int i = 0; i < n; i++)
{
svals[i] = uni(rng);
s += svals[i];
}
vector<vector<int>> table(m, vector<int>(4, 0));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
table[j][getchar(ip[i][j])] = (table[j][getchar(ip[i][j])] + svals[i]) % MOD;
}
}
for (int i = 0; i < n; i++)
{
int ssum = 0;
for (int j = 0; j < m; j++)
{
int curr = 0;
for (int f = 0; f < 4; f++)
{
curr += table[j][f];
}
curr -= table[j][getchar(ip[i][j])];
ssum = (ssum + curr) % MOD;
}
if (ssum == (1LL*(s - svals[i])*k) % MOD) res[i]++;
}
}
int mmax = -1;
int mp = -1;
for (int i = 0; i < n; i++)
{
if (res[i] > mmax)
{
mmax = res[i];
mp = i;
}
}
cout << mp + 1 << "\n";
}
# | 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... |