Submission #1078176

#TimeUsernameProblemLanguageResultExecution timeMemory
1078176Neco_arcOsmosmjerka (COCI17_osmosmjerka)C++17
160 / 160
1257 ms86324 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" #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; char a[maxn][maxn]; ll H[maxn][maxn][32], po[32]; unordered_map<ll, ll> S; int md(int x, int m) { return ((x % m) + m) % m; } ll calc(int u, int v, int t) { ll ans = 0; fi(i, 0, 30) if(getbit(k, i)) { ans = (ans * po[i] + H[u][v][i]) ; u = md(u + (1 << i) * dx[t], n); v = md(v + (1 << i) * dy[t], m); } 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, 0, n - 1) fi(j, 0, m - 1) cin >> a[i][j]; po[0] = base; fi(i, 1, 30) po[i] = po[i - 1] * po[i - 1] ; fi(t, 0, 7) { fi(i, 0, n - 1) fi(j, 0, m - 1) H[i][j][0] = a[i][j]; fi(p, 1, 30) fi(i, 0, n - 1) fi(j, 0, m - 1) { int u = md(i + (1 << (p - 1)) * dx[t], n); int v = md(j + (1 << (p - 1)) * dy[t], m); H[i][j][p] = (H[i][j][p - 1] * po[p - 1] + H[u][v][p - 1]) ; } fi(i, 0, n - 1) fi(j, 0, m - 1) { S[calc(i, j, t)] ++; } } ll mau = 1ll * (n * m * 8) * (n * m * 8); ll tu = 0; for(auto [x, sl] : S) tu = tu + 1ll * 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 ; while(nTest--) { solve(); } return 0; }

Compilation message (stderr)

osmosmjerka.cpp: In function 'int main()':
osmosmjerka.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
osmosmjerka.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen(Neco".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
osmosmjerka.cpp:106:47: warning: iteration 32 invokes undefined behavior [-Waggressive-loop-optimizations]
  106 |     fi(i, 1, maxn * maxn - 2) po[i] = po[i - 1] * base ;
      |                                       ~~~~~~~~^
osmosmjerka.cpp:14:38: note: within this loop
   14 | #define fi(i, a, b) for(int i = a; i <= b; i++)
......
  106 |     fi(i, 1, maxn * maxn - 2) po[i] = po[i - 1] * base ;
      |        ~~~~~~~~~~~~~~~~~~~~~          
osmosmjerka.cpp:106:5: note: in expansion of macro 'fi'
  106 |     fi(i, 1, maxn * maxn - 2) po[i] = po[i - 1] * base ;
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...