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 collections
n=int(input())
s=list(map(int,input().split()))
if 0 in s:
  print(0)
  quit()
s=collections.Counter(s)
l1=[0]
l2=[]
for x in s:
  if s[x]>1:
    l2.append(x)
    l2.append(24-x)
  else:
    l1.append(x)
x=len(l1)
an=0
for i in range(2**x):
  memo=[0]*x
  for j in range(x):
    if ((i >> j) & 1):
      memo[j]=l1[j]
    else:
      memo[j]=24-l1[j] 
  ans=12
  memo=memo+l2
  for k in range(len(memo)):
    for m in range(k+1,len(memo)):
      ans=min(ans,abs(memo[k]-memo[m]))
  an=max(ans,an)
print(an)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
d.sort()
d_a = [v if i % 2 == 0 else 24-v for i, v in enumerate(d)]
d_b = [v if i % 2 == 1 else 24-v for i, v in enumerate(d)]
d_a.append(0)
d_b.append(0)
d_a.sort()
d_b.sort()
res_a = 24
res_b = 24
for i in range(n):
    res_a = min(res_a, d_a[i+1]-d_a[i])
    res_b = min(res_b, d_b[i+1]-d_b[i])
res = max(res_a, res_b)
if res == 24:
    res = 0
print(res)

Submission status: Wrong Answer

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

from collections import defaultdict
d = defaultdict(int)

d[0] += 1
for d_ in ds:
    d[d_] += 1
    if d_ == 12 and d[d_] == 2:
        print(0)
        exit()
    elif d_ == 0 and d[d_] == 2: 
        print(0)
        exit()
    elif d[d_] == 3:
        print(0)
        exit()

def calcmin(tmp):
    n = len(tmp)
    ret = 1 << 50
    for i in range(n):
        for j in range(i+1,n):
            ret = min(ret, abs(tmp[i]-tmp[j]))
    return ret

two = []
x = []
for k in d.keys():
    if d[k] == 2 or k == 12:
        two.append(k)
        two.append(24-k)
    elif d[k] == 1:
        x.append(k)

two = list(set(two))
n = len(x)

ans = 0
for i in range(1 << n):
    tmp = x[:]
    for j in range(n):
        if i & (1 << j):
            tmp[j] = 24-x[j]
    tmp.extend(two)
    ans = max(calcmin(tmp), ans)
print(ans)

Submission status: Wrong Answer

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

from collections import defaultdict
d = defaultdict(int)


for d_ in ds:
    d[d_] += 1
    if d_ == 12 and d[d_] == 2:
        print(0)
        exit()
    elif d_ == 0 and d[d_] == 2: 
        print(0)
        exit()
    elif d[d_] == 3:
        print(0)
        exit()

def calcmin(tmp):
    n = len(tmp)
    ret = 1 << 50
    for i in range(n):
        for j in range(i+1,n):
            ret = min(ret, abs(tmp[i]-tmp[j]))
    return ret

two = []
x = []
for k in d.keys():
    if d[k] == 2 or k == 0 or k == 12:
        two.append(k)
        two.append(24-k)
    elif d[k] == 1:
        x.append(k)
two = list(set(two))
n = len(x)

ans = 0
for i in range(1 << n):
    tmp = x[:]
    for j in range(n):
        if i & (1 << j):
            tmp[j] = 24-x[j]
    tmp.extend(two)
    tmp.append(0)
    ans = max(calcmin(tmp), ans)
print(ans)

Submission status: Wrong Answer

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

from collections import defaultdict
d = defaultdict(int)


for d_ in ds:
    d[d_] += 1
    if d_ == 12 and d[d_] == 2:
        print(0)
        exit()
    elif d_ == 0 and d[d_] == 2: 
        print(0)
        exit()
    elif d[d_] == 3:
        print(0)
        exit()

def calcmin(tmp):
    n = len(tmp)
    ret = 1 << 50
    for i in range(n):
        for j in range(i+1,n):
            ret = min(ret, abs(tmp[i]-tmp[j]))
    return ret

two = []
x = []
for k in d.keys():
    if d[k] == 2 or k == 0 or k == 12:
        two.append(k)
        two.append(24-k)
    elif d[k] == 1:
        x.append(k)
two = list(set(two))
n = len(x)

ans = 0
for i in range(1 << n):
    tmp = x[:]
    for j in range(n):
        if i & (1 << j):
            tmp[j] = 24-x[j]
    tmp.extend(two)
    ans = max(calcmin(tmp), ans)
print(ans)

Submission status: Wrong Answer

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

from collections import defaultdict
d = defaultdict(int)

d[0] += 1
for d_ in ds:
    d[d_] += 1
    if d_ == 12 and d[d_] == 2:
        print(0)
        exit()
    elif d_ == 0 and d[d_] == 2: 
        print(0)
        exit()
    elif d[d_] > 2:
        print(0)
        exit()

def calcmin(tmp):
    n = len(tmp)
    ret = 1 << 50
    for i in range(n):
        for j in range(i+1,n):
            ret = min(ret, abs(tmp[i]-tmp[j]))
    return ret

two = []
x = []
for k in d.keys():
    if d[k] == 2:
        two.append(k)
        two.append(24-k)
    if d[k] == 1:
        x.append(k)
two = list(set(two))
n = len(x)

ans = 0
for i in range(1 << n):
    tmp = x[:]
    for j in range(n):
        if i & (1 << j):
            tmp[j] = 24-x[j]
    tmp.extend(two)
    ans = max(calcmin(tmp),ans)

print(ans%24)

Submission status: Wrong Answer

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

from collections import defaultdict
d = defaultdict(int)

d[0] += 1
for d_ in ds:
    d[d_] += 1
    if d_ == 12 and d[d_] == 2:
        print(0)
        exit()
    elif d_ == 12 and d[d_] == 2: 
        print(0)
        exit()
    elif d[d_] > 2:
        print(0)
        exit()

def calcmin(tmp):
    n = len(tmp)
    ret = 1 << 50
    for i in range(n):
        for j in range(i+1,n):
            ret = min(ret, abs(tmp[i]-tmp[j]))
    return ret

two = []
x = []
for k in d.keys():
    if d[k] == 2:
        two.append(k)
        two.append(24-k)
    if d[k] == 1:
        x.append(k)
two = list(set(two))
n = len(x)

ans = 0
for i in range(1 << n):
    tmp = x[:]
    for j in range(n):
        if i & (1 << j):
            tmp[j] = 24-x[j]
    tmp.extend(two)
    ans = max(calcmin(tmp),ans)

print(ans%24)

Submission status: Wrong Answer

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

from collections import defaultdict
d = defaultdict(int)

d[0] += 1
for d_ in ds:
    d[d_] += 1
    if d[d_] > 2:
        print(0)
        exit()

def calcmin(tmp):
    n = len(tmp)
    ret = 1 << 50
    for i in range(n):
        for j in range(i+1,n):
            ret = min(ret, abs(tmp[i]-tmp[j]))
    return ret

two = []
x = []
for k in d.keys():
    if d[k] == 2:
        two.append(k)
        two.append(24-k)
    if d[k] == 1:
        x.append(k)
two = list(set(two))
n = len(x)

ans = 0
for i in range(1 << n):
    tmp = x[:]
    for j in range(n):
        if i & (1 << j):
            tmp[j] = 24-x[j]
    tmp.extend(two)
    # print(tmp, calcmin(tmp))
    ans = max(calcmin(tmp),ans)
print(ans%24)

Submission status: Wrong Answer

Solution code:
import math
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

def AddV2(v,w):
    return [v[0]+w[0],v[1]+w[1]]

dir4 = [[1,0],[0,1],[-1,0],[0,-1]]


def clamp(x,y,z):
    return max(y,min(z,x))

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
#
def Zaatsu(a):
    a.sort()
    now = a[0][0]
    od = 0
    for i in range(n):
        if(now==a[i][0]):
            a[i][0]=od
        else:
            now = a[i][0]
            od+=1
            a[i][0] = od
    
    a.sort(key = lambda x : x[1])
    return a

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

def rl(x):
    return range(len(x))

# a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################


#11-

n = int(input())

aa = list(map(int, input().split()))
t = [0 for i in range(13)]
a=[]

for i in aa:
    
    if(t[i]<=1):
        t[i]+=1
        a.append(i)
    if(t[i]==2 or i==0):
        print(0)
        exit()
    
#print(a)
n = len(a)

b = [0 for i in range(25)]
ans = 0
count = 0

for i in range(2**(n-1)):
    count +=1
    for j in range(25):
        b[j]=0
    b[0]=1
    b[24]=1
    for j in range(n):
        if((i>>j) & 1):
            b[24-a[j]] += 1
        else:
            b[a[j]] += 1
    minim = 24
    prev = -24
    for j in range(0,25):
        if(b[j]==1):
            minim = min(minim, j-prev)
            prev = j
        elif(b[j]>=2):
            minim = 0
            break
    ans = max(ans,minim)
    #print(b)

print(ans)
#print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ns = list(map(int, input().split()))
ns = sorted(ns)
ans = [0] * 24
ans[0] = 1
for i in range(n):
    if i % 2 == 0:
        ans[ns[i]] += 1
    else:
        ans[(24 - ns[i]) % 24] += 1
print(ans)
for i in ans:
    if i >= 2:
        print(0)
        exit()
ans = ans[1:]
print(1+min(len(i) for i in ''.join(map(str, ans)).split('1')))

Submission status: Wrong Answer

Solution code:
n = int(input())
ns = list(map(int, input().split()))
l = [0] * 24
ans = [0] * 24
ans[0] = 1
for i in range(1, 13):
    l[i] = i
    l[-i] = i
for i in ns:
    if l[i] >= l[(24 - i)%24]:
        k = i
    else:
        k = 24 - i
    ans[k] += 1
    for j in range(0, 13):
        l[(k + j)% 24] = min(l[(k + j)% 24], j)
        l[k - j] = min(l[k - j], j)
cnt = 0
for i in ans:
    if i >= 2:
        print(0)
        exit()
ans = ans[1:]
print(1+min(len(i) for i in ''.join(map(str,ans)).split('1')))

Submission status: Wrong Answer

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

if n == 1:
    print(D[0])
    exit()

def is_ok(x):
    for i in range(n):
        if D[i] < x:
            return False
    for i in range(n-1):
        for j in range(i+1, n):
            if max(D[j]-D[i], (24-D[j])-D[i]) < x:
                return False
    else:
        return True

l = -1
r = 13
while l+1 < r:
    c = (l+r)//2
    if is_ok(c):
        l = c
    else:
        r = c
print(l)

Submission status: Wrong Answer

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

if n == 1:
    print(D[0])
    exit()

def is_ok(x):
    for i in range(n):
        if D[i] < x:
            return False
    for i in range(n-1):
        for j in range(i+1, n):
            if max(D[j]-D[i], (24-D[j])-D[i]) < x:
                return False
    else:
        return True

l = 0
r = 13
while l+1 < r:
    c = (l+r)//2
    if is_ok(c):
        l = c
    else:
        r = c
print(l)

Submission status: Wrong Answer

Solution code:
import collections
from collections import deque
N=int(input())
D=list(map(int,input().split()))
c=collections.Counter(D)
count0=0
count12=0
l=[]
if c[12]>0:
    count12=1
if c[0]>0:
    count0=1
#print(l,count0,count12)
#print(n)
allmax=0
q=deque()
l=[]
q.append([0])
q.append([24])
if (count0==1):
    q=deque()
    q.append([0,0])
    q.append([0,24])
    q.append([24,24])
for i in range(1,12):
    length=len(q)
    j=0
    if c[i]==0: continue
    if c[i]==1:
        while j<length:
            buf1=[]
            buf2=[]
            l=q.popleft()
            buf1.extend(l)
            buf1.append(i)
            buf2.extend(l)
            buf2.append(24-i)
            q.append(buf1)
            q.append(buf2)
            j=j+1
    if c[i]>1:
        while j<length:
            buf1=[]
            buf2=[]
            buf3=[]
            l=q.popleft()
            buf1.extend(l)
            buf1.extend([i,i])
            buf2.extend(l)
            buf2.extend([24-i,24-i])
            buf3.extend(l)
            buf3.extend([i,24-i])
            q.append(buf1)
            q.append(buf2)
            q.append(buf3)
            j=j+1
    #print(q)
    #input()
if count12==1:
    length=len(q)
    j=0
    while j<length:
        buf1=[]
        l=q.popleft()
        buf1.extend(l)
        l.append(12)
        q.append(l)
        j=j+1
#print(q)
for l in q:
    l.sort()
    mi=100
    n=len(l)
    for j in range(n-1):
        mi=min(mi,(l[j+1]-l[j]),24-(l[j+1]-l[j]))
    mi=min(mi,24-l[n-1],l[n-1])
    allmax=max(allmax,mi)
print(allmax)

"""
for i in range(pow(2,n)):
    buf=[0]
    bit=[0]*n
    mi=100
    if count12==1:
        buf.append(12)
    buf.append(0)
    for j in range(n):
        if (i>>j)&1:
            bit[j]=1
    #print(bit)
    for j in range(n):
        buf.append(l[j][bit[j]])
    buf.sort()
    buf.append(24)
    #print(buf)
    for j in range(len(buf)-1):
        mi=min(mi,buf[j+1]-buf[j])
    allmax=max(allmax,mi)
print(allmax)
"""

Submission status: Wrong Answer

Solution code:
import collections
from collections import deque
N=int(input())
D=list(map(int,input().split()))
c=collections.Counter(D)
count0=0
count12=0
l=[]
if c[12]>0:
    count12=1
if c[0]>0:
    count0=1
#print(l,count0,count12)
#print(n)
allmax=0
q=deque()
l=[]
q.append([0])
if (count0==1):
    q=deque()
    q.append([0,0])
for i in range(1,12):
    length=len(q)
    j=0
    if c[i]==0: continue
    if c[i]==1:
        while j<length:
            buf1=[]
            buf2=[]
            l=q.popleft()
            buf1.extend(l)
            buf1.append(i)
            buf2.extend(l)
            buf2.append(24-i)
            q.append(buf1)
            q.append(buf2)
            j=j+1
    if c[i]>1:
        while j<length:
            buf1=[]
            buf2=[]
            buf3=[]
            l=q.popleft()
            buf1.extend(l)
            buf1.extend([i,i])
            buf2.extend(l)
            buf2.extend([24-i,24-i])
            buf3.extend(l)
            buf3.extend([i,24-i])
            q.append(buf1)
            q.append(buf2)
            q.append(buf3)
            j=j+1
    #print(q)
    #input()
if count12==1:
    length=len(q)
    j=0
    while j<length:
        buf1=[]
        l=q.popleft()
        buf1.extend(l)
        l.append(12)
        q.append(l)
        j=j+1
#print(q)
for l in q:
    l.append(24)
    l.sort()
    mi=100
    n=len(l)
    for j in range(n-1):
        mi=min(mi,l[j+1]-l[j])
    allmax=max(allmax,mi)
print(allmax)

"""
for i in range(pow(2,n)):
    buf=[0]
    bit=[0]*n
    mi=100
    if count12==1:
        buf.append(12)
    buf.append(0)
    for j in range(n):
        if (i>>j)&1:
            bit[j]=1
    #print(bit)
    for j in range(n):
        buf.append(l[j][bit[j]])
    buf.sort()
    buf.append(24)
    #print(buf)
    for j in range(len(buf)-1):
        mi=min(mi,buf[j+1]-buf[j])
    allmax=max(allmax,mi)
print(allmax)
"""

Submission status: Wrong Answer

Solution code:
import collections
from collections import deque
N=int(input())
D=list(map(int,input().split()))
c=collections.Counter(D)
count0=0
count12=0
l=[]
if c[12]>0:
    count12=1
if c[0]>0:
    count0=1
#print(l,count0,count12)
#print(n)
allmax=0
q=deque()
l=[]
q.append([0])
if (count0==1):
    q=deque()
    q.append([0,0])
for i in range(1,12):
    length=len(q)
    j=0
    if c[i]==0: continue
    if c[i]==1:
        while j<length:
            buf1=[]
            buf2=[]
            l=q.popleft()
            buf1.extend(l)
            buf1.append(i)
            buf2.extend(l)
            buf2.append(24-i)
            q.append(buf1)
            q.append(buf2)
            j=j+1
    if c[i]>1:
        while j<length:
            buf1=[]
            buf2=[]
            buf3=[]
            l=q.popleft()
            buf1.extend(l)
            buf1.extend([i,i])
            buf2.extend(l)
            buf2.extend([24-i,24-i])
            buf3.extend(l)
            buf3.extend([i,24-i])
            q.append(buf1)
            q.append(buf2)
            q.append(buf3)
            j=j+1
    #print(q)
    #input()
if count12==1:
    length=len(q)
    j=0
    while j<length:
        buf1=[]
        l=q.popleft()
        buf1.extend(l)
        l.append(12)
        q.append(l)
        j=j+1
#print(q)
for l in q:
    l.sort()
    mi=100
    n=len(l)
    for j in range(n-1):
        mi=min(mi,l[j+1]-l[j])
    allmax=max(allmax,mi)
print(allmax)

"""
for i in range(pow(2,n)):
    buf=[0]
    bit=[0]*n
    mi=100
    if count12==1:
        buf.append(12)
    buf.append(0)
    for j in range(n):
        if (i>>j)&1:
            bit[j]=1
    #print(bit)
    for j in range(n):
        buf.append(l[j][bit[j]])
    buf.sort()
    buf.append(24)
    #print(buf)
    for j in range(len(buf)-1):
        mi=min(mi,buf[j+1]-buf[j])
    allmax=max(allmax,mi)
print(allmax)
"""

Submission status: Wrong Answer

Solution code:
import collections
from collections import deque
N=int(input())
D=list(map(int,input().split()))
c=collections.Counter(D)
count0=0
count12=0
l=[]
if c[12]>0:
    count12=1
if c[0]>0:
    count0=1
#print(l,count0,count12)
#print(n)
allmax=0
q=deque()
l=[]
q.append([0])
q.append([24])
if (count0==1):
    q=deque()
    q.append([0,0])
    q.append([24,24])


for i in range(1,12):
    length=len(q)
    j=0
    if c[i]==0: continue
    if c[i]==1:
        while j<length:
            buf1=[]
            buf2=[]
            l=q.popleft()
            buf1.extend(l)
            buf1.append(i)
            buf2.extend(l)
            buf2.append(24-i)
            q.append(buf1)
            q.append(buf2)
            j=j+1
    if c[i]>1:
        while j<length:
            buf1=[]
            buf2=[]
            buf3=[]
            l=q.popleft()
            buf1.extend(l)
            buf1.extend([i,i])
            buf2.extend(l)
            buf2.extend([24-i,24-i])
            buf3.extend(l)
            buf3.extend([i,24-i])
            q.append(buf1)
            q.append(buf2)
            q.append(buf3)
            j=j+1
    #print(q)
    #input()
if count12==1:
    length=len(q)
    j=0
    while j<length:
        buf1=[]
        l=q.popleft()
        buf1.extend(l)
        l.append(12)
        q.append(l)
        j=j+1
#print(q)
for l in q:
    l.sort()
    mi=100
    n=len(l)
    for j in range(n-1):
        mi=min(mi,l[j+1]-l[j])
    allmax=max(allmax,mi)
print(allmax)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,=pin()
    cl=[0]*13
    for d in pin():
        cl[d]+=1
    #print(cl)
    k=[]
    def dfslike(n=0,hist=[]):
        if n>=13:
        
            pass
            #search
            t=sorted(hist)
            temp=min(t[0]-t[-1]+24,t[-1]-t[0])
            for x in range(len(t)-1):
                temp=min(temp,t[x+1]-t[x],24-(t[x+1]-t[x]))
                
            k.append(temp)
            return

        if cl[n]>0:
            dfslike(n+1,hist+[n])
            dfslike(n+1,hist+[24-n])
            if cl[n]>1:
                dfslike(n+1,hist+[n]+[24-n])
        else:
            dfslike(n+1,hist)
    ans=24
    dfslike()
    
    print(max(k))
#%%submit!
resolve()

Submission status: Wrong Answer

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7

n = int(input())
d = list(map(int, input().split()))
Dlist = [0 for i in range(12)]
for num in d:
    if num == 0:
        print(0)
        sys.exit()
    Dlist[num-1]+=1
    if Dlist[num-1] == 3:
        print(0)
        sys.exit()
judge = [0]
unknown = []
if Dlist[11] >= 2:
    print(0)
    sys.exit()
elif Dlist[11] == 1:
    judge.append(12)
for i,num in enumerate(Dlist[1:11]):
    if num == 2:
        judge.append(i+2)
        judge.append(i+14)
    if num == 1:
        unknown.append(i+1)
nujeng = len(unknown)
ans = 0
for i in range(2**nujeng):
    tmp = []
    for num in judge:
        tmp.append(num)
    for j in range(nujeng):
        dnow = unknown[j]
        if ((i >> j) & 1):
            tmp.append(dnow+1)
        else:
            tmp.append(24-dnow-1)
    dic = 50
    if tmp:
        tmp.sort()
        pre = -inf
        for num in tmp:
            if num-pre < dic:
                dic = num-pre
            pre = num
        if 24-tmp[-1] < dic:
            dic = 24-tmp[-1]
        ans = max(dic, ans)
print(ans)

Submission status: Wrong Answer

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

T = [0]*13
T[0] = 1
for d in D:
    T[d] += 1


Times = [0]*24
ones =[]
for i,t in enumerate(T):
    if t>=3 or (t==2 and (i==0 or i==12)):
        print(0)
        exit()
    elif t==2:
        Times[i] = 1
        Times[24-i] = 1
    elif t==1:
        ones.append(i)

ans = 0
L = len(ones)
for i in range(2**L):
    stats = [False]*L
    temp = i
    for j in range(L):
        stats[j] = temp&1
        temp >>= 1
    
    newTime = [t for t in Times]
    res = 10**9
    for j,t in enumerate(ones):
        nt = t if stats[j] else (24-t)%24
        newTime[nt] = 1
    
    gaps = []
    for j,t in enumerate(newTime):
        if t!=0:
            gaps.append(j)
    for j in range(len(gaps)-1):
        res = min(res,min(gaps[j+1]-gaps[j],gaps[j]+24-gaps[j+1]))
    if len(gaps)>=2:
        res = min(res, gaps[0]+24-gaps[1])
    ans = max(ans, res)
print(ans)

Submission status: Wrong Answer

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

T = [0]*13
T[0] = 1
for d in D:
    T[d] += 1


Times = [0]*24
ones =[]
for i,t in enumerate(T):
    if t>=3 or (t==2 and (i==0 or i==12)):
        print(0)
        exit()
    elif t==2:
        Times[i] = 1
        Times[24-i] = 1
    elif t==1:
        ones.append(i)

ans = 0
L = len(ones)
for i in range(2**L):
    stats = [False]*L
    temp = i
    for j in range(L):
        stats[j] = temp&1
        temp >>= 1
    
    newTime = [t for t in Times]
    res = 10**9
    for j,t in enumerate(ones):
        nt = t if stats[j] else (24-t)%24
        newTime[nt] = 1
    
    gaps = []
    for j,t in enumerate(newTime):
        if t==1:
            gaps.append(j)
    for j in range(len(gaps)-1):
        res = min(res,min(gaps[j+1]-gaps[j],gaps[j]+24-gaps[j+1]))
    if len(gaps)>=2:
        res = min(res, gaps[0]+24-gaps[1])
    ans = max(ans, res)
print(ans)

Submission status: Wrong Answer

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

T = [0]*13
T[0] = 1
for d in D:
    T[d] += 1


Times = [0]*24
ones =[]
for i,t in enumerate(T):
    if t>=3 or (t==2 and (i==0 or i==12)):
        print(0)
        exit()
    elif t==2:
        Times[i] = 1
        Times[24-i] = 1
    elif t==1:
        ones.append(i)

ans = 0
L = len(ones)
for i in range(2**L):
    stats = [False]*L
    temp = i
    for j in range(L):
        stats[j] = temp&1
        temp >>= 1
    
    newTime = [t for t in Times]
    res = 10**9
    for j,t in enumerate(ones):
        nt = t if stats[j] else (24-t)%24
        newTime[nt] = 1
    
    gaps = []
    for j,t in enumerate(newTime):
        if t==1:
            gaps.append(j)
    for j in range(len(gaps)-1):
        res = min(res,gaps[j+1]-gaps[j])
    if len(gaps)>=2:
        res = min(res, gaps[0]+24-gaps[1])
    ans = max(ans, res)
print(ans)

Submission status: Wrong Answer

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

T = [0]*13
T[0] = 1
for d in D:
    T[d] += 1


Times = [0]*24
ones =[]
for i,t in enumerate(T):
    if t>=3 or t==2 and (i==0 or i==12):
        print(0)
        exit()
    elif t==2:
        Times[i] = 1
        Times[24-i] = 1
    elif t==1:
        ones.append(i)

ans = 0
L = len(ones)
for i in range(2**L):
    stats = [False]*L
    temp = i
    for j in range(L):
        stats[j] = temp&1
        temp >>= 1
    
    newTime = [t for t in Times]
    res = 10**9
    for j,t in enumerate(ones):
        nt = t if stats[j] else (24-t)%24
        newTime[nt] += 1
    
    gaps = []
    for j,t in enumerate(newTime):
        if t==1:
            gaps.append(j)
    for j in range(len(gaps)-1):
        res = min(res,gaps[j+1]-gaps[j])
    if len(gaps)>=2:
        res = min(res, gaps[0]+24-gaps[1])
    ans = max(ans, res)
print(ans)

Submission status: Wrong Answer

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

T = [0]*13
T[0] = 1
for d in D:
    T[d] += 1


Times = [0]*24
ones =[]
for i,t in enumerate(T):
    if t>=3 or t==2 and (i==0 or i==12):
        print(0)
        exit()
    elif t==2:
        Times[i] = 1
        Times[24-i] = 1
    elif t==1:
        if i!=0:
            ones.append(i)

ans = 0
L = len(ones)
for i in range(2**L):
    stats = [False]*L
    temp = i
    for j in range(L):
        stats[j] = temp&1
        temp >>= 1
    
    newTime = [t for t in Times]
    res = 10**9
    for j,t in enumerate(ones):
        nt = t if stats[j] else 24-t
        newTime[nt] += 1
    
    gaps = []
    for j,t in enumerate(newTime):
        if t==1:
            gaps.append(j)
    for j in range(len(gaps)-1):
        res = min(res,gaps[j+1]-gaps[j])
    if len(gaps)>=2:
        res = min(res, gaps[0]+24-gaps[1])
    ans = max(ans, res)
print(ans)

Submission status: Wrong Answer

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

T = [0]*13
T[0] = 1
for d in D:
    T[d] += 1


Times = [0]*24
ones =[]
for i,t in enumerate(T):
    if t>=3 or t==2 and (i==0 or i==12):
        print(0)
        exit()
    elif t==2:
        Times[i] = 1
        Times[24-i] = 1
    elif t==1:
        if i!=0:
            ones.append(i)

ans = 0
L = len(ones)
for i in range(2**L):
    stats = [False]*L
    temp = i
    for j in range(L):
        stats[j] = temp&1
        temp >>= 1
    
    newTime = [t for t in Times]
    res = 10**9
    for j,t in enumerate(ones):
        nt = t if stats[j] else 24-t
        newTime[nt] += 1
    
    gaps = []
    for j,t in enumerate(newTime):
        if t==1:
            gaps.append(j)
        elif t==2:
            print(0)
            exit()
    for j in range(len(gaps)-1):
        res = min(res,gaps[j+1]-gaps[j])
    if len(gaps)>=2:
        res = min(res, gaps[0]+24-gaps[1])
    ans = max(ans, res)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [0]*13
for i in map(int,input().split()):
  if i == 0:
    print(0)
    exit()
  d[i] += 1
t = [0]*25
t[0] = t[-1] = 1
c = 0
for i,j in enumerate(d):
  if j == 0:
    continue
  elif j >= 2:
    t[i] = t[24-i] = 1
  else:
    if c == 0:
      t[i] = 1
    else:
      t[24-i] = 1
    c = 1-c
m = 24
ans = 24
for i in t:
  m += 1
  if i:
    ans = min(ans,m)
    m = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import sys

N,*D = map(int,open(0).read().split())
lst = []
if N == 1:
    print(min(D[0], 24 - D[0]))
    sys.exit()
if D.count(0) >= 1 or D.count(24) >= 1 or D.count(12) >= 2:
    print(0)
    sys.exit()
if D.count(12) == 1:
    lst.append([12])
lst.append([0,24])

for i in range(1,12):
    i_24 = 24 - i
    cnt = D.count(i)    
    if cnt == 1:
        lst.append([i,i_24])
    elif cnt == 2:
        lst.append([i])
        lst.append([i_24])
    elif cnt >= 3:
        print(0)
        exit()

min_list = []
for i in itertools.product(*lst):
    s = 24
    comb = itertools.combinations(i,2)
    for a,b in comb:
        s = min(abs(b - a), s)
    min_list.append(s)    
print(max(min_list))

Submission status: Wrong Answer

Solution code:
import itertools
import sys

N,*D = map(int,open(0).read().split())
lst = []
if N == 1:
    print(min(D[0], 24 - D[0]))
    sys.exit()
if D.count(0) >= 1 or D.count(24) >= 1 or D.count(12) >= 2:
    print(0)
    sys.exit()
if D.count(12) == 1:
    lst.append([12])
lst.append([0,24])

for i in range(1,12):
    i_24 = 24 - i
    if i_24 in D:
        D.append(i)
    cnt = D.count(i)    
    if cnt == 1:
        lst.append([i,i_24])
    elif cnt == 2:
        lst.append([i])
        lst.append([i_24])
    elif cnt >= 3:
        print(0)
        exit()

min_list = []
for i in itertools.product(*lst):
    s = 24
    comb = itertools.combinations(i,2)
    for a,b in comb:
        s = min(abs(b - a), s)
    min_list.append(s)    
print(max(min_list))