Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Dice IV

 Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.

Input

  In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.

Output

  Print "Yes" if given dices are all different, otherwise "No" in a line.

Constraints

$2 \leq n \leq 100$

$0 \leq $ the integer assigned to a face $ \leq 100$

Sample Input 1

3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1

Sample Output 1

No

Sample Input 2 

3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6

Sample Output 2

Yes



Sample input:
3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1


Sample output:
No

Submission status: Accepted

Solution code:
class _Dice:
    
    def __init__(self, nums):
        self.nums = list(nums)
        
    @property
    def top(self):
        return self.nums[0]
        
    def _shift(self, *pairs):
        for pair in pairs:
            num = self.nums[pair[0]]
            self.nums[pair[0]] = self.nums[pair[1]]
            self.nums[pair[1]] = num
            
    def get_matches(self, num):
        return [i for i, m in enumerate(self.nums) if m == num]
            
    def go(self, opes:str):
        for ope in opes:
            if ope == "N":
                self.go_north()
            elif ope == "E":
                self.go_east()
            elif ope == "W":
                self.go_west()
            else:
                self.go_south()
                
    def go_top(self, index):
        
        if index == 1:
            self.go_north()
        elif index == 2:
            self.go_west()
        elif index == 3:
            self.go_east()
        elif index == 4:
            self.go_south()
        elif index == 5:
            self.go_north()
            self.go_north()
            
    def go_ahead(self, index):

        if index == 2:
            self.go_cw()
        elif index == 4:
            self.go_cw()
            self.go_cw()
        elif index == 3:
            self.go_ccw()
            
        
    def go_north(self):
        self._shift((0, 1), (1, 5), (5, 4))
        
    def go_east(self):
        self._shift((0, 3), (3, 5), (5, 2))
        
    def go_west(self):
        self._shift((0, 2), (2, 5), (5, 3))
        
    def go_south(self):
        self._shift((0, 4), (4, 5), (5, 1))
        
    def go_ccw(self):
        self._shift((3, 4), (4, 2), (2, 1))
        
    def go_cw(self):
        self._shift((3, 1), (1, 2), (2, 4))
        
        
class Dice(_Dice):
    
    @classmethod
    def isequal(cls, a:_Dice, b:_Dice):
                
        a_clone = a.nums.copy()
        for top in a.get_matches(b.nums[0]):
            a.go_top(top)
            a_top_clone = a.nums.copy()
            for ahead in a.get_matches(b.nums[1]):
                a.go_ahead(ahead)
                
                for i, j in zip(a.nums, b.nums):
                    if i != j:
                        break
                else:
                    return True
                
                a.nums = a_top_clone.copy()
                
            a.nums = a_clone.copy()
            
        else:
            return False
        
def check(dices):
    for i, dice_A in enumerate(dices):
        if i == len(dices) - 1:
            break
        
        for dice_B in dices[i + 1:]:
            if Dice.isequal(dice_A, dice_B):
                return False
        
    return True
        

count = int(input())
dices = [Dice(map(int, input().split())) for _ in range(count)]
print("Yes" if check(dices) else "No")

Submission status: Accepted

Solution code:
class Dice():
    def __init__(self):
        self.nums = list(range(6))
        self.work = list(range(6))

    def set_nums(self, n0, n1, n2, n3, n4, n5):
        self.nums[0] = n0
        self.nums[1] = n1
        self.nums[2] = n2
        self.nums[3] = n3
        self.nums[4] = n4
        self.nums[5] = n5

    def rotate(self, cmd):
        for i in range(6):
            # deepcopy
            self.work[i] = self.nums[i]

        if cmd == 'N':
            self.set_nums(self.work[1], self.work[5], self.work[2], self.work[3], self.work[0], self.work[4])
        elif cmd == 'S':
            self.set_nums(self.work[4], self.work[0], self.work[2], self.work[3], self.work[5], self.work[1]),
        elif cmd == 'E':
            self.set_nums(self.work[3], self.work[1], self.work[0], self.work[5], self.work[4], self.work[2])
        else:
            self.set_nums(self.work[2], self.work[1], self.work[5], self.work[0], self.work[4], self.work[3])

    def top(self):
        return self.nums[0]

    def right(self, top, front):
        # サイコロの面IDを返す
        if top == 1:
            return [3,5,2,4][front-2]
        elif top == 6:
            return [4,2,5,3][front-2]
        elif top == 2:
            # 0が返る場合は不正なサイコロ
            return [4,0,1,6,0,3][front-1]
        elif top == 5:
            # 0が返る場合は不正なサイコロ
            return [3,0,6,1,0,4][front-1]
        elif top == 3:
            # 0が返る場合は不正なサイコロ
            return [2,6,0,0,1,5][front-1]
        elif top == 4:
            # 0が返る場合は不正なサイコロ
            return [5,1,0,0,6,2][front-1]
        else:
            pass

    def rolls(self):
        # 上面、前面、右面、左面、奥面、下面の値を返す
        return [self.nums[i] for i in range(6)]


import random

# init
n = int(input())
nums = [[int(arg) for arg in input().split()] for _ in range(n)]
dices = [Dice() for _ in range(n)]
for i in range(n):
    dices[i].set_nums(*nums[i])

master_roll = dices.pop(0).rolls()
results = []
for dice in dices:
    for i in range(1000):
        cmd = ['N', 'S', 'E', 'W'][random.randint(0,3)]
        dice.rotate(cmd)
        dice_roll = dice.rolls()
        if all([master_roll[i] == dice_roll[i] for i in range(6)]):
            results.append(0)
            break
print('Yes' if len(results) == 0 else 'No')

Submission status: Accepted

Solution code:
import itertools
import copy

class Dice:
    def __init__(self,d1,d2,d3,d4,d5,d6):
        self.dice = [d1,d2,d3,d4,d5,d6]
    def turn(self,dir):
        if dir == 'S':
            self.dice = [self.dice[4],self.dice[0],self.dice[2],self.dice[3],self.dice[5],self.dice[1]]
        if dir == 'N':
            self.dice = [self.dice[1],self.dice[5],self.dice[2],self.dice[3],self.dice[0],self.dice[4]]
        if dir == 'W':
            self.dice = [self.dice[2],self.dice[1],self.dice[5],self.dice[0],self.dice[4],self.dice[3]]
        if dir == 'E':
            self.dice = [self.dice[3],self.dice[1],self.dice[0],self.dice[5],self.dice[4],self.dice[2]]


def check_1_column(dice1,dice2):
    '''
    input:Diceクラスを2つ読み込む
    output:Dice1を4回縦回転して、Dice2と一致するようであれば1を返す。一致しなければ、0を返す。
    '''
    for b in range(4):
        if dice1.dice[0] == dice2.dice[0] and dice1.dice[1] == dice2.dice[1] and dice1.dice[2] == dice2.dice[2] and dice1.dice[3] == dice2.dice[3] and dice1.dice[4] == dice2.dice[4] and dice1.dice[5] == dice2.dice[5]:
            return 1
        dice1.turn('N')
    return 0

def check_all(dice1,dice2):

    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('N')
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    dice1.turn('E')
    if check_1_column(dice1,dice2):
        return 1
    return 0

# 入力
n = int(input())
input_dice = []
for a in range(n):
    temp = list(map(int,input().split()))
    temp_class = Dice(temp[0],temp[1],temp[2],temp[3],temp[4],temp[5])
    input_dice.append(temp_class)

# Diceを2つ入力
# 一致してたら、Trueを返す。
flag = 0
for a in itertools.combinations(input_dice,2):
    temp1 = copy.copy(a[0])
    temp2 = copy.copy(a[1])
    flag += check_all(temp1,temp2)
if flag == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
class diceClass:
	def __init__(self, valuelist):
		self.valuelist = valuelist
		self.t = valuelist[0]
		self.b = valuelist[5]
		self.n = valuelist[4]
		self.s = valuelist[1]
		self.e = valuelist[2]
		self.w = valuelist[3]

	def print(self):
		print('t={0}, b={1}, n={2}, s={3}, w={4}, e={5}'.format(self.t, self.b, self.n, self.s, self.e, self.w))

	def throw(self, direction):
		# N,S,W,E
		if direction == 'N':
			self.t, self.s, self.b, self.n = self.s, self.b, self.n, self.t
		elif direction == 'S':
			self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
		elif direction == 'W':
			self.t, self.e, self.b, self.w = self.e, self.b, self.w, self.t
		elif direction == 'E':
			self.t, self.e, self.b, self.w = self.w, self.t, self.e, self.b

def compare(lst1, lst2):
	for i in lst1:
		if lst2.count(i) != 1:
			return False
	return True

n = int(input())
dirinput = 'WWWWSWWWWSWWWWSWWWWWSWWWWSSWWWW'
classes = []
for i in range(0,n):
	arrinput = list(map(int, input().split()))
	dice = diceClass(arrinput)
	dicresult = []
	for s in dirinput:
		dice.throw(s)
		if dicresult.count([[dice.t, dice.s], dice.e]) == 0:
			dicresult.append([[dice.t, dice.s], dice.e])
	classes.append(dicresult)

for i in range(0, len(classes)-1):
	for j in range(i+1,len(classes)):
		if compare(classes[i],classes[j]) == True:
			print('No')
			exit(0)

print('Yes')

#		print(classes[i])
#		for k in i:
#			if
#for s in dirinput:
#	dice.throw(s)
#	dice2.throw(s)
#	if dicresult1.count([[dice.t, dice.s], dice.e]) == 0:
#		dicresult1.append([[dice.t, dice.s], dice.e])
#	if dicresult2.count([[dice2.t, dice2.s], dice2.e]) == 0:
#		dicresult2.append([[dice2.t, dice2.s], dice2.e])

#print(dicresult1)
#print(dicresult2)

#for i in dicresult1:
#	if dicresult2.count(i) != 1:
#		print('No')
#		exit(0)

#print('Yes')

Submission status: Accepted

Solution code:
class Dice:
  __table =[[0,1,2,3,4,5],[0,2,4,1,3,5],[0,4,3,2,1,5],[0,3,1,4,2,5],
            [1,5,2,3,0,4],[1,2,0,5,3,4],[1,0,3,2,5,4],[1,3,5,0,2,4],
            [2,5,4,1,0,3],[2,4,0,5,1,3],[2,0,1,4,5,3],[2,1,5,0,4,3],
            [3,5,1,4,0,2],[3,1,0,5,4,2],[3,0,4,1,5,2],[3,4,5,0,1,2],
            [4,2,5,0,3,1],[4,5,3,2,0,1],[4,3,0,5,2,1],[4,0,2,3,5,1],
            [5,1,3,2,4,0],[5,3,4,1,2,0],[5,4,2,3,1,0],[5,2,1,4,3,0]]
  __another = []
  def __init__(self,dice):
    self.dice = dice
    for t in self.__table:
      a = []
      for v in t:
        a.append(dice[v])      
      self.__another.append(a)
      
  def output(self):
    print(self.dice[0])
    
  def right_dise(self,a,b):
    for t in self.__another:
      if t[0] == a and t[1] == b:
        return t[2]

  def comparison(self,dice):
    result = 0
    for table_temp in self.__another:
      table_temp = ''.join(map(str,table_temp))
      dice = ''.join(map(str,dice))
      if table_temp == dice:
        print('Yes')
        result = 1
        break
    if result == 0:
      print('No')
  
  def comparison2(self,dice):
    for table_temp in self.__another:
      table_temp = ''.join(map(str,table_temp))
      dice = ''.join(map(str,dice))
      if table_temp == dice:
        return 1
    return 0

  def move(self,str):
    if str == 'N':
      temp = self.dice[0]
      self.dice[0] = self.dice[1]
      self.dice[1] = self.dice[5]
      self.dice[5] = self.dice[4]
      self.dice[4] = temp
    elif str == 'S':
      temp = self.dice[0]
      self.dice[0] = self.dice[4]
      self.dice[4] = self.dice[5]
      self.dice[5] = self.dice[1]
      self.dice[1] = temp
    elif str == 'E':
      temp = self.dice[0]
      self.dice[0] = self.dice[3]
      self.dice[3] = self.dice[5]
      self.dice[5] = self.dice[2]
      self.dice[2] = temp
    elif str == 'W':
      temp = self.dice[0]
      self.dice[0] = self.dice[2]
      self.dice[2] = self.dice[5]
      self.dice[5] = self.dice[3]
      self.dice[3] = temp      
  
num = int(input())
di1 = list(map(int,input().split()))
di = Dice(di1)
result = 0
for _ in range(num-1):
  di2 = list(map(int,input().split()))
  result += di.comparison2(di2)
  
if result > 0:
  print('No')
else:
  print('Yes')

Submission status: Accepted

Solution code:
import math
import itertools
import sys

class Dice:
  def __init__(self, int_array):
    self.numbers = int_array
    self.faces = {}
    self.faces['top'] = self.numbers[0]
    self.faces['back'] = self.numbers[1]
    self.faces['right'] = self.numbers[2]
    self.faces['left'] = self.numbers[3]
    self.faces['front'] = self.numbers[4]
    self.faces['bottom'] = self.numbers[5]

  def getNum(self, n):
    return self.numbers[n-1]

  def getFace(self, f):
    return self.faces[f]

  def getRightFace(self, t, b):
    top = self.faces['top']
    back = self.faces['back']
    right = self.faces['right']
    left = self.faces['left']
    front = self.faces['front']
    bottom = self.faces['bottom']

    if t == self.getNum(2):
      self.rotate('N')

    elif t == self.getNum(4):
      self.rotate('E')

    elif t == self.getNum(5):
      self.rotate('S')

    elif t == self.getNum(3):
      self.rotate('W')

    elif t == self.getNum(6):
      for _ in range(2):
        self.rotate('N')

    while self.getFace('back') != b:
      self.rotate('R')

    result = self.getFace('right')
      
    self.faces['top'] = top
    self.faces['back'] = back
    self.faces['right'] = right
    self.faces['left'] = left
    self.faces['front'] = front
    self.faces['bottom'] = bottom

    return result

  def rotate(self, direction):
    if direction == 'N': # 前回り
      top = self.getFace('top') #一時保存

      self.faces['top'] = self.faces['back']
      self.faces['back'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['front']
      self.faces['front'] = top
      
    elif direction == 'E': # 右回り
      top = self.faces['top'] #一時保存

      self.faces['top'] = self.faces['left']
      self.faces['left'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['right']
      self.faces['right'] = top
      
    elif direction == 'S': # 後ろ回り
      top = self.faces['top'] #一時保存

      self.faces['top'] = self.faces['front']
      self.faces['front'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['back']
      self.faces['back'] = top
      
    elif direction == 'W': # 左回り
      top = self.faces['top'] #一時保存

      self.faces['top'] = self.faces['right']
      self.faces['right'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['left']
      self.faces['left'] = top
      
    elif direction == 'R': # その場右回り
      back = self.faces['back'] #一時保存

      self.faces['back'] = self.faces['left']
      self.faces['left'] = self.faces['front']
      self.faces['front'] = self.faces['right']
      self.faces['right'] = back
      
    elif direction == 'L': # その場左回り
      back = self.faces['back'] #一時保存

      self.faces['back'] = self.faces['right']
      self.faces['right'] = self.faces['front']
      self.faces['front'] = self.faces['left']
      self.faces['left'] = back

def isSameDice(dice_1, dice_2):
  faces = ['top', 'back', 'right', 'left', 'front', 'bottom']

  for _ in range(4):
    for _ in range(4):
      flag = True

      for face in faces:
        if dice_1.getFace(face) != dice_2.getFace(face):
          flag = False
          break

      if flag:
        return True
      dice_1.rotate('R')

    dice_1.rotate('N')

  dice_1.rotate('E')
  for _ in range(4):
    flag = True

    for face in faces:
      if dice_1.getFace(face) != dice_2.getFace(face):
        flag = False
        break

    if flag:
      return True
    dice_1.rotate('R')

  for _ in range(2):
    dice_1.rotate('W')
  for _ in range(4):
    flag = True

    for face in faces:
      if dice_1.getFace(face) != dice_2.getFace(face):
        flag = False
        break

    if flag:
      return True
    dice_1.rotate('R')

  return False
      
def main():
  n = int(input())
  dices = [list(map(int, input().split())) for _ in range(n)]

  existSame = False

  for c in itertools.combinations(dices, 2):
    if isSameDice(Dice(c[0]), Dice(c[1])):
      existSame = True
      break

  if existSame:
    print('No')
  else:
    print('Yes')

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
def f():
 for c in range(n):
  for d in a[c+1:]:
   for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
    if[d[p[0]],d[p[5]]]==a[c][::5]:
     b=[d[i]for i in p[1:5]]*2
     for k in range(4):
      if b[k:k+4]==a[c][1:5]:return"No"
 return"Yes"
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:b[3:5]=b[4],b[3]
print(f())

Submission status: Accepted

Solution code:
D = [
    (1, 5, 2, 3, 0, 4), # 'U'
    (3, 1, 0, 5, 4, 2), # 'R'
    (4, 0, 2, 3, 5, 1), # 'D'
    (2, 1, 5, 0, 4, 3), # 'L'
]

N = int(input())
L = [None]*N
for i in range(N):
    *L[i], = map(int, input().split())

p = (0, 0, 0, 1, 1, 2, 2, 3)
ok = 1
for i in range(N):
    Li = L[i]
    for j in range(i+1, N):
        Lj = L[j]
        for k in range(24):
            if Li == Lj:
                ok = 0
            Lj[:] = (Lj[e] for e in D[p[k%8]])
print("Yes" if ok else "No")

Submission status: Accepted

Solution code:
def roll_e(d):
    w = []
    w = d
    d[0], d[1], d[2], d[3], d[4], d[5] = w[3], w[1], w[0], w[5], w[4], w[2]
    return d

def roll_s(d):
    w = []
    w = d
    d[0], d[1], d[2], d[3], d[4], d[5] = w[4], w[0], w[2], w[3], w[5], w[1]
    return d

def dice_judge(d1, d2):
    no_flag = 0

    i = 0
    while d1[1] != d2[1]:
        if i == 7:
            no_flag = 1
            break
        elif i == 4:
            d2 = roll_e(d2)
        d2 = roll_s(d2)
        i += 1

    i = 0
    while d1[0] != d2[0] and no_flag == 0:
        if i == 4:
            break
        d2 = roll_e(d2)
        i += 1

    if d1 == d2:
        return True
    else:
        return False

n = int(input())
d = []
no_flag = 0

i = 0
while n > i:
    d.append(input().split())
    i += 1
i, j = 0, 0
while n-1 > i:
    j = i + 1
    while n > j:
        if dice_judge(d[i], d[j]):
            no_flag = 1
        j += 1
    i += 1

if no_flag == 0:
    print("Yes")
elif no_flag == 1:
    print("No")

Submission status: Accepted

Solution code:
class Dice:
    
    keys = [ 
        "top", 
        "front", 
        "right", 
        "left", 
        "back", 
        "bottom"
        ]
    keys_for_top = [
            ["front", "right", "back", "left", "bottom"],
            ["bottom", "right", "top", "left", "back"],
            ["bottom", "back", "top", "front", "left"],
            ["bottom", "front", "top", "back", "right"],
            ["bottom", "left", "top", "right", "front"],
            ["front", "left", "back", "right", "top"]
        ]

    def __init__(self, eye1, eye2, eye3, eye4, eye5, eye6):
        self.__eyes = {
            "top": eye1,
            "front": eye2,
            "right": eye3,
            "left": eye4,
            "back": eye5,
            "bottom": eye6
        }

    def set_eyes(self, eye1, eye2, eye3, eye4, eye5, eye6):
        self.__eyes["top"] = eye1
        self.__eyes["front"] = eye2
        self.__eyes["right"] = eye3
        self.__eyes["left"] = eye4
        self.__eyes["back"] = eye5
        self.__eyes["bottom"] = eye6
    
    def get_eyes(self, key):
        return self.__eyes[key]

    def N(self):
        self.set_eyes(
            self.get_eyes("front"),
            self.get_eyes("bottom"),
            self.get_eyes("right"),
            self.get_eyes("left"),
            self.get_eyes("top"),
            self.get_eyes("back")
            )
    def S(self):
        self.set_eyes(
            self.get_eyes("back"),
            self.get_eyes("top"),
            self.get_eyes("right"),
            self.get_eyes("left"),
            self.get_eyes("bottom"),
            self.get_eyes("front")
            )
        
    def E(self):
        self.set_eyes(
            self.get_eyes("left"),
            self.get_eyes("front"),
            self.get_eyes("top"),
            self.get_eyes("bottom"),
            self.get_eyes("back"),
            self.get_eyes("right")
            )
        
    def W(self):
        self.set_eyes(
            self.get_eyes("right"),
            self.get_eyes("front"),
            self.get_eyes("bottom"),
            self.get_eyes("top"),
            self.get_eyes("back"),
            self.get_eyes("left")
            )
    
    def print_top(self):
        print(self.get_eyes("top"))

    def guess_right_from_top_front(self, top, front):
        key_top = None
        key_front = None
        
        for key in Dice.keys:
            if top == self.get_eyes(key):
                key_top = key
            if front == self.get_eyes(key):
                key_front = key
        

        for i in range(6):
            if key_top == Dice.keys[i]:
                for j in range(4):
                    if key_front == Dice.keys_for_top[i][j]:
                        return Dice.keys_for_top[i][(j + 1) % 4]
        return False

    @classmethod
    def generate_all_states(cls, dice):
        dices = []
        for i in range(6):
            for j in range(4):
                dices.append(cls(
                    dice.get_eyes(Dice.keys[i]),
                    dice.get_eyes(Dice.keys_for_top[i][j]),
                    dice.get_eyes(Dice.keys_for_top[i][(j + 1) % 4]),
                    dice.get_eyes(Dice.keys_for_top[i][(j + 3) % 4]),
                    dice.get_eyes(Dice.keys_for_top[i][(j + 2) % 4]),
                    dice.get_eyes(Dice.keys_for_top[i][4])
                    ))
        return dices
    
    @classmethod
    def is_same_states(cls, dice1, dice2):
        for i in range(6):
            if dice1.get_eyes(Dice.keys[i]) != dice2.get_eyes(Dice.keys[i]):
                return False
        return True
    
    @classmethod
    def is_same_dices(cls, dice1, dice2):
        all_states_dice2 = Dice.generate_all_states(dice2)
        for i in range(24):
            if Dice.is_same_states(dice1, all_states_dice2[i]):
                return True
        return False   

n = int(input())
dices = []
for i in range(n):
    e1, e2, e3, e4, e5, e6 = map(int, input().split())
    dices.append(Dice(e1, e2, e3, e4, e5, e6))

for i in range(n):
    for j in range(i+1, n):
        if Dice.is_same_dices(dices[i], dices[j]):
            print("No")
            quit()
print("Yes")

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def equals(self,another):

        ret = False;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return ret



num_dice = int(input())
DICE = []

for i in range(num_dice):
    table = list(map(int,input().split()))
    tmp_dice = Dice()
    tmp_dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])
    DICE.append(tmp_dice)

FLG = True

for i in range(num_dice-1):
    for k in range(i+1,num_dice):
        if DICE[i].equals(DICE[k]) == True:
            FLG = False
            break


if FLG == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:

class Dice:
    def __init__(self,a,b,c,d,e,f):
        self.face1 = a
        self.face2 = b
        self.face3 = c
        self.face4 = d
        self.face5 = e
        self.face6 = f

    def above_face(self):
        return self.face1

    def roll(self, order):
        if order == 'N':
            tmp = self.face1
            self.face1 = self.face2
            self.face2 = self.face6
            self.face6 = self.face5
            self.face5 = tmp
        elif order == 'S':
            tmp = self.face1
            self.face1 = self.face5
            self.face5 = self.face6
            self.face6 = self.face2
            self.face2 = tmp
        elif order == 'W':
            tmp = self.face1
            self.face1 = self.face3
            self.face3 = self.face6
            self.face6 = self.face4
            self.face4 = tmp
        else:
            tmp = self.face1
            self.face1 = self.face4
            self.face4 = self.face6
            self.face6 = self.face3
            self.face3 = tmp

n = int(input())
dice_list = []
d_list = []
for i in range(n):
    a,b,c,d,e,f = map(int,input().split())
    dice_list.append(Dice(a,b,c,d,e,f))
    d_list.append(Dice(a,b,c,d,e,f))

flag = True
for k in range(n - 1):
    for j in range(k + 1,n):
        for i in 'NNNNWNNNWNNNENNNENNNWNNN':
            d_list[j].roll(i)
            if dice_list[k].face1 == d_list[j].face1 and dice_list[k].face2 == d_list[j].face2 and \
                    dice_list[k].face3 == d_list[j].face3 and dice_list[k].face4 == d_list[j].face4 and \
                    dice_list[k].face5 == d_list[j].face5 and dice_list[k].face6 == d_list[j].face6:
                flag = False
                break
        else:
            continue
        break
    else:
        continue
    break

if flag == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
ptn=[
  [1,2,3,4,5,6],
  [2,6,3,4,1,5],
  [3,6,5,2,1,4],
  [4,6,2,5,1,3],
  [5,6,4,3,1,2],
  [6,2,4,3,5,1]
]

def diffDice(orgDice, newDice):
  flg = False   # diff
  tmpDice = [0,0,0,0,0,0]
  for i in range(6):
    #newDiceをptn1で並べ替え
    for idx, j in enumerate(ptn[i]):
      tmpDice[idx] = newDice[j-1]

    if orgDice[0] != tmpDice[0] and orgDice[5] != tmpDice[5]:
      continue
    
    if ((orgDice[0] == tmpDice[0] and orgDice[5] != tmpDice[5]) or
     (orgDice[0] != tmpDice[0] and orgDice[5] == tmpDice[5])):
      continue
      
    if (
    (orgDice[1:5] == [tmpDice[1],tmpDice[2],tmpDice[3],tmpDice[4]]) or 
    (orgDice[1:5] == [tmpDice[3],tmpDice[1],tmpDice[4],tmpDice[2]]) or 
    (orgDice[1:5] == [tmpDice[2],tmpDice[4],tmpDice[1],tmpDice[3]]) or 
    (orgDice[1:5] == [tmpDice[4],tmpDice[3],tmpDice[2],tmpDice[1]])): 
      flg = True
      break
  return flg
    

n = int(input())
dice1 = list(input().split(" "))
flg=False
for i in range(1,n):
  dice2 = list(input().split(" "))
  flg = diffDice(dice1,dice2)
  if flg == True:
    break

if flg:
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
class Dice():

    def __init__(self, dice_list):
        self.state = [0 for _ in range(6)]
        self.state[0] = dice_list[0]
        self.state[1] = dice_list[1]
        self.state[2] = dice_list[2]
        self.state[3] = dice_list[3]
        self.state[4] = dice_list[4]
        self.state[5] = dice_list[5]

    def north(self):
        tmp = self.state[0]
        self.state[0] = self.state[1]
        self.state[1] = self.state[5]
        self.state[5] = self.state[4]
        self.state[4] = tmp

    def west(self):
        tmp = self.state[0]
        self.state[0] = self.state[2]
        self.state[2] = self.state[5]
        self.state[5] = self.state[3]
        self.state[3] = tmp

    def south(self):
        tmp = self.state[0]
        self.state[0] = self.state[4]
        self.state[4] = self.state[5]
        self.state[5] = self.state[1]
        self.state[1] = tmp


    def east(self):
        tmp = self.state[0]
        self.state[0] = self.state[3]
        self.state[3] = self.state[5]
        self.state[5] = self.state[2]
        self.state[2] = tmp

    
if __name__ == '__main__':
    def is_same(dice_num1, dice_num2):
        dice1 = Dice(dice_num1)

        flag = False
        dice2 = Dice(dice_num2)
        for i in range(4):
            for j in range(4):
                if dice1.state[1] == dice2.state[1]:
                    flag = True
                    break
                dice2.east()

            if dice1.state[1] == dice2.state[1]:
                flag = True
                break

            dice2.north()

        if flag == False:
            dice2 = Dice(dice_num2)
            dice2.west()
            dice2.south()
            for i in range(4):
                if dice1.state[1] == dice2.state[1]:
                    flag = True
                    break
                dice2.west()

        if flag == False:
            dice2 = Dice(dice_num2)
            dice2.east()
            dice2.south()
            for i in range(4):
                if dice1.state[1] == dice2.state[1]:
                    break
                dice2.west()

        ans = 'No'
        for i in range(4):
            if dice1.state == dice2.state:
                ans = 'Yes'
                break
            dice2.west()

        if ans == 'Yes':
            return True
        else:
            return False

    N = int(input())
    L = [list(map(int, input().split())) for _ in range(N)]

    answer = 'Yes'
    for i in range(N):
        for j in range(N):
            if i != j:
                if is_same(L[i], L[j]):
                    answer = 'No'
        
        
    print(answer)