Problem:


Score : 500 points

Problem Statement

In CODE FESTIVAL XXXX, there are N+1 participants from all over the world, including Takahashi.

Takahashi checked and found that the time gap (defined below) between the local times in his city and the i-th person's city was D_i hours.
The time gap between two cities is defined as follows. For two cities A and B, if the local time in city B is d o'clock at the moment when the local time in city A is 0 o'clock, then the time gap between these two cities is defined to be min(d,24-d) hours.
Here, we are using 24-hour notation.
That is, the local time in the i-th person's city is either d o'clock or 24-d o'clock at the moment when the local time in Takahashi's city is 0 o'clock, for example.

Then, for each pair of two people chosen from the N+1 people, he wrote out the time gap between their cities. Let the smallest time gap among them be s hours.

Find the maximum possible value of s.

Constraints

1 \leq N \leq 50

0 \leq D_i \leq 12

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the maximum possible value of s.

Sample Input 1

3
7 12 8

Sample Output 1

4

For example, consider the situation where it is 7, 12 and 16 o'clock in each person's city at the moment when it is 0 o'clock in Takahashi's city. In this case, the time gap between the second and third persons' cities is 4 hours.

Sample Input 2

2
11 11

Sample Output 2

2

Sample Input 3

1
0

Sample Output 3

0

Note that Takahashi himself is also a participant.



Sample input:
3
7 12 8


Sample output:
4

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
d = list(map(int, input().split()))
from itertools import product
if n>=24:
    ans = 0
elif n>=13:
    from collections import Counter
    d.append(0)
    c = Counter(d)
    if c[0]<=1 and c[12]<=1 and all(c[v]<=2 for v in range(1,12)):
        ans = 1
    else:
        ans = 0
else:
    ans = 0
    for ind in product(*[range(2) for _ in range(n)]):
        vals = []
        for i in range(n):
            if ind[i]:
                vals.append(d[i])
            else:
                vals.append((24-d[i])%24)
        vals.append(0)
        res = 50
        for i in range(len(vals)):
            for j in range(i+1,len(vals)):
                res = min(res, abs(vals[i]-vals[j]))
        ans = max(ans, res)
print(ans)

Submission status: Wrong Answer

Solution code:
# にぶたんの匂いがするが問題の意味がいまいちわからん
# まちがえた 全探索でいいし、Nは最大で2*12個でいい？

n = int(input())
dd = {}
dd[0] = 1
for x in list(map(int, input().split())):
    if x in dd and dd[x] < 2:
        dd[x] += 1
    elif x not in dd:
        dd[x] = 1
d = []
for k, v in dd.items():
    d += [k] * v
a = 0
for bit in range(1 << len(d)):
    tmp = d[:]
    for i in range(len(d)):
        if bit >> i & 1 == 1:
            tmp[i] = (24 - tmp[i])
    b = 10**10
    for i in range(len(d)):
        for j in range(i + 1, len(d)):
            b = min(b, abs(tmp[i] - tmp[j]))
    a = max(a, b)
print(a % 12)

Submission status: Wrong Answer

Solution code:
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def solve():
    n = getN()
    nums = getList()
    nums.sort()
    if n == 1:
        print(0)
        return

    ji = [12]
    for i, num in enumerate(nums):
        if i % 2 == 0:
            ji.append(12-num)
        else:
            ji.append(12 + num)

    ans = INF
    ji.sort()
    for i, j in zip(ji, ji[1:]):
        ans = min(ans, j - i)

    ans = min(ans, (- ji[-1] + ji[0] + 24) % 24)
    # print(ji)
    print(ans)





def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Wrong Answer

Solution code:
from copy import*
n=int(input())
d=[0]+list(map(int,input().split()))
c=dict(zip(list(range(13)),[0]*13))
for i in d:
  c[i]+=1
ans=0
for i in range(1,12):
  if c[i]==2:
    k=d.index(i)
    d[k]=24-d[k]
for i in range(1<<12):
  a=copy(d)
  cnt=24
  for j in range(1,12):
    if (i>>j)&1 and c[j]==1:
      k=d.index(j)
      a[k]=24-a[k]
  for j in range(n+1):
    for k in range(j+1,n+1):
      cnt=min(cnt,abs(a[j]-a[k]))
  ans=max(cnt%24,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from copy import*
n=int(input())
d=[0]+list(map(int,input().split()))
c=dict(zip(list(range(13)),[0]*13))
for i in d:
  c[i]+=1
ans=0
for i in range(12):
  if c[i]==2:
    k=d.index(i)
    d[k]=24-d[k]
for i in range(1<<12):
  a=copy(d)
  cnt=24
  for j in range(1,12):
    if (i>>j)&1 and c[j]==1:
      k=d.index(j)
      a[k]=24-a[k]
  for j in range(n+1):
    for k in range(j+1,n+1):
      cnt=min(cnt,abs(a[j]-a[k]))
  ans=max(cnt%24,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=[0]+sorted(list(map(int,input().split())))
ans=24
for i in range(n+1):
  if i%2:d[i]=24-d[i]
for i in range(n+1):
  for j in range(i+1,n+1):
    ans=min(abs(d[i]-d[j]),ans)
print(ans%24)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    #全部異なるならbit全探索できそう
    #2つ以上同じものがあるとk以上同じものがある時　向きが逆だとして最小値候補に入れておく
    n=I()
    lis=LI()
    if 0 in lis:
        print(0)
        sys.exit()
    c=Counter(lis)
    ans=inf
    for x in c.keys():
        #print(x)
        if c[x]>=3:
            print(0)
            sys.exit()
        elif c[x]>=2:
            ans=min(ans,x,24-2*x)
    lis.append(0)
    lis=list(set(lis))
    u=len(lis)
    #print(lis)
    #ansは上限
    answers=[]
    #print(ans)
    for x in product([0,1],repeat=u):
        time=[]
        for i in range(u):
            if x[i]==1:
                time.append(24-lis[i])
            else:
                time.append(lis[i])
        #print(time)
        z=ans

        for i in range(u-1):
            for j in range(i+1,u):
                z=min(z,24-abs(time[i]-time[j]),abs(time[i]-time[j]))   
        #print(z)
        answers.append(z)
        
    print(max(answers))
        
        
        
                
        
        
                
        
            
            
    
            
            
    


                
    
    
    
            
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    #全部異なるならbit全探索できそう
    #2つ以上同じものがあるとk以上同じものがある時　向きが逆だとして最小値候補に入れておく
    n=I()
    lis=LI()
    if 0 in lis:
        print(0)
        sys.exit()
    c=Counter(lis)
    ans=inf
    for x in c.keys():
        #print(x)
        if c[x]>=2:
            ans=min(ans,x,24-2*x)
    lis.append(0)
    lis=list(set(lis))
    u=len(lis)
    #print(lis)
    #ansは上限
    answers=[]
    #print(ans)
    for x in product([0,1],repeat=u):
        time=[]
        for i in range(u):
            if x[i]==1:
                time.append(24-lis[i])
            else:
                time.append(lis[i])
        #print(time)
        z=ans

        for i in range(u-1):
            for j in range(i+1,u):
                z=min(z,min(24-abs(time[i]-time[j]),abs(time[i]-time[j])))
        #print(z)
        answers.append(z)
        
    print(max(answers))
        
        
        
                
        
        
                
        
            
            
    
            
            
    


                
    
    
    
            
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import product

n = int(input())
d = Counter(list(map(int, input().split())) + [0])

ans, cnt = [], []
for num in d:
    if d[num] > (2 - (num in {0, 12})):
        print(0)
        exit()
    elif ((num in {0, 12}) and d[num] == 1) or d[num] == 2:
        ans += list(set([num, (24 - num) % 24]))
        ans.append(num)
    elif d[num] == 1:
        cnt.append(num)

s = 0
if len(cnt) == 0:
    s = min(ans[i] - ans[i - 1] for i in range(1, len(ans)))
for bit in product([1, -1], repeat=len(cnt)):
    tmp = ans[:]
    tmp += [(ci - 12) * bi + 12 for bi, ci in zip(bit, cnt)]
    tmp = sorted(tmp + [i + 24 for i in tmp])
    stmp = min(tmp[i] - tmp[i - 1] for i in range(1, len(tmp)))
    s = max(s, stmp)
print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = sorted(list(map(int, input().split())) + [0])

ans, cnt = [], 1
for num in d:
    ans.append(((num - 12) * cnt + 12) % 24)
    cnt *= -1

ans += [i + 24 for i in ans]
s = min(ans[i] - ans[i - 1] for i in range(1, len(ans)))
print(s)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
d = Counter(list(map(int, input().split())) + [0])

if any(d[num] > (2 - (num in {0, 12})) for num in d):
    print(0)
    exit()

bit, cnt = [0] * 24, 1
for num in d:
    if (num in {0, 12}) and d[num] == 1:
        bit[num] = 1 
    elif d[num] == 2:
        bit[num], bit[24 - num] = 1, 1
    elif d[num] == 1:
        bit[(num - 12) * cnt + 12] = 1
        cnt *= -1
ans = [i for i, li in enumerate(bit * 2) if li == 1]
s = min(ans[i] - ans[i - 1] for i in range(1, len(ans)))
print(s)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
d = Counter(list(map(int, input().split())) + [0])

if any(d[num] > (2 - (num in {0, 12})) for num in d):
    print(0)
    exit()

bit, cnt = [0] * 24, 1
for num in d:
    if (num in {0, 12}) and d[num] == 1:
        bit[num] = 1 
    elif d[num] == 2:
        bit[num], bit[24 - num] = 1, 1
    elif d[num] == 1:
        bit[(num - 12) * cnt + 12] = 1
        cnt *= -1
ans = [i for i, li in enumerate(bit * 2) if li == 1]
s = min(ans[i] - ans[i - 1] for i in range(1, len(ans)))

Submission status: Wrong Answer

Solution code:
from itertools import product
import random

def solve(n,dl):
    # n = int(input())
    # dl = list(map(int, input().split()))

    if 0 in dl:
        return 0

    doubles = []
    dl1 = []
    dl2 = []
    for i in range(1,13):
        i_cnt = dl.count(i)
        if i_cnt > 2:
            return 0
        elif i_cnt == 2:
            dl2.append(24-i)
            dl2.append(i)
        elif i_cnt == 1:
            dl1.append(i)        

    ans = 0
    ite = list(product(range(2),repeat=len(dl1)))
    for pattern in ite:
        dl24 = [0]
        for i, v in enumerate(pattern):
            if v == 1:
                dl24.append(24-dl1[i])
            else:
                dl24.append(dl1[i])
        dl24 = dl24 + dl2
        dl24.sort()
        diff_min = 24
        # print(dl24)
        if len(dl24) == 1:
            ans = max(ans, min(dl24[0], 24-dl24[0]))
        else:
            for a,b in zip(dl24[:-1],dl24[1:]):
                diff = b-a
                diff_min = min(diff_min,diff)
            ans = max(diff_min,ans)
    return ans


def solve2(n,dl):
    ite = list(product(range(2),repeat=len(dl)))
    ans = 0
    for pattern in ite:
        dl_new = [0]
        for i, v in enumerate(pattern):
            if v == 1:
                dl_new.append(24-dl[i])
            else:
                dl_new.append(dl[i])
        dl_new.sort()
        diff_min = 24
        for a,b in zip(dl_new[:-1], dl_new[1:]):
            diff = b-a
            diff_min = min(diff_min, diff)
        ans = max(ans,diff_min)
    return ans


if __name__ == "__main__":
    n = int(input())
    dl = list(map(int, input().split()))
    ans = solve(n,dl)
    print(ans)
    # for _ in range(10):
    #     n = random.randint(1,10)
    #     dl = [random.randint(1,12) for _ in range(n)]
    #     ans1 = solve(n, dl[:])
        # ans2 = solve2(n,dl[:])
        # if ans1 != ans2:
        #     print(n)
        #     print(dl)
        #     print(ans1)
        #     print(ans2)
        #     print('----')

Submission status: Wrong Answer

Solution code:
from itertools import product

n = int(input())
dl = list(map(int, input().split()))

if 0 in dl:
    print(0)
    exit()


doubles = []
dl1 = []
dl2 = []
for i in range(1,13):
    i_cnt = dl.count(i)
    if i_cnt > 2:
        print(0)
        exit()
    elif i_cnt == 2:
        dl2.append(24-i)
        dl2.append(i)
    elif i_cnt == 1:
        dl1.append(i)        


ans = 0
ite = list(product(range(2),repeat=len(dl1)))
for pattern in ite:
    dl24 = []
    for i, v in enumerate(pattern):
        if v == 1:
            dl24.append(24-dl1[i])
        else:
            dl24.append(dl1[i])
    dl24 = dl24 + dl2
    dl24.sort()
    diff_min = 24
    # print(dl24)
    if len(dl24) == 1:
        ans = max(ans, min(dl24[0], 24-dl24[0]))
    else:
        for a,b in zip(dl24[:-1],dl24[1:]):
            diff = b-a
            diff_min = min(diff_min,diff)
        ans = max(diff_min,ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
dl = list(map(int, input().split()))

if 0 in dl:
    print(0)
    exit()

dl.sort()
dl1 = [0]
dl2 = [0]
for i, d in enumerate(dl):
    if i%2 == 0:
        dl1.append(d)
        dl2.append(24-d)
    else:
        dl1.append(24-d)
        dl2.append(d)

dl1.sort()
dl2.sort()

min_1 = 24
for a,b in zip(dl1[1:],dl1[:-1]):
    diff = a-b
    min_1 = min(min_1,diff)

min_2 = 24
for a,b in zip(dl2[1:],dl2[:-1]):
    diff = a-b
    min_2 = min(min_2,diff)

ans = max(min_1,min_2)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from numba import njit


@njit
def solve():
    ans = 0
    for i in range(1 << N):
        clocks = np.zeros((N + 2), dtype=np.int8)
        clocks[-1] = 24
        for j in range(N):
            if i >> j & 1:
                clocks[j + 1] = D[j]
            else:
                clocks[j + 1] = 24 - D[j]
        ans = max(ans, np.min(np.diff(clocks)))
    return ans


N = int(input())
D = np.array(input().split(), dtype=np.int8)
if N >= 24:
    print(0)
    exit()
else:
    print(solve())

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools,copy
input = sys.stdin.readline

N=int(input())
D=list(map(int,input().split()))
time_list = [0]*13
time_list[0] = 1 #-高橋君-#
#-時差の精査 0,12時間差が2つ,それ以外は3つあれば0-#
for d in D:
    time_list[d] += 1
    if time_list[d]>=3:
        print(0)
        exit()

#- 時差が2種類あるものから先に置いていく -#
time24list=[]
singlelist=[]
for jisa,cnt in enumerate(time_list):
    if cnt == 0:
        continue
    elif cnt==2:
        time24list.append(jisa)
        time24list.append(24-jisa)
    elif jisa ==0 or jisa == 12:
        time24list.append(jisa)
    else:
        singlelist.append(jisa)

#- singleリストを全探索 -#
lst = len(singlelist)
bit = 2**lst
ans = 0
for bi in range(bit):
    tmp = copy.deepcopy(time24list)
    min_jisa = 12 
    for j in range(lst):
        if bi>>j & 1:
            tmp.append(singlelist[j])
        else:
            tmp.append(singlelist[j]+12)
    tmp.sort()
    tmp.append(24)
    for i in range(len(tmp)-1):
        dtime = tmp[i+1]-tmp[i]
        min_jisa = min(dtime,min_jisa)
    ans = max(ans,min_jisa)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
D=list(map(int,input().split()))
time_list = [0]*13
time_list[0] = 1 #-高橋君-#
#-時差の精査 0,12時間差が2つ,それ以外は3つあれば0-#
for d in D:
    time_list[d] += 1
    if time_list[d]>=3:
        print(0)
        exit()
    elif time_list[12]>=2:
        print(0)
        exit()
    elif time_list[0]>=2:
        print(0)
        exit()
#- 時差が2種類あるものから先に置いていく -#
time24list=[]
singlelist=[]
for jisa,cnt in enumerate(time_list):
    if cnt == 0:
        continue
    elif cnt==2:
        time24list.append(jisa)
        time24list.append(24-jisa)
    elif jisa ==0 or jisa == 12:
        time24list.append(jisa)
    else:
        singlelist.append(jisa)

#- singleリストを全探索 -#
lst = len(singlelist)
bit = 2**lst
ans = 0
for bi in range(bit):
    tmp = time24list[::]
    min_jisa = 12 
    for j in range(lst):
        if bi>>j & 1:
            tmp.append(singlelist[j])
        else:
            tmp.append(singlelist[j]+12)
    tmp.sort()
    tmp.append(24)
    for i in range(len(tmp)-1):
        dtime = tmp[i+1]-tmp[i]
        min_jisa = min(dtime,min_jisa)
    ans = max(ans,min_jisa)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations, product
def calc(a):
    ret = 10 ** 20
    for comb in combinations(a, 2):
        ret = min(ret, abs(comb[0] - comb[1]))
    return ret

def main():
    N = int(input())
    D = list(map(int, input().split()))
    if D.count(0):
        return 0
    cnt = [[] for _ in range(13)]
    for i in D:
        cnt[i].append(i)
    d = []
    d2 = [0]
    single_cnt = 0
    for i, c in enumerate(cnt):
        if i == 12:
            if len(c) == 1:
                d2.append(12)
            elif len(c) == 2:
                return 0
        elif len(c) == 1:
            d.append((i, 24-i))
            single_cnt += 1
        elif len(c) == 2:
            d2.append(i)
            d2.append(24-i)
        elif len(c) == 3:
            return 0
    ans = 0
    for prod in product(range(2), repeat=single_cnt):
        tmp = []
        for i, p in enumerate(prod):
            tmp.append(d[i][p])
        ans = max(ans, calc(tmp + d2))
    return ans
            
print(main())

Submission status: Wrong Answer

Solution code:
from itertools import combinations, product
def calc(a):
    ret = 10 ** 20
    for comb in combinations(a, 2):
        ret = min(ret, abs(comb[0] - comb[1]))
    return ret

def main():
    N = int(input())
    D = list(map(int, input().split()))
    if D.count(0):
        return 0
    cnt = [[] for _ in range(13)]
    cnt[0].append(0)
    for i in D:
        cnt[i].append(i)
    if any([len(i) >= 3 for i in cnt]):
        return 0
    cnt[0].pop()
    d = []
    d2 = [0]
    for i, c in enumerate(cnt):
        if len(c) == 1:
            d.append((i, 24-i))
        elif len(c) == 2:
            d2.append(i)
            d2.append(24-i)
    ans = 0
    single_cnt = sum([len(i) % 2 for i in cnt])
    for prod in product(range(2), repeat=single_cnt):
        tmp = []
        for i, p in enumerate(prod):
            tmp.append(d[i][p])
        ans = max(ans, calc(tmp + d2))
    return ans
            
print(main())

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))

if N >= 23:
    print(0)

else:
    res = 0
    for bit in range(2**N):
        d = [0 for _ in range(24)]
        d[0] = 1
        for i in range(N):
            if (bit >> i) & 1:
                d[D[i]] += 1
            else:
                d[(24 - D[i]) % 24] += 1
        md = 25
        tmp = 0
        if d[0] > 1:
            md = 0
        else:
            for i in range(1, 24):
                if d[i] > 1:
                    md = 0
                    break
                elif d[i] == 1:
                    md = min(md, i - tmp)
                    tmp = i
            md = min((24 - tmp) % 24, md)
        res = max(res, md)
    print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))

if N >= 23:
    print(0)

else:
    res = 0
    for bit in range(2**N):
        d = [0 for _ in range(24)]
        d[0] = 1
        for i in range(N):
            if (bit >> i) & 1:
                d[D[i]] += 1
            else:
                d[(24 - D[i]) % 24] += 1
        md = 25
        tmp = 0
        if d[0] > 1:
            md = 0
        else:
            for i in range(1, 24):
                if d[i] > 1:
                    md = 0
                    break
                elif d[i] == 1:
                    md = min(md, i - tmp)
                    tmp = i
        md = min(24 - tmp, md)
        res = max(res, md)
    print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))

if N >= 23:
    print(0)

else:
    res = 0
    for bit in range(2**N):
        d = [0 for _ in range(24)]
        d[0] = 1
        for i in range(N):
            if (bit >> i) & 1:
                d[D[i]] += 1
            else:
                d[(24 - D[i]) % 24] += 1
        md = 25
        tmp = 0
        for i in range(24):
            if d[i] > 1:
                md = 0
                break
            elif d[i] == 1:
                md = min(md, i - tmp)
                tmp = i
        md = min(24 - tmp, md)
        res = max(res, md)
    print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    N = int(input())
    D = list(map(int, input().split()))
    d = Counter(D)
    # 前処理
    for i in range(13):
        if (i == 0 or i == 12) and d[i] == 2:
            print(0)
            exit()
        elif d[i] >= 3:
            print(0)
            exit()
    ans = 0
    for i in range(2**11):
        time = [0, 24]
        if d[12] == 1:
            time.append(12)
        for j in range(1,12):
            if d[j] == 1:
                if i >> j & 1:
                    time.append(24-j)
                else:
                    time.append(j)
            elif d[j] == 2:
                time.append(24-j)
                time.append(j)
        time.sort()
        ret = 25
        for i in range(1,len(time)):
            ret = min(ret, time[i]-time[i-1])
        ans = max(ans, ret)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

N = int(sys.stdin.readline())
D = list(map(int, sys.stdin.readline().split()))

ans = 0
for i in range(2**N):
    # bitがたっているところは24 - Dの時差にする
    tmp_time = D[:]
    for j in range(N):
        if (i >> j) & 1:
            tmp_time[j] = 24 - D[j]

    diff = float("inf")
    for j in range(N):
        for k in range(N):
            if j == k:
                continue
            diff = min(diff, abs(tmp_time[j] - tmp_time[k]))
    ans = max(ans, diff)

print(ans if ans != float("inf") else 0)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N = getN()
D = getList()
D = Counter(D)

l_1 = []
l_2 = []
for i in D.items():
    if i[0] == 0:
        print(0)
        exit()
    if i[1] >= 3:
        print(0)
        exit()
    if i[1] == 2:
        l_2.append(i[0])
        l_2.append(24 - i[0])
    elif i[1] == 1:
        l_1.append(i[0])

def judge(array):
    res = abs(array[-1] - array[0])
    for i in range(len(array) - 1):
        res = min(res, array[i + 1] - array[i])
    return res

ans = 0
# Dの要素の個数が１個の時のみ分岐する（最大2 ** 12)
N_1 = len(l_1)
for bit in range(1 << N_1):
    opt = copy.deepcopy(l_2)
    opt.append(0)
    for i in range(N_1):
        if bit & (1 << i):
            opt.append(l_1[i])
        else:
            opt.append(24 - l_1[i])
    opt.sort()
    ans = max(ans, judge(opt))
print(ans)