# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200205 | MetB | Osmosmjerka (COCI17_osmosmjerka) | C++14 | 2339 ms | 73208 KiB |
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 1000001
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;
int n, m, k;
ull p = 37, pm[N];
ull d[500][500][20];
string s[1000];
map <ull, int> mp;
ull query (int x, int y, int h, int v, int k) {
ull sum = 0, mult = 1;
for (int i = 0; i <= 19; i++) {
if (k & (1 << i)) {
sum += d[x][y][i] * mult;
x = (x + (n + h) * (1 << i)) % n;
y = (y + (m + v) * (1 << i)) % m;
mult = mult * pm[i];
}
}
return sum;
}
ll gcd (ll a, ll b) {
if (!b) return a;
return gcd (b, a % b);
}
int main () {
cin >> n >> m >> k;
k = min (k, n * m);
for (int i = 0; i < n; i++)
cin >> s[i];
pm[0] = p;
for (int i = 1; i <= 20; i++)
pm[i] = pm[i-1] * pm[i-1];
for (int h = -1; h <= 1; h++)
for (int v = -1; v <= 1; v++) {
if (!h && !v) continue;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
d[i][j][0] = s[i][j] - 'a';
}
for (int w = 0; w < 19; w++)
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int nx = (i + (n + h) * (1 << w)) % n;
int ny = (j + (m + v) * (1 << w)) % m;
d[i][j][w+1] = d[i][j][w] + d[nx][ny][w] * pm[w];
}
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
mp[query (i, j, h, v, k)]++;
}
}
ll ans = 0, all = (n * m * 8) * (n * m * 8);
for (auto a : mp) {
ans += a.second * a.second;
}
cout << ans / gcd (ans, all) << "/" << all / gcd (ans, all);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |