이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
const ll INF=LLONG_MAX;
const int mxn=4200;
ll dp[mxn][4];
ll pw[mxn];
string s[mxn];
void mul(ll &a, ll b){
a%=MOD; b%=MOD; a*=b; a%=MOD;
}
void add(ll &a, ll b){
a%=MOD; b%=MOD; a+=b; a%=MOD;
}
int conv(char c){
if(c=='A')return 0;
if(c=='C')return 1;
if(c=='G')return 2;
return 3;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
int n,m,k;
cin >> n >> m >> k;
pw[0]=1ll;
ll allpw = 0ll, allk = 0ll;
for(int i=1; i<=n; i++){
cin >> s[i];
pw[i] = pw[i-1]*4ll%MOD;
add(allpw,pw[i]);
add(allk,(k*pw[i])%MOD);
for(int j=0; j<m; j++){
int ch = conv(s[i][j]);
add(dp[j][ch],pw[i]);
}
}
for(int i=1; i<=n; i++){
ll cur = 0ll;
for(int j=0; j<m; j++){
int ch = conv(s[i][j]);
add(cur,(allpw - dp[j][ch]+MOD)%MOD);
}
add(cur,k*pw[i]%MOD);
if(allk==cur){
cout << i << endl;
return 0;
}
}
}
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN
# | 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... |