이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define int ll
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
const long long oo = 1e18;
const int MAX = 1e5 + 5;
const int BASE1 = 91, BASE2 = 101, MOD = 1e9 + 7;
int pw1[MAX], pw2[MAX];
int n, m, k;
vector<string> arr;
map<char, int> mp = {{'A', 'A'}, {'C', 'B'}, {'G', 'C'}, {'T', 'D'}};
pair<int, int> S[MAX][4];
void solve(){
cin >> n >> m >> k;
arr.resize(n);
for (int i = 0; i < n; i++)
{
cin >> arr[i];
for(char& c:arr[i]){
c = mp[c];
}
}
for(int j = 0; j < m; ++j){
for(int i = 0; i < n; ++i){
for(int k = 0; k < 4; ++k){
if(k != (arr[i][j] - 'A')){
S[j][k] = {(S[j][k].first + pw1[i]) % MOD, (S[j][k].second + pw2[i]) % MOD};
}
}
}
}
pair<int, int> H = {0, 0};
for (int i = 0; i < n; i++)
{
H = {(H.first + pw1[i] * k) % MOD, H.second + pw2[i] * k};
}
for(int i = 0; i < n; ++i){
H = {((H.first - pw1[i] * k) % MOD + 2 * MOD) % MOD,
((H.second - pw2[i] * k) % MOD + 2 * MOD) % MOD};
pair<int, int> tmp = {0, 0};
for(int j = 0; j < m; ++j){
tmp.first = (tmp.first + S[j][arr[i][j] - 'A'].first) % MOD;
tmp.second = (tmp.second + S[j][arr[i][j] - 'A'].second) % MOD;
}
if(tmp == H){
cout << i + 1 << '\n';
return;
}
H = {((H.first + pw1[i] * k)) % MOD,
((H.second + pw2[i] * k)) % MOD};
}
}
signed main()
{
pw1[0] = 1;
for(int i = 1; i < MAX; ++i){
pw1[i] = (pw1[i - 1] * BASE1) % MOD;
}
pw2[0] = 1;
for(int i = 1; i < MAX; ++i){
pw2[i] = (pw2[i - 1] * BASE2) % MOD;
}
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t){
t--;
solve();
}
}
# | 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... |