답안 #823625

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
823625 2023-08-12T22:53:46 Z EthanKim8683 Osmosmjerka (COCI17_osmosmjerka) C++17
100 / 160
696 ms 50920 KB
#include<bits/stdc++.h>
using namespace std;
using I=int;
using C=char;
using Lli=long long int;
using B=bool;
const I M=500;
const I N=500;
const Lli MOD=(1ll<<31)-1;
const Lli BAS=37187;
I dx[]{-1,-1,-1,0,0,1,1,1},dy[]{-1,0,1,-1,1,-1,0,1};
C blks[M][N+1];
B viss[N][M][8];
Lli hshs[N][M][8];
map<Lli,I>cnts;
I m,n;
C get(I i,I j,I dir,I len){
  return blks[((i+len*dx[dir])%m+m)%m][((j+len*dy[dir])%n+n)%n];
}
I main(){
  cin.tie(0)->sync_with_stdio(0);
  I k;cin>>m>>n>>k;
  for(I i=0;i<m;i++)cin>>blks[i];
  I len=min(max(n,m),k);
  Lli pow=1;
  for(I i=1;i<=len;i++)pow=pow*BAS%MOD;
  for(I i=0;i<8;i++)for(I j=0;j<m;j++)for(I l=0;l<n;l++){
    if(viss[j][l][i])continue;
    I x=j,y=l;
    for(;x>=0&&x<m&&y>=0&&y<n;x-=dx[i],y-=dy[i]);
    x+=dx[i],y+=dy[i];
    Lli hsh=0;
    for(I o=0;o<len;o++)hsh=(hsh*BAS+get(x,y,i,o))%MOD;
    for(;x>=0&&x<m&&y>=0&&y<n;x+=dx[i],y+=dy[i]){
      hshs[x][y][i]=hsh,viss[x][y][i]=1;
      hsh=((hsh*BAS+get(x,y,i,len)-get(x,y,i,0)*pow)%MOD+MOD)%MOD;
    }
  }
  for(I i=0;i<m;i++)for(I j=0;j<n;j++)for(I l=0;l<8;l++)cnts[hshs[i][j][l]]++;
  Lli num=0,den=8*n*m;
  den*=den;
  for(auto[hsh,cnt]:cnts)num+=(Lli)cnt*cnt;
  Lli fac=gcd(num,den);
  printf("%lli/%lli\n",num/fac,den/fac);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Incorrect 12 ms 3028 KB Output isn't correct
7 Incorrect 106 ms 14000 KB Output isn't correct
8 Incorrect 696 ms 50920 KB Output isn't correct