Submission #725262

# Submission time Handle Problem Language Result Execution time Memory
725262 2023-04-17T05:49:12 Z acatmeowmeow Osmosmjerka (COCI17_osmosmjerka) C++11
100 / 160
4000 ms 8652 KB
#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<pair<int, int>, int> cnt;
	int sz = min(l, max(n, m)), r = l % sz, total = 0;
	const int base = 31, 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 hsh = 0, rhsh = 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;
					hsh = (hsh*base) % modulo + (grid[curx][cury] - 'a' + 1), hsh %= modulo;
					if (k >= r) continue;
					rhsh = (rhsh*base) % modulo + (grid[curx][cury] - 'a' + 1), rhsh %= modulo;
				}
				cnt[pair<int, int>(hsh, rhsh)]++;
				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
1 Correct 1 ms 232 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 11 ms 448 KB Output is correct
6 Incorrect 130 ms 1736 KB Output isn't correct
7 Incorrect 2854 ms 8652 KB Output isn't correct
8 Execution timed out 4080 ms 8072 KB Time limit exceeded