Submission #65436132


Source Code Expand

import heapq
import math
import sys
from bisect import bisect_left
from collections import deque

input = sys.stdin.readline
print = sys.stdout.write


# sys.setrecursionlimit(10 ** 7)
# mod =  998244353
# MAX = 9_999_987_654_321_000_000
# dir4 = [[-1,0],[1,0],[0,-1],[0,1]]
# dir8 = [[-1,0],[-1,-1],[0,-1],[1,-1],[1,0],[1,1],[0,1],[-1,1]]




def solve():
  n = int(input().rstrip())
  a = []
  b= []
  for i in range(n):
    a.append(list(input().rstrip()))
  for i in range(n):
    b.append(list(input().rstrip()))
  ans = sys.maxsize
  for z in range(1,5):
    count = z%4
    c = [["" for _ in range(n)]for _ in range(n)]
    #round
    for i in range(n):
      for j in range(n):
        c[j][n-i-1] = a[i][j]

    #
    for i in range(n):
      for j in range(n):
        if c[i][j] != b[i][j]:
          count+=1
    ans = min(count,ans)
    #
    for i in range(n):
      for j in range(n):
        a[i][j] = c[i][j]
  print("%d"%ans)


        



if __name__ == '__main__':
  solve()

Submission Info

Submission Time
Task B - Grid Rotation
User fiveIsDoor
Language Python (PyPy 3.10-v7.3.12)
Score 250
Code Size 1048 Byte
Status AC
Exec Time 87 ms
Memory 84260 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 250 / 250
Status
AC × 2
AC × 21
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
random_01.txt AC 76 ms 81432 KiB
random_02.txt AC 79 ms 81480 KiB
random_03.txt AC 77 ms 81316 KiB
random_04.txt AC 83 ms 83512 KiB
random_05.txt AC 78 ms 81636 KiB
random_06.txt AC 78 ms 80948 KiB
random_07.txt AC 78 ms 81508 KiB
random_08.txt AC 84 ms 83624 KiB
random_09.txt AC 86 ms 83852 KiB
random_10.txt AC 85 ms 84148 KiB
random_11.txt AC 87 ms 83960 KiB
random_12.txt AC 86 ms 84100 KiB
random_13.txt AC 85 ms 84260 KiB
random_14.txt AC 84 ms 84204 KiB
random_15.txt AC 84 ms 83968 KiB
random_16.txt AC 84 ms 83944 KiB
random_17.txt AC 74 ms 76820 KiB
random_18.txt AC 72 ms 77020 KiB
random_19.txt AC 73 ms 76828 KiB
sample_01.txt AC 73 ms 77096 KiB
sample_02.txt AC 73 ms 76876 KiB