This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/** I can do this all day **/
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define Mp make_pair
#define SZ(x) (int)x.size()
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
const int N = 4110;
const ll mod = 1e9 + 21;
const ll mod2 = 998244353;
const ll inf = 8e18;
const int LOG = 22;
const ll base = 5e4 + 21;
char C[N];
int n, m, k, mark[N], a[N][N];
ll pw[N], ps[N], hsh[N][4];
int main()
{
pw[0] = 1;
ps[0] = 1;
for(int i = 1; i < N; i ++)
{
pw[i] = base * pw[i - 1] % mod;
ps[i] = (ps[i - 1] + pw[i]) % mod;
}
scanf("%d%d%d", &n, &m, &k);
for(int i = 0; i < n; i ++)
{
scanf("%s", C);
for(int j = 0; j < m; j ++)
{
int cu;
if(C[j] == 'A') cu = 0;
else if(C[j] == 'T') cu = 1;
else if(C[j] == 'C') cu = 2;
else cu = 3;
a[i][j] = cu;
///printf("%d", a[i][j]);
hsh[j][cu] = (hsh[j][cu] + pw[i]) % mod;
}
///printf("\n");
}
for(int i = 0; i < n; i ++)
{
ll cu = 0;
for(int j = 0; j < m; j ++)
{
cu = (cu + ps[n - 1] - hsh[j][a[i][j]] + mod) % mod;
}
///printf("%lld ", cu);
if(cu == (ps[n - 1] - pw[i] + mod) % mod * k % mod)
{
return !printf("%d", i + 1);
}
}
return 0;
}
/** test corner cases(n = 1?) watch for overflow or minus indices **/
Compilation message (stderr)
genetics.cpp: In function 'int main()':
genetics.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
42 | scanf("%d%d%d", &n, &m, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
genetics.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
45 | scanf("%s", C);
| ~~~~~^~~~~~~~~
# | 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... |