Submission #854529

# Submission time Handle Problem Language Result Execution time Memory
854529 2023-09-27T20:46:49 Z smirichto Osmosmjerka (COCI17_osmosmjerka) C++17
80 / 160
4000 ms 15732 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pi pair<ll,ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define alll(x) ((x).begin()+1), (x).end()
#define clean(v) (v).resize(distance((v).begin(), unique(all(v))));
#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define mod mod
#define endl '\n'
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 998244353;

void io() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
}

template<class T>
bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

template<class T>
bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }

void nop() {
    cout << -1 << endl;
    return;
}

long long exp(long long x, long long y, long long p = mod) {
    long long res = 1;
    x %= p;
    while (y) {
        if (y & 1) {
            res *= x;
            res %= p;
        }
        x *= x;
        x %= p;
        y >>= 1;
    }
    return res;
}



const int N = 505 ;
char tab[N][N] ;

int di[] = {-1 , -1 , -1 , 0 , 1 , 1 , 1 , 0};
int dj[] = {-1 , 0 , 1 ,1 , 1 ,0 , -1 , -1};
int n , m , kk;
int base = 9973 ;
int get(char c){
    return c - 'a' ;
}
ll get_hash(int si , int sj , int dir , int len = 0)
{
    if(len==min(n , kk)) return 0 ;
    return get(tab[si][sj]) + base * get_hash((si + di[dir] + n) % n , (sj + dj[dir] + n)%n , dir , len+1) ;
}
void solve() {
    cin>>n>>m>>kk ;
    for(int i = 0 ; i<n ; i++){
        for(int j = 0 ; j<m ; j++){
            cin>>tab[i][j] ;
        }
    }
    map<ll,int> mp ;
    ll good = 0 ;
    for(int i = 0 ; i<n ; i++){
        for(int j = 0 ; j<m ; j++){
            for(int k = 0 ; k<8 ; k++){
                mp[get_hash(i , j , k)]++ ;
            }
        }
    }
    ll tot = n * m * 8 ;tot *= tot ;
    for(auto p : mp){
        good += p.S * p.S ;
    }
    ll gd = __gcd(tot , good) ;
    cout<<good / gd<<"/"<<tot/gd<<endl;

}

int main() {

    io();
    ll tt = 1;
    //cin>>tt ;
    while (tt--) {
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 468 KB Output isn't correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 5 ms 476 KB Output is correct
6 Incorrect 67 ms 2388 KB Output isn't correct
7 Incorrect 893 ms 3928 KB Output isn't correct
8 Execution timed out 4035 ms 15732 KB Time limit exceeded