# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
725267 | acatmeowmeow | Osmosmjerka (COCI17_osmosmjerka) | C++11 | 4083 ms | 10796 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int gcd(int a, int b) {
return !b ? a : gcd(b, a % b);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, l;
cin >> n >> m >> l;
vector<vector<char>> grid(n + 5, vector<char>(m + 5));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> grid[i][j];
}
}
vector<int> dx = {-1, -1, 0, 1, 1, 1, 0, -1}, dy = {0, 1, 1, 1, 0, -1, -1, -1};
map<tuple<int, int, int, int>, int> cnt;
int sz = min(l, max(n, m)), r = l % sz, total = 0;
const int base1 = 31, base2 = 53, modulo = 1e9 + 7;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (int d = 0; d < 8; d++) {
int hsh1 = 0, rhsh1 = 0, hsh2 = 0, rhsh2 = 0;
for (int k = 0; k < sz; k++) {
int curx = (i + (k*dx[d]) % n + n) % n, cury = (j + (k*dy[d]) % m + m) % m;
hsh1 = (hsh1*base1) % modulo + (grid[curx][cury] - 'a' + 1), hsh1 %= modulo;
hsh2 = (hsh2*base2) % modulo + (grid[curx][cury] - 'a' + 1), hsh2 %= modulo;
if (k >= r) continue;
rhsh1 = (rhsh1*base1) % modulo + (grid[curx][cury] - 'a' + 1), rhsh1 %= modulo;
rhsh2 = (rhsh2*base1) % modulo + (grid[curx][cury] - 'a' + 1), rhsh2 %= modulo;
}
cnt[tuple<int, int, int, int>(hsh1, rhsh1, hsh2, rhsh2)]++;
total++;
}
}
}
int ans = 0;
for (auto&x : cnt) ans += x.second*x.second;
total *= total;
int d = gcd(ans, total);
ans /= d, total /= d;
cout << ans << "/" << total << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |