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 = sys.stdin.readline
n = int(input())
D = list(map(int,input().split()))

C = [0] * 13
C[0] = 1
for i in range(n):
    C[D[i]] += 1
for i in range(13):
    C[i] = min(2, C[i])

D = []
for i in range(13):
    for j in range(C[i]):
        D.append(i)

# D.append(0)
# n += 1
# D = list(set(D))
# print(D,n)
# if len(D) < n:
#     print(0)

n = len(D)
A = [0] * n
ans0 = 0
for i in range(2**n):
    ib = format(i, "b").zfill(n)
    for j in range(n):
        A[j] = D[j] * (-1) ** int(ib[j])
    ans = 30
    for j in range(n):
        for k in range(j+1, n):
            di = abs(A[k] - A[j])
            # print(ans)
            ans = min(ans, min(di, 24-di))
    # print(ib, ans0,ans)
    ans0 = max(ans0, ans)
print(ans0)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
D = list(map(int,input().split()))
A = [0] * (n+1)
ans0 = 0
for i in range(n**2):
    ib = format(i, "b").zfill(n)
    for j in range(n):
        A[j] = D[j] * (-1) ** int(ib[j])
    ans = 30
    for j in range(n+1):
        for k in range(j+1, n+1):
            di = abs(A[k] - A[j])
            ans = min(ans, min(di, 24-di))
    ans0 = max(ans0, ans)
print(ans0)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    d = list(map(int, input().split()))
    if n == 1:
        print(d[0])
        exit()
    dc = defaultdict(int)
    dc[0] = 1
    for i in range(n):
        v = d[i]
        if dc[v] >= 2 or (dc[v] == 1 and (v == 12 or v == 0)):
            print(0)
            exit()
        dc[v] += 1
    
    dd = []
    ddt = []
    for i in range(0, 13):
        if (i == 0 or i == 12) and dc[i] == 1:
            ddt.append(i)
        elif dc[i] == 1:
            dd.append(i)
        elif dc[i] == 2:
            ddt.append(i)
            ddt.append(24 - i)


    
    ans = 0
    for i in range(1 << len(dd)):
        d3 = []
        for j in range(len(ddt)):
            d3.append(ddt[j])

        for j in range(len(dd)):
            if (i & (1 << j)):
                d3.append(dd[j])
            else:
                d3.append(24 - dd[j])
        
        d3 = sorted(d3)
        t = float("inf")
        for i in range(len(d3) - 1):
            t = min(t, d3[i + 1] - d3[i])
        ans = max(t, ans)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    d = list(map(int, input().split()))
    if n == 1:
        print(d[0])
        exit()
    dc = defaultdict(int)
    dc[0] = 1
    for i in range(n):
        v = d[i]
        if dc[v] >= 2 or (dc[v] == 1 and (v == 12 or v == 0)):
            print(0)
            exit()
        dc[v] += 1
    
    dd = []
    ddt = []
    for i in range(0, 13):
        if (i == 0 or i == 12) and dc[i] == 1:
            ddt.append(i)
        if dc[i] == 1:
            dd.append(i)
        elif dc[i] == 2:
            ddt.append(i)
            ddt.append(24 - i)


    
    ans = 0
    for i in range(1 << len(dd)):
        d3 = []
        for j in range(len(ddt)):
            d3.append(ddt[j])

        for j in range(len(dd)):
            if (i & (1 << j)):
                d3.append(dd[j])
            else:
                d3.append(24 - dd[j])
        
        d3 = sorted(d3)
        t = float("inf")
        for i in range(len(d3) - 1):
            t = min(t, d3[i + 1] - d3[i])
        ans = max(t, ans)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    d = list(map(int, input().split()))
    if n == 1:
        print(d[0])
        exit()
    d2 = []
    dc = defaultdict(int)
    for i in range(n):
        v = d[i]
        if dc[v] >= 2 or (dc[v] == 1 and v == 12) or v == 0:
            print(0)
            exit()
        dc[v] += 1
        d2.append(v)
    
    dd = []
    ddt = []
    for i in range(0, 13):
        if dc[i] == 1:
            dd.append(i)
        elif dc[i] == 2:
            ddt.append(i)
            ddt.append(24 - i)


    
    ans = 0
    for i in range(1 << len(dd)):
        d3 = [0]
        for j in range(len(ddt)):
            d3.append(ddt[j])

        for j in range(len(dd)):
            if (i & (1 << j)):
                d3.append(dd[j])
            else:
                d3.append(24 - dd[j])
        
        d3 = sorted(d3)
        t = float("inf")
        for i in range(len(d3) - 1):
            t = min(t, d3[i + 1] - d3[i])
        t = min(t , 24 - d[-1])
        ans = max(t, ans)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    d = list(map(int, input().split()))
    if n == 1:
        print(d[0])
        exit()
    d2 = []
    dc = defaultdict(int)
    for i in range(n):
        v = d[i]
        if dc[v] >= 2 or (dc[v] == 1 and v == 12) or v == 0:
            print(0)
            exit()
        dc[v] += 1
        d2.append(v)
    
    dd = []
    ddt = []
    for i in range(0, 13):
        if dc[i] == 1:
            dd.append(i)
        elif dc[i] == 2:
            ddt.append(i)
            ddt.append(24 - i)


    
    ans = 0
    for i in range(1 << len(dd)):
        d3 = [0]
        for j in range(len(ddt)):
            d3.append(ddt[j])

        for j in range(len(dd)):
            if (i & (1 << j)):
                d3.append(dd[j])
            else:
                d3.append(24 - dd[j])
        
        d3 = sorted(d3)
        t = float("inf")
        for i in range(len(d3) - 1):
            t = min(t, d3[i + 1] - d3[i])
        ans = max(t, ans)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    d = list(map(int, input().split()))
    if n == 1:
        print(d[0])
        exit()
    d2 = []
    dc = defaultdict(int)
    for i in range(n):
        v = d[i]
        if dc[v] >= 2 or (dc[v] == 1 and v == 12) or v == 0:
            print(0)
            exit()
        dc[v] += 1
        d2.append(v)
    
    dd = []
    ddt = []
    for i in range(0, 13):
        if dc[i] == 1:
            dd.append(i)
        elif dc[i] == 2:
            ddt.append(i)
            ddt.append(24 - i)


    
    ans = 0
    for i in range(1 << len(dd)):
        d3 = []
        for j in range(len(ddt)):
            d3.append(ddt[j])

        for j in range(len(dd)):
            if (i & (1 << j)):
                d3.append(dd[j])
            else:
                d3.append(24 - dd[j])
        
        d3 = sorted(d3)
        t = float("inf")
        for i in range(len(d3) - 1):
            t = min(t, d3[i + 1] - d3[i])
        ans = max(t, ans)
    print(ans)
 


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    d = list(map(int, input().split()))
    if n == 1:
        print(min(d[0],24 - d[0]))
        exit()
    d2 = []
    dc = defaultdict(int)
    for i in range(n):
        v = min(d[i], 24 - d[i])
        if dc[v] > 2 or (dc[v] == 1 and v == 12) or v == 0:
            print(0)
            exit()
        dc[v] += 1
        d2.append(v)
    
    dd = []
    ddt = []
    for i in range(0, 13):
        if dc[i] == 1:
            dd.append(i)
        elif dc[i] == 2:
            ddt.append(i)
            ddt.append(24 - i)


    
    ans = 0
    for i in range(1 << len(dd)):
        d3 = []
        for j in range(len(ddt)):
            d3.append(ddt[j])

        for j in range(len(dd)):
            if (i & (1 << j)):
                d3.append(dd[j])
            else:
                d3.append(24 - dd[j])
        
        d3 = sorted(d3)
        t = float("inf")
        for i in range(len(d3) - 1):
            t = min(t, d3[i + 1] - d3[i])
        ans = max(t, ans)
    print(ans)
   


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    d = list(map(int, input().split()))
    if n == 1:
        print(d[0])
        exit()
    d2 = []
    dc = defaultdict(int)
    for i in range(n):
        v = min(d[i], 24 - d[i])
        if dc[v] > 2 or (dc[v] == 1 and (v == 0 or v == 12)):
            print(0)
            exit()
        dc[v] += 1
        d2.append(v)
    
    ans = 0
    for i in range(1 << len(d2)):
        d3 = []
        for j in range(len(d2)):
            if (i & (1 << j)):
                d3.append(d2[j])
            else:
                d3.append(24 - d2[j])
        
        d3 = sorted(d3)
        t = float("inf")
        for i in range(len(d3) - 1):
            t = min(t, d3[i + 1] - d3[i])
        ans = max(t, ans)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

import collections

n = int(input())

inp_list = list(map(int, input().split()))
inp_list.append(0)

c = collections.Counter(inp_list)
a = c.most_common()


def ura(time):
    if time == 12:
        time = 12
    elif time == 0:
        time = 0
    else:
        time = 24 - time

    return time


member = []

for tup in a:
    if tup[1] > 1:
        member.append(tup[0])
        member.append(tup[0])
    elif tup[1] == 1:
        member.append(tup[0])


ans = 0

for i in range(2**len(member)):
    trry = format(i, '0' + str(len(member))+'b')
    time_diff = 24

    for ii in range(len(member)-1):
        for iii in range(ii+1, len(member)):
            A = member[ii]
            if trry[iii] == '0':
                B = member[iii]
            else:
                B = ura(member[iii])
            a_b = abs(A-B)
            b_a = min(A, B)+24-max(A, B)
            time_diff = min(time_diff, a_b, b_a)

    ans = max(ans, time_diff)

print(ans)

Submission status: Wrong Answer

Solution code:
import copy

N=int(input())
D=list(map(int,input().split()))
D.sort()
time=[]
kakutei=[]
tmp=0
for d in D: 
  if d==0:
    print(0)
    exit()
  elif tmp==d:
    count+=1
    if count>=2 or (d==12 and count>=1):
      print(0)
      exit()
  else:
    count=0
  if d not in time:
    if d==12:
      kakutei.append(d)
    else:
      time.append(d)
  elif 24-d not in time and d!=12:
    kakutei.append(d)
    kakutei.append(24-d)
    time.remove(d)
  tmp=d
kakutei.append(0)
ans=0
if len(time)==0:
  kakutei.sort()
  minclock=12
  for j in range(len(kakutei)-1):
    minclock=min(minclock,kakutei[j+1]-kakutei[j])
  ans=max(ans,minclock)
  print(ans)
  exit()
for i in range(2**len(time)):
  clock=kakutei.copy()
  bit = format(i, "b").zfill(len(time))
  for i in range(len(bit)):
    if bit[i]=='0':
      clock.append(time[i])
    else:
      clock.append(24-time[i])
  clock.sort()
  minclock=12
  for j in range(len(clock)-1):
    minclock=min(minclock,clock[j+1]-clock[j])
  ans=max(ans,minclock)
print(ans)

Submission status: Wrong Answer

Solution code:
import copy

N=int(input())
D=list(map(int,input().split()))
D.sort()
time=[]
kakutei=[]
tmp=0
for d in D: 
  if d==0:
    print(0)
    exit()
  elif tmp==d:
    count+=1
    if count>=2 or (d==12 and count>=1):
      print(0)
      exit()
  else:
    count=0
  if d not in time:
    if d==12:
      kakutei.append(d)
    else:
      time.append(d)
  elif 24-d not in time:
    kakutei.append(d)
    kakutei.append(24-d)
    time.remove(d)
  tmp=d
kakutei.append(0)
ans=0
if len(time)==0:
  kakutei.sort()
  minclock=12
  for j in range(len(kakutei)-1):
    minclock=min(minclock,kakutei[j+1]-kakutei[j])
  ans=max(ans,minclock)
  print(ans)
  exit()
for i in range(2**len(time)):
  clock=kakutei.copy()
  bit = format(i, "b").zfill(len(time))
  for i in range(len(bit)):
    if bit[i]=='0':
      clock.append(time[i])
    else:
      clock.append(24-time[i])
  clock.sort()
  minclock=12
  for j in range(len(clock)-1):
    minclock=min(minclock,clock[j+1]-clock[j])
  ans=max(ans,minclock)
print(ans)

Submission status: Wrong Answer

Solution code:

N=int(input())

D=list(map(int,input().split()))
flg =False
A = [0 for i in range(13)]
A[0]=1
for i in range(N):
    j = min(i,24-i)
    if j==0:
        flg=True
        break
    elif j==12:
        if A[j]==1:
            flg=True
            break
        else:
            A[j]+=1
    else:
        if A[j]==2:
            flg=True
            break
        else:
            A[j]+=1

import copy

if flg:
    print(0)
else:
    count=0
    one_times=[]
    times=[0]
    for i in range(1,12): 
        if A[i]==1:
            count+=1
            one_times.append(i)
        if A[i]==2:
            times.append(i)
            times.append(24-i)
    if A[12]==1:
        times.append(12)
    score_max=0
    for i in range(2**count):
        t=copy.copy(times)
        for j in range(count):
            if (i//(2**j))%2==0:
                t.append(one_times[j])
            else:
                t.append(24-one_times[j])
        t.sort()
        score_min=24
        for j in range(len(t)):
            if j==len(t)-1:
                score_min=min(t[0]+24-t[len(t)-1],score_min)
            else:
                score_min=min(t[j+1]-t[j],score_min)
        score_max=(score_min,score_max)
    print(score_max)

Submission status: Wrong Answer

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

D1 = [0] + [(D[i] if i % 2 == 0 else 24 - D[i]) for i in range(N)]
D2 = [0] + [(D[i] if i % 2 == 0 else 24 - D[i]) for i in range(N)]

ans1 = float('inf')
ans2 = float('inf')

for i in range(1, N + 1):
    ans1 = min(ans1, abs(D1[i] - D1[i - 1]))
    ans2 = min(ans2, abs(D2[i] - D2[i - 1]))

print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import collections


def main(N, D):
    Dcounter = collections.Counter(D)
    a = [0, ]
    b = []
    for i, v in Dcounter.items():
        if v > 2 or (i == 0 and v > 0) or (i == 12 and v > 1):
            print(0)
            return
        if v == 2:
            a.append(i)
            a.append(24-i)
        if v == 1:
            b.append(i)
    ans = 0
    for i in range(1 << len(b)):
        use = a.copy()
        for j in range(len(b)):
            if ((i >> j) & 1) == 1:
                use.append(b[j])
            else:
                use.append(24-b[j])
        use = sorted(use)
        distance = [use[i+1] - use[i] for i in range(len(use)-1)]
        ans = max(ans, min(distance))
    print(ans)

if __name__ == "__main__":
    N = int(input())
    D = list(map(int, input().split(" ")))
    main(N, D)

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
d=i2()
e=[[d[0],24-d[0]]]
ccc=100

for i in range(1,n):
 cc=[]
 for j in [d[i],24-d[i]]:
  c=100
  for k in e:
   x=abs(j-k[0])
   x=min(x,24-x)
   y=abs(j-k[1])
   y=min(y,24-x)
   c=min(c,max(x,y))
  cc.append(c)
 ccc=min(ccc,max(cc))
 e.append([d[i],24-d[i]])

if ccc==100:
   print(min(d[0],24-d[0]))
else:
   print(ccc)

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
d=i2()
e=[[d[0],24-d[0]]]
ccc=100

for i in range(1,n):
 cc=[]
 for j in [d[i],24-d[i]]:
  c=100
  for k in e:
   c=min(c,max(abs(j-k[0]),abs(j-k[1])))
  cc.append(c)
 ccc=min(ccc,max(cc))
 e.append([d[i],24-d[i]])

if ccc==100:
   print(min(d[0],24-d[0]))
else:
   print(ccc)

Submission status: Wrong Answer

Solution code:
import sys
N=int(input())
D=[int(i) for i in input().split()]
if N==1:
    print(0)
    sys.exit()
L=[0]*13
L[0]=1
for d in D:
    L[d]+=1
for s in L:
    if s>=3:
        print(0)
        sys.exit()
if L[0]>=2 or L[12]>=2:
    print(0)
    sys.exit()
#print(L)
def check(K):
    sta=0
    #end=0
    num=10**9
    ans=10**9
    while sta<24:
        if K[sta]==1:
            ans=min(ans,num)
            num=0
        sta+=1
        num+=1
        #print(num,sta,ans)
    ans=min(num,ans)
    return ans


ans=-1
for s in range(1<<11):
    K=[0]*24
    K[0]=1
    if L[12]==1:
        K[12]=1
    for j in range(11):
        if L[j+1]==0:
            continue
        if L[j+1]==2:
            K[j+1]=1
            K[24-(j+1)]=1
            continue
        if (s&(1<<j)):
            K[j+1]=1
        else:
            K[24-(j+1)]=1
    ans=max(ans,check(K))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())+1
D=[0]+[int(i) for i in input().split()]
ans=12
for i in D:
  for j in D:
    x=[i,24-i]
    y=[j,24-j]
    for p in x:
      for q in y:
        if ans>min(abs(p-q),24-abs(p-q)):
          ans=min(abs(p-q),24-abs(p-q))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())


N = int(input())
dd = inpl()

cnt = [0]*13
for d in dd:
    cnt[d] += 1

koho = [0]
ed1 = []

if cnt[0] > 0:
    print(0)
    sys.exit()

if cnt[12] >= 2:
    print(0)
    sys.exit()
elif cnt[12] == 1:
    koho.append(12)


for d,n in enumerate(cnt):
    if d == 12:
        continue
    if n >= 3:
        print(0)
        sys.exit()
    elif n == 2:
        koho.append(d)
        koho.append(24-d)
    elif n == 1:
        ed1.append(d)

L = len(ed1)
ans = 0
if L != 0:
    for bit in range((1<<L)-1):
        tmp = koho[:]
        for b in range(L):
            if bit & (1<<b):
                tmp.append(ed1[b])
            else:
                tmp.append(24-ed1[b])

        tmp.sort()
        azusa = INF
        azunyan = len(tmp)
        for x in range(1,azunyan):
            azusa = min(tmp[x]-tmp[x-1],azusa)
        ans = max(azusa,ans)
else:
    tmp = koho[:]
    azunyan = len(tmp)
    ans = INF
    for x in range(1,azunyan):
        ans = min(tmp[x]-tmp[x-1],ans)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())


N = int(input())
dd = inpl()

cnt = [0]*13
for d in dd:
    cnt[d] += 1

koho = [0]
ed1 = []
for d,n in enumerate(cnt):
    if n >= 3:
        print(0)
        sys.exit()
    elif n == 2:
        koho.append(d)
        koho.append(24-d)
    elif n == 1:
        ed1.append(d)

L = len(ed1)
ans = 0
if L != 0:
    for bit in range((1<<L)-1):
        tmp = koho[:]
        for b in range(L):
            if bit & (1<<b):
                tmp.append(ed1[b])
            else:
                tmp.append(24-ed1[b])

        tmp.sort()
        azusa = INF
        azunyan = len(tmp)
        for x in range(1,azunyan):
            azusa = min(tmp[x]-tmp[x-1],azusa)
        ans = max(azusa,ans)
else:
    tmp = koho[:]
    azunyan = len(tmp)
    ans = INF
    for x in range(1,azunyan):
        ans = min(tmp[x]-tmp[x-1],ans)

if ans == 24:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from numpy import *
from scipy import *

n = array(input(), dtype=int)
d = array(input().split(), dtype=int)
h = zeros(24, dtype=int)
h[0] = 1
h[d] += 1
ans = array(0, dtype=int)
if h[0] >= 2 or h[12] >= 2:
    print(ans)
    exit()
for x in h:
    if x >= 3:
        print(ans)
        exit()

for i in range(12):
    if h[i] >= 2:
        h[24-i] = 2

def dfs(depth, h):
    global ans
    r = 0
    res = inf
    for i in range(1,24):
        r += 1
        if h[i] != 0:
            res = min(res,r)
            r = 0
    res = min(res,r)
    ans = max(ans,res)
    if depth == 12:
        return
    if h[depth] == 1:
        h[depth], h[24-depth] = h[24-depth], h[depth]
        dfs(depth+1, h)
        h[depth], h[24-depth] = h[24-depth], h[depth]
    dfs(depth+1, h)

dfs(1, h)
print(ans)

Submission status: Wrong Answer

Solution code:
from numpy import *
from scipy import *

n = array(input(), dtype=int)
d = array(input().split(), dtype=int)
h = zeros(24, dtype=int)
h[0] = 1
for x in d:
    h[x] += 1
ans = array(0, dtype=int)
if h[0] >= 2 or h[12] >= 2:
    print(ans)
    exit()
for x in h:
    if x >= 3:
        print(ans)
        exit()

for i in range(12):
    if h[i] >= 2:
        h[24-i] = 2

def dfs(depth):
    global ans
    r = 0
    res = inf
    for i in range(1,24):
        r += 1
        if h[i] != 0:
            res = min(res,r)
            r = 0
    res = min(res,r)
    ans = max(ans,res)
    if depth == 12:
        return
    if h[depth] == 1:
        h[depth], h[24-depth] = h[24-depth], h[depth]
        dfs(depth+1)
        h[depth], h[24-depth] = h[24-depth], h[depth]
    dfs(depth+1)

dfs(1)
print(ans)

Submission status: Wrong Answer

Solution code:
from numpy import *
from scipy import *
n = int(input())
d = list(map(int,input().split()))
a = zeros(24)
a[0] += 1
for x in d:
    a[x]+=1

if a[0] >= 2:
    print(0)
    exit()

if a[12] >= 2:
    print(0)
    exit()

for x in a:
    if x >= 3:
        print(0)
        exit()

for i in range(12):
    if a[i] >= 2:
        a[24-i] = 1

def calc_min_range(a):
    ret = inf
    range = 0
    for x in a[1:]:
        if x == 0:
            range += 1
        else:
            range += 1
            ret = min(ret,range)
            range = 0
    ret = min(ret,range)
    return ret
ans = 0
def dfs(depth, a):
    global ans
    if depth == 12:
        return
    if a[depth] == 1:
        a[depth], a[24-depth] = a[24-depth], a[depth]
        ans = max(ans,calc_min_range(a))
        dfs(depth+1, a)
        a[depth], a[24-depth] = a[24-depth], a[depth]
    ans = max(ans,calc_min_range(a))
    dfs(depth+1, a)
dfs(1, a)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import product, combinations


def solve(n, ds):
    if n >= 24:
        return 0
    freq = Counter(ds)
    if 0 in freq or freq[12] >= 2 or max(freq.values()) >= 3:
        return 0
    cmp = set()
    alt = []
    for d, l in freq.items():
        if l == 2 or d == 12:
            cmp.add(d)
            cmp.add(24 - d)
        else:
            alt.append((d, 24 - d))
    tak = min(freq.keys())
    if alt:
        ans = 0
        for prd in product(*alt):
            tmp = min(tak, min((abs(x - y) for x, y in combinations(cmp.union(prd), 2)), default=0))
            ans = max(ans, tmp)
    else:
        ans = min(tak, min((abs(x - y) for x, y in combinations(cmp, 2)), default=0))
    return ans


print(solve(int(input()), list(map(int, input().split()))))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import product, combinations


def solve(n, ds):
    if n >= 24:
        return 0
    freq = Counter(ds)
    if 0 in freq or freq[12] >= 2 or max(freq.values()) >= 3:
        return 0
    cmp = set()
    alt = []
    for d, l in freq.items():
        if l == 2 or d == 12:
            cmp.add(d)
            cmp.add(24 - d)
        else:
            alt.append((d, 24 - d))
    ans = 0
    for prd in product((0, 1), repeat=len(alt)):
        tmp = float('inf')
        tmp_cmp = cmp.copy()
        for i, x in zip(prd, alt):
            tmp_cmp.add(x[i])
        for x, y in combinations(tmp_cmp, 2):
            tmp = min(tmp, abs(x - y))
        ans = max(ans, tmp)
    return ans


print(solve(int(input()), list(map(int, input().split()))))

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
D = [int(d) for d in input().split()]
# N = 5
# D = [3, 5, 7, 9, 12]
counts = [0] * 13

if 0 in D or D.count(12) > 1:
    print(0)
    sys.exit()

for i in range(N):
    if D[i] > 12:
        D[i] = 24 - D[i]
D.append(0)

for d in D:
    counts[d] += 1

E = []
F = []
for idx, count in enumerate(counts):
    if count > 2:
        print(0)
        sys.exit()
    elif count == 2:
        E.append(idx)
        E.append(24 - idx)
    elif idx == 0 or (idx == 12 and count > 0):
        E.append(idx)
    elif count == 1:
        F.append(idx)

max_val = 0


def update(arr):
    global max_val
    min_val = 24
    arr.sort()
    for i in range(1, len(arr)):
        if arr[i] - arr[i - 1] < min_val:
            min_val = arr[i] - arr[i - 1]
    if min_val > max_val:
        max_val = min_val

for i in range(2 ** len(F)):
    G = [0] * len(F)
    for j in range(len(F)):
        if i & (2 ** j):
            G[j] = 24 - F[j]
        else:
            G[j] = F[j]
    update(E + G)

print(max_val)

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np

N = int(input())
D = list(map(int, input().split()))
D.append(0)
m = 0

while 1:
    D.sort()
    Dsub = [(D[i+1] - D[i]) for i in range(len(D)-1)]
    Dsub.sort()

    if m > Dsub[0]:
        break
    else:
        m = Dsub[0]
        Dsub1 = [(D[i+1] - D[i]) for i in range(len(D)-1)]
        index = Dsub1.index(m)
        D[index] = abs(24 - D[index])

print(m)

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np

N = int(input())
D = list(map(int, input().split()))
D.append(0)
m = 0

while 1:
    D.sort()
    Dsub = [(D[i+1] - D[i]) for i in range(len(D)-1)]
    Dsub.sort()

    if m >= Dsub[0]:
        break
    else:
        m = Dsub[0]
        Dsub1 = [(D[i+1] - D[i]) for i in range(len(D)-1)]
        index = Dsub1.index(m)
        D[index] = abs(24 - D[index])

print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
d_l = list(map(int, input().split()))
d_l.insert(0, 0)

mn = None
for i in range(n+1):
    for j in range(i+1, n+1):
        ans = max(abs(d_l[i]-d_l[j]), abs(24-d_l[i]-d_l[j]))
        if mn is None: mn = ans
        if mn > ans: mn = ans

print(mn)

Submission status: Wrong Answer

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

mn = min(d_l)
for i in range(n):
    for j in range(i+1, n):
        ans = max(abs(d_l[i]-d_l[j]), abs(24-d_l[i]-d_l[j]))
        if mn > ans: mn = ans

print(mn)

Submission status: Wrong Answer

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

if n == 1:
    print(0)

mn = min(d_l)
for i in range(n):
    for j in range(i+1, n):
        ans = max(abs(d_l[i]-d_l[j]), abs(24-d_l[i]-d_l[j]))
        if mn > ans: mn = ans

print(mn)

Submission status: Wrong Answer

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

if n == 1:
    print(0)

mn = min(d_l)
for i in range(n):
    for j in range(i+1, n):
        ans = abs(max(d_l[i]-d_l[j], 24-d_l[i]-d_l[j]))
        if mn > ans: mn = ans

print(mn)

Submission status: Wrong Answer

Solution code:
# C問題
def solve(List1,List2):
	maxval = -1
	for i in List1:
		dif = abs(i-List2[0])
		if dif > 12:
			dif = 24 - dif

		if maxval < dif:
			maxval = dif

	return maxval

N = int(input())
D = list(map(int,input().split(" ")))

D = list(map(lambda x:[x,(24-x)],D))

D.append([0,24])

table = []
for i in range(N+1):
	for j in range(i+1,N+1):
		table.append(solve(D[i],D[j])) 
		
print(min(table))

Submission status: Wrong Answer

Solution code:
# C問題
def solve(List1,List2):
	maxval = -1
	for i in List1:
		dif = abs(i-List2[0])
		if dif > 12:
			continue
			
		if maxval < dif:
			maxval = dif

	return maxval

N = int(input())
D = list(map(int,input().split(" ")))

D = list(map(lambda x:[x,(24-x)],D))

D.append([0,24])

table = []
for i in range(N+1):
	for j in range(i+1,N+1):
		table.append(solve(D[i],D[j])) 

print(min(table))

Submission status: Wrong Answer

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

ans = 0
for i in range(len(ds)):
    mx = 1000
    for j in range(len(ds)):
        if i!=j:
            if ds[i]==ds[j]:
                mx = min(mx, abs(ds[i]-(24-ds[j])))
            else:
                mx = min(mx, abs(ds[i]-ds[j]), abs(ds[i]-(24-ds[j])), abs(ds[j]-(24-ds[i])))
            #print("ds[{}], ds[{}]={},{}".format(i, j, ds[i], ds[j]))
            #print("mx:{}".format(mx))
    ans = max(ans, mx)
    #print("ans={}".format(ans))
print(ans if n>1 else 0)