Submission #1078106

#TimeUsernameProblemLanguageResultExecution timeMemory
1078106Neco_arcOsmosmjerka (COCI17_osmosmjerka)C++17
120 / 160
4061 ms21880 KiB
#include <bits/stdc++.h> #ifdef LOCAL #include <bits/debug.hpp> #endif // LOCAL #define ll long long #define all(x) x.begin(), x.end() #define Neco "Osmosmjerka" #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin()) #define getbit(x,i) ((x >> i)&1) #define _left id * 2, l, mid #define _right id * 2 + 1, mid + 1, r #define cntbit(x) __builtin_popcountll(x) #define fi(i, a, b) for(int i = a; i <= b; i++) #define fid(i, a, b) for(int i = a; i >= b; i--) #define maxn (int) 507 using namespace std; const ll mod = 1e9 + 7; //972663749 const ll base = 911382323; const int dx[] = {0, -1, 0, 1, -1, -1, 1, 1}; const int dy[] = {-1, 0, 1, 0, -1, 1, -1, 1}; int n, m, k; ll po[maxn * maxn]; char a[maxn][maxn]; unordered_map<ll, ll> S; int nex(int x, int y) { if(x < 1) x = y; if(x > y) x -= y; return x; } bool inside(int i, int j) { return 1 <= i && i <= n && 1 <= j && j <= m; } ll MulHash(ll a, ll p, ll k) { ll ans = 0; for(; k > 0; k >>= 1, a = (a * p + a) % mod, p = (p * p) % mod) { if(k & 1) ans = (ans * p + a) % mod; } return ans; } ll HASH(string s) { ll ans = 0; for(char c : s) ans = (ans * base + c) % mod; return ans; } void solve() { cin >> n >> m >> k; fi(i, 1, n) fi(j, 1, m) cin >> a[i][j]; fi(i, 1, n) fi(j, 1, m) fi(t, 0, 7) { ll Hash = 0, remain = 0, len = 0; int u = i, v = j; do { ++len; Hash = (Hash * base + a[u][v]) % mod; u = nex(u + dx[t], n), v = nex(v + dy[t], m); } while(!(u == i && v == j)); for(int u = i, v = j, _ = 1; _ <= k % len; ++_) { remain = (remain * base + a[u][v]) % mod; u = nex(u + dx[t], n), v = nex(v + dy[t], m); } Hash = MulHash(Hash, po[len], k / len); Hash = (Hash * po[k % len] + remain) % mod; S[Hash] ++; } ll mau = 1ll * m * n * 8; mau = mau * mau; ll tu = 0; for(auto [x, sl] : S) { tu = 1ll * tu + sl * sl; } ll g = __gcd(tu, mau); tu /= g, mau /= g; cout << tu << '/' << mau; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(Neco".inp", "r")) { freopen(Neco".inp", "r", stdin); freopen(Neco".out", "w", stdout); } int nTest = 1; // cin >> nTest; po[0] = 1; fi(i, 1, maxn * maxn - 2) po[i] = po[i - 1] * base % mod; while(nTest--) { solve(); } return 0; }

Compilation message (stderr)

osmosmjerka.cpp: In function 'int main()':
osmosmjerka.cpp:110:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
osmosmjerka.cpp:111:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |         freopen(Neco".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...