이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
mt19937 Rand(chrono::high_resolution_clock::now().time_since_epoch().count());
const int maxN=4105,MOD=1e9+7;
const ll inf=2e18;
int n,m,k;
ll Hash[maxN+1],f[maxN+1][4];
string s[maxN+1];
ll gen(ll MOD)
{
return Rand()%MOD;
}
int cd(char c)
{
if(c=='A')
{
return 0;
}
if(c=='C')
{
return 1;
}
if(c=='G')
{
return 2;
}
return 3;
}
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>k;
ll base=0;
for(int i=1;i<=n;i++)
{
cin>>s[i];
s[i]=" "+s[i];
Hash[i]=gen(MOD);
base=(base+Hash[i])%MOD;
}
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
int tmp=cd(s[j][i]);
f[i][tmp]=(f[i][tmp]+Hash[j])%MOD;
}
}
for(int i=1;i<=n;i++)
{
ll res=0;
for(int j=1;j<=m;j++)
{
int tmp=cd(s[i][j]);
ll cur=(base-f[j][tmp])%MOD;
if(cur<0)
{
cur+=MOD;
}
res=(res+cur)%MOD;
//cout<<i<<" "<<j<<" "<<cur<<" "<<f[j][1-tmp]<<'\n';
}
ll cur=(base-Hash[i]+MOD)%MOD;
//cout<<res<<" "<<base<<'\n';
if(res==(k*cur)%MOD)
{
cout<<i;
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... |