답안 #477704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477704 2021-10-03T07:30:37 Z MohammadAghil Osmosmjerka (COCI17_osmosmjerka) C++14
140 / 160
2230 ms 78080 KB
#include <bits/stdc++.h> 
  using  namespace std;
typedef  long long ll;
typedef  pair<int, int> pp;
#define  rep(i,l,r) for(int i = (l); i < r; i++)
#define  per(i,r,l) for(int i = (r); i >= l; i--)
#define  all(x) x.begin(), x.end()
#define  sz(x) (int)(x).size()
#define  pb push_back
#define  ff first
#define  ss second 

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll mod = 1e9 + 9, maxn = 5e2 + 5, inf = 1e9 + 5, p = 9973, lg = 31;

ll jmp[maxn][maxn][lg];
int n, m, k; 
ll pw[lg];
vector<ll> st;

ll add(int a, int b, int c, int md){
    return (a + ((1LL << b)%md)*c + md)%md;
}

void calc(int x, int y){
    rep(k,1,lg){
        rep(i,0,n){
            rep(j,0,m){
                jmp[i][j][k] = (jmp[i][j][k-1]*pw[k-1]%mod + 
                    jmp[add(i, k-1, x,  n)][add(j, k-1, y,  m)][k-1])%mod;
            }
        }
    }
    rep(i,0,n){
        rep(j,0,m){
            ll res = 0;
            pp cr = {i, j};
            rep(b,0,lg){
                if(k&(1 << b)){
                    res = (res*pw[b]%mod + jmp[cr.ff][cr.ss][b])%mod;
                    cr.ff = add(cr.ff, b, x, n);
                    cr.ss = add(cr.ss, b, y, m);
                }
            }
            st.pb(res);
        }
    }
}

int main(){
    cin.tie(0) -> sync_with_stdio(0);
    cin >> n >> m >> k;
    rep(i,0,n){
        rep(j,0,m){
            char c; cin >> c;
            jmp[i][j][0] = int(c);
        }
    }    
    pw[0] = p;
    rep(i,1,lg){
        pw[i] = 1LL*pw[i-1]*pw[i-1]%mod;
    }
    rep(i,-1,2){
        rep(j,-1,2){
            if(i == 0 && j == 0) continue;
            calc(i, j);
        }
    }
    sort(all(st));
    ll lst = -1, cnt = 0;
    ll t = 0, b = 64LL*n*n*m*m;
    rep(i,0,sz(st)){
        if(lst != st[i]){
            t += 1LL*cnt*cnt;
            cnt = 0;
        }
        lst = st[i];
        cnt++;
    } t += cnt*cnt;
    ll g = __gcd(t, b);
    cout << t/g << '/' << b/g;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 6 ms 1100 KB Output is correct
6 Correct 36 ms 3272 KB Output is correct
7 Correct 513 ms 19928 KB Output is correct
8 Incorrect 2230 ms 78080 KB Output isn't correct