This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Om Namah Shivaya
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x, y) ((x + y - 1) / (y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep1(i, n) for(int i = 1; i <= n; ++i)
#define rev(i, s, e) for(int i = s; i >= e; --i)
#define trav(i, a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a, b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a, b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
refs:
edi
*/
const int MOD = 1e9 + 7;
const int N = 4100 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
vector<int> ps = {5791, 8237, 3067, 6991, 3527};
vector<int> mods = {791139137, 433567597, 271149607, 561259969, 222708581};
ll pows[N][2];
void precalc() {
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
shuffle(all(ps), rng);
shuffle(all(mods), rng);
rep(j, 2) {
pows[0][j] = 1;
rep1(i, N - 1) {
pows[i][j] = pows[i - 1][j] * ps[j] % mods[j];
}
}
}
void solve(int test_case)
{
precalc();
ll n,m,k; cin >> n >> m >> k;
ll a[n+5][m+5];
rep1(i,n){
rep1(j,m){
char ch; cin >> ch;
ll x = 0;
if(ch == 'A') x = 0;
if(ch == 'C') x = 1;
if(ch == 'G') x = 2;
if(ch == 'T') x = 3;
a[i][j] = x;
}
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
auto random = [&](ll l, ll r){
return uniform_int_distribution<ll>(l,r)(rng);
};
vector<pll> w(n+5);
rep1(i,n){
w[i].ff = random(1,mods[0]-1);
w[i].ss = random(1,mods[1]-1);
}
pll want = {0,0};
rep1(i,n){
want.ff += (w[i].ff * k);
want.ff %= mods[0];
want.ss += (w[i].ss * k);
want.ss %= mods[1];
}
pll col_sum[m+5][4];
memset(col_sum,0,sizeof col_sum);
rep1(i,n){
rep1(j,m){
ll ch = a[i][j];
col_sum[j][ch].ff = (col_sum[j][ch].ff + w[i].ff) % mods[0];
col_sum[j][ch].ss = (col_sum[j][ch].ss + w[i].ss) % mods[1];
}
}
rep1(i,n){
pll sum = {0,0};
rep1(j,m){
rep(ch,4){
if(ch != a[i][j]){
sum.ff = (sum.ff + col_sum[j][ch].ff) % mods[0];
sum.ss = (sum.ss + col_sum[j][ch].ss) % mods[1];
}
}
}
sum.ff = (sum.ff + w[i].ff * k) % mods[0];
sum.ss = (sum.ss + w[i].ss * k) % mods[1];
if(sum == want){
cout << i << endl;
return;
}
}
assert(0);
}
int main()
{
fastio;
int t = 1;
// cin >> t;
rep1(i, t) {
solve(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... |