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 <bits/stdc++.h>
#define N 5005
#define ll long long int
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;
ll n,m,ar[N][N],sum,t,pw[N],p=5,tut[N][10],top,k;
// ll p=100003;
char s[N][N];
ll add(ll x,ll y)
{
x%=mod;
y%=mod;
x+=y;
x%=mod;
while(x<0)
x+=mod;
return x;
}
ll cik(ll x,ll y)
{
x%=mod;
y%=mod;
x-=y;
x%=mod;
while(x<0)
x+=mod;
return x;
}
ll carp(ll x,ll y)
{
x%=mod;
y%=mod;
x*=y;
x%=mod;
while(x<0)
x+=mod;
return x;
}
int main()
{
fast;
cin>>n>>m>>k;
// cout<<k<<endl;
pw[0]=1;
for(int i=1;i<=5e3;i++)
pw[i]=carp(pw[i-1],p);
// cout<<k<<endl;
fo(i,1,n)
cin>>s[i]+1;
fo(i,1,n)
fo(j,1,m)
{
if(s[i][j]=='A')
ar[i][j]=1;
if(s[i][j]=='T')
ar[i][j]=2;
if(s[i][j]=='G')
ar[i][j]=3;
if(s[i][j]=='C')
ar[i][j]=4;
}
for(int i=1;i<=n;i++)
{
// cout<<top<<sp<<pw[i-1]<<sp<<k<<endl;
top=add(top,carp(pw[i-1],k));
}
fo(i,1,n)
{
fo(j,1,m)
{
for(int h=1;h<=4;h++)
{
if(h==ar[i][j])
continue;
tut[j][h]=add(tut[j][h],pw[i-1]);
// cout<<pw[i]<<endl;
}
}
}
// for(int i=1;i<=4;i++)
// {
// for(int j=1;j<=m;j++)
// cout<<tut[j][i]<<sp;
// cout<<endl;
// }
// cout<<endl;
for(int i=1;i<=n;i++)
{
ll x=0;
for(int j=1;j<=m;j++)
x=add(x,tut[j][ar[i][j]]);
// cout<<i<<sp<<x<<sp<<cik(top,carp(pw[i-1],k))<<sp<<top<<endl;
if(x==cik(top,carp(pw[i-1],k)))
return cout<<i,0;
}
cout<<top<<endl;
}
Compilation message (stderr)
genetics.cpp: In function 'int main()':
genetics.cpp:69:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
cin>>s[i]+1;
~~~~^~
# | 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... |