답안 #854527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854527 2023-09-27T20:46:32 Z smirichto Osmosmjerka (COCI17_osmosmjerka) C++17
0 / 160
3 ms 604 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() {
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
#endif
    io();
    ll tt = 1;
    //cin>>tt ;
    while (tt--) {
        solve();
    }

    return 0;
}

Compilation message

osmosmjerka.cpp: In function 'int main()':
osmosmjerka.cpp:95:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |     freopen("input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
osmosmjerka.cpp:96:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |     freopen("output.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 8
2 Runtime error 2 ms 604 KB Execution killed with signal 8
3 Runtime error 2 ms 604 KB Execution killed with signal 8
4 Runtime error 2 ms 604 KB Execution killed with signal 8
5 Runtime error 2 ms 604 KB Execution killed with signal 8
6 Runtime error 2 ms 604 KB Execution killed with signal 8
7 Runtime error 2 ms 604 KB Execution killed with signal 8
8 Runtime error 3 ms 604 KB Execution killed with signal 8