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:
n = int(input())
D = list(map(int,input().split()))
kouho_1 = [0]*(n+1)
kouho_2 = [0]*(n+1)
flag = False
change = 0
for i in range(n):
    if D[i] == 0:
        kouho_1[i+1] = 0
    elif D[i] == 12:
        kouho_1[i+1] = 12
    else:
        if not flag:
            flag = True
            kouho_1[i+1] = D[i]
        else:
            cur1 = 24
            temp1 = D[i]
            cur2 = 24
            temp2 = 24-D[i]
            for j in range(i+1):
                cur1 = min(cur1, abs(kouho_1[j]-temp1))
            for j in range(i+1):
                cur2 = min(cur2, abs(kouho_1[j]-temp2))
            if cur1 > cur2:
                kouho_1[i+1] = temp1
            else:
                kouho_1[i+1] = temp2
flag = False
for i in range(n):
    if D[i] == 0:
        kouho_2[i+1] = 0
    elif D[i] == 12:
        kouho_2[i+1] = 12
    else:
        if not flag:
            flag = True
            kouho_2[i+1] = 24-D[i]
        else:
            cur1 = 24
            temp1 = D[i]
            cur2 = 24
            temp2 = 24-D[i]
            for j in range(i+1):
                cur1 = min(cur1, abs(kouho_2[j]-temp1))
            for j in range(i+1):
                cur2 = min(cur2, abs(kouho_2[j]-temp2))
            if cur1 > cur2:
                kouho_2[i+1] = temp1
            else:
                kouho_2[i+1] = temp2
ans1 = abs(kouho_1[0]-kouho_1[1])
ans2 = abs(kouho_2[0]-kouho_2[1])
for i in range(n+1):
    for j in range(i+1, n+1):
        ans1 = min(ans1, abs(kouho_1[i]-kouho_1[j]), 24-abs(kouho_1[i]-kouho_1[j]))
        ans2 = min(ans2, abs(kouho_2[i]-kouho_2[j]), 24-abs(kouho_2[i]-kouho_2[j]))
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
D = list(map(int,input().split()))
kouho_1 = [0]*(n+1)
kouho_2 = [0]*(n+1)
flag = False
change = 0
for i in range(n):
    if D[i] == 0:
        kouho_1[i+1] = 0
    elif D[i] == 12:
        kouho_1[i+1] = 12
    else:
        if not flag:
            flag = True
            kouho_1[i+1] = D[i]
        else:
            cur1 = 24
            temp1 = D[i]
            cur2 = 24
            temp2 = 24-D[i]
            for j in range(i+1):
                cur1 = min(cur1, abs(kouho_1[j]-temp1))
            for j in range(i+1):
                cur2 = min(cur2, abs(kouho_1[j]-temp2))
            if cur1 > cur2:
                kouho_1[i+1] = temp1
            else:
                kouho_1[i+1] = temp2
flag = False
for i in range(n):
    if D[i] == 0:
        kouho_2[i+1] = 0
    elif D[i] == 12:
        kouho_2[i+1] = 12
    else:
        if not flag:
            flag = True
            kouho_2[i+1] = 24-D[i]
        else:
            cur1 = 24
            temp1 = D[i]
            cur2 = 24
            temp2 = 24-D[i]
            for j in range(i+1):
                cur1 = min(cur1, abs(kouho_2[j]-temp1))
            for j in range(i+1):
                cur2 = min(cur2, abs(kouho_2[j]-temp2))
            if cur1 > cur2:
                kouho_2[i+1] = temp1
            else:
                kouho_2[i+1] = temp2
ans1 = 24
ans2 = 24
for i in range(n+1):
    for j in range(i+1, n+1):
        ans1 = min(ans1, abs(kouho_1[i]-kouho_1[j]))
        ans2 = min(ans2, abs(kouho_2[i]-kouho_2[j]))
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
D = list(map(int,input().split()))
kouho_1 = [0]*(n+1)
kouho_2 = [0]*(n+1)
flag = False
change = 0
for i in range(n):
    if D[i] == 0:
        kouho_1[i+1] = 0
    elif D[i] == 12:
        kouho_1[i+1] = 12
    else:
        if not flag:
            flag = True
            kouho_1[i+1] = D[i]
        else:
            cur1 = 24
            temp1 = D[i]
            cur2 = 24
            temp2 = 24-D[i]
            for j in range(i+1):
                cur1 = min(cur1, abs(kouho_1[j]-temp1))
            for j in range(i+1):
                cur2 = min(cur2, abs(kouho_1[j]-temp2))
            if cur1 >= cur2:
                kouho_1[i+1] = temp1
            else:
                kouho_1[i+1] = temp2
flag = False
for i in range(n):
    if D[i] == 0:
        kouho_2[i+1] = 0
    elif D[i] == 12:
        kouho_2[i+1] = 12
    else:
        if not flag:
            flag = True
            kouho_2[i+1] = 24-D[i]
        else:
            cur1 = 24
            temp1 = D[i]
            cur2 = 24
            temp2 = 24-D[i]
            for j in range(i+1):
                cur1 = min(cur1, abs(kouho_2[j]-temp1))
            for j in range(i+1):
                cur2 = min(cur2, abs(kouho_2[j]-temp2))
            if cur1 >= cur2:
                kouho_2[i+1] = temp1
            else:
                kouho_2[i+1] = temp2
ans1 = 24
ans2 = 24
for i in range(n+1):
    for j in range(i+1, n+1):
        ans1 = min(ans1, abs(kouho_1[i]-kouho_1[j]))
        ans2 = min(ans2, abs(kouho_2[i]-kouho_2[j]))
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
d.sort()
ans = min(d)
for i in range(n):
    d[i] = 24 - d[i]

for i in range(n):
    for j in range(n):
        if i != j:
            ans = min(ans, abs(d[i]-d[j]))

print(ans)

Submission status: Wrong Answer

Solution code:
N, *D = map(int, open(0).read().split())
D.append(0)
used = [0]*(N+1)
cnt = N
while True:
  ls = []
  for i in range(N+1):
    for j in range(N+1):
      if i==j:
        continue
      a,b = min(D[i],D[j]),max(D[i],D[j])
      d = b-a
      ls.append((min(d,24-d),i,j))
  ls.sort(key=lambda x:x[0])
  d,a,b = ls[0]
  if used[a]==0 and used[b]==0:
    used[a] = 1
    used[b] = 1
    da = (24-D[a])%24
    ma = 100
    for i in range(N+1):
      if i==a:
        continue
      x = abs(da-D[i])
      ma = min(ma,x,24-x)
    db = (24-D[b])%24
    mb = 100
    for i in range(N+1):
      if i==b:
        continue
      x = abs(db-D[i])
      mb = min(mb,x,24-x)
    if ma<mb:
      if d>=mb:
        print(d)
        break
      D[b] = db
    else:
      if d>=ma:
        print(d)
        break
      D[a] = da
  elif used[a]==0:
    used[a] = 1
    da = (24-D[a])%24
    ma = 100
    for i in range(N+1):
      if i==a:
        continue
      x = abs(da-D[i])
      ma = min(ma,x,24-x)
    if d>=ma:
      print(d)
      break
    else:
      D[a] = da
  elif used[b]==0:
    used[b] = 1
    db = (24-D[b])%24
    mb = 100
    for i in range(N+1):
      if i==b:
        continue
      x = abs(db-D[i])
      mb = min(mb,x,24-x)
    if d>=mb:
      print(d)
      break
    else:
      D[b] = mb
  else:
    print(d)
    break

Submission status: Wrong Answer

Solution code:
N = int(input())
Ds = list(map(int, input().split()))
diff = []
for i in range(N):
    el = []
    for j in range(N):
        #自分は除くか
        if i == j : continue
        el.append(abs(Ds[i]-Ds[j]))
    diff.append(el)

ans = 100
for i,d in enumerate(Ds):
    a = abs(24-2*d)
    rel = diff[i]
    rel1 = [min(abs(r-a),24-abs(r-a)) for r in rel]
    if len(rel) == 0:
        print(min(Ds[0],24-Ds[0]))
        exit()
    ret = max(min(rel),min(rel1))
    ans = min(ret,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Ds = list(map(int, input().split()))
diff = []
for i in range(N):
    el = []
    for j in range(N):
        #自分は除くか
        if i == j : continue
        el.append(abs(Ds[i]-Ds[j]))
    diff.append(el)

ans = 100
for i,d in enumerate(Ds):
    a = abs(24-2*d)
    rel = diff[i]
    rel1 = [abs(r-a) for r in rel]
    if len(rel) == 0:
        print(min(Ds[0],24-Ds[0]))
        exit()
    ret = max(min(rel),min(rel1))
    ans = min(ret,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
a = sorted([0]+a)
for i in range(0, n+1, 2): a[i] = 24-a[i]
a.sort()
ans = 23
for i in range(n): ans = min(ans, abs(a[i]-a[i+1])%24)
print(ans)

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
a.sort()
for i in range(0, n, 2): a[i] = 24-a[i]
a.sort()
ans = 24
for i in range(n-1): ans = min(ans, abs(a[i]-a[i+1])%24)
print(ans)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split());a=sorted([0]+a);print(abs((24-a[-2])%24-a[-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
if n >= 24 or 0 in d:
  print(0)
  exit()
mi = 0
for i in range(2**n):
  l = [0]
  for j in range(n):
    if i & (1<<j):
      l.append(d[j])
    else:
      l.append(24-d[j])
  l.sort()
  m = 24
  for j in range(n):
    m = min(m,l[j+1]-l[j])
  mi = max(mi,m)
print(mi)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    D = [int(i) for i in input().split()]
    ans = 0
    cnt = [0]*24
    from collections import Counter
    c = Counter(D)
    cnt[0] = 1
    s = [0]*13
    for k, v in c.items():
        if v >= 3 or k == 0:
            ans = 0
            return print(ans)
        elif v >= 2:
            cnt[k] += 1
            cnt[24 - k] += 1
        elif k == 12:
            cnt[12] += 1
        else:
            s[k] += 1
    if any(c >= 2 for c in cnt):
        return print(0)
    for bit in range(1 << 11):
        cur = cnt[:]
        for i in range(11):
            if s[i+1]:
                if bit & (1 << i):
                    cur[24 - (i+1)] += 1
                else:
                    cur[i+1] += 1
        if any(c >= 2 for c in cnt):
            continue
        pre = 0
        mi = 24
        for i, ne in enumerate(cur[1:] + [1], start=1):
            if ne and i - pre < mi:
                mi = i - pre
                pre = i
        if mi != 24:
            ans = max(ans, mi)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    D = [int(i) for i in input().split()]
    ans = 0
    cnt = [0]*24
    from collections import Counter
    c = Counter(D)
    cnt[0] = 1
    s = []
    for k, v in c.items():
        if v >= 3 or k == 0:
            ans = 0
            return print(ans)
        elif v >= 2:
            cnt[k] += 1
            cnt[24 - k] += 1
        else:
            s.append(k)
    if any(c >= 2 for c in cnt):
        return print(0)
    for bit in range(1 << len(s)):
        cur = cnt[:]
        for i in range(len(s)):
            if bit & (1 << i):
                cur[24 - s[i]] += 1
            else:
                cur[s[i]] += 1
        if any(c >= 2 for c in cnt):
            continue
        pre = 0
        mi = 24
        for i, ne in enumerate(cur[1:] + [1], start=1):
            if ne and i - pre < mi:
                mi = i - pre
                pre = i
        # print(cur, mi)
        ans = max(ans, mi)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    D = [int(i) for i in input().split()]
    ans = 0
    cnt = [0]*24
    from collections import Counter
    c = Counter(D)
    cnt[0] = 1
    s = []
    for k, v in c.items():
        if v >= 3 or k == 0:
            ans = 0
            return print(ans)
        elif v >= 2:
            cnt[k] += 1
            cnt[24 - k] += 1
        else:
            s.append(k)
    if any(c >= 2 for c in cnt):
        return print(0)
    for bit in range(1 << len(s)):
        cur = cnt[:]
        for i in range(len(s)):
            if bit & (1 << i):
                cur[24 - s[i]] += 1
            else:
                cur[s[i]] += 1
        pre = 0
        mi = 24
        for i, ne in enumerate(cur[1:] + [1], start=1):
            if ne and i - pre < mi:
                mi = i - pre
                pre = i
        # print(cur, mi)
        ans = max(ans, mi)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    D = [int(i) for i in input().split()]
    ans = 0
    cnt = [0]*24
    from collections import Counter
    c = Counter(D)
    cnt[0] = 1
    s = []
    for k, v in c.items():
        if v >= 3 or k == 0:
            ans = 0
            return print(ans)
        elif v >= 2:
            cnt[k] += 1
            cnt[24 - k] += 1
        else:
            s.append(k)
    for bit in range(1 << len(s)):
        cur = cnt[:]
        for i in range(len(s)):
            if bit & (1 << i):
                cur[24 - s[i]] += 1
            else:
                cur[s[i]] += 1
        pre = 0
        mi = 24
        for i, ne in enumerate(cur[1:] + [1], start=1):
            if ne and i - pre < mi:
                mi = i - pre
                pre = i
        # print(cur, mi)
        ans = max(ans, mi)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    D = [int(i) for i in input().split()]
    ans = min(D)
    from itertools import combinations
    for clo in range(12, -1, -1):
        possi = False
        for c in combinations(range(N), 2):
            possi = (abs(D[c[0]] - D[c[1]]) >= clo) or \
                    (abs(D[c[0]] - (24 - D[c[1]])) >= clo) or \
                    (abs((24 - D[c[0]]) - D[c[1]]) >= clo) or \
                    (abs((24 - D[c[0]]) - (24 - D[c[1]])) >= clo)
            if not(possi):
                break
        if possi:
            ans = min(ans, clo)
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def saiki(num,lis):
    if num==13:
        temp=10**9
        for i in range(len(lis)-1):
            for j in range(i+1,len(lis)):
                temp=min(temp,abs(lis[i]-lis[j]))
        if temp!=10**9:
            ans.append(temp)
        
    else:
        if dp[num]>2:
            print(0)
            exit()
        elif dp[num]==2:
            saiki(num+1,lis+[num]+[24-num])
            saiki(num+1,lis+[num]+[num])
            saiki(num+1,lis+[24-num]+[24-num])
        elif dp[num]==1:
            saiki(num+1,lis+[num])
            saiki(num+1,lis+[24-num])
        else:
            saiki(num+1,lis)            


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

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

ans=[0]
saiki(0,[])

print(max(ans))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def saiki(num,lis):
    if num==13:
        temp=10**9
        for i in range(len(lis)-1):
            for j in range(i+1,len(lis)):
                temp=min(temp,abs(lis[i]-lis[j]))
        if temp!=10**9:
            ans.append(temp)
        
    else:
        if dp[num]>2:
            print(0)
            exit()
        elif dp[num]==2:
            saiki(num+1,lis+[num]+[24-num])
            saiki(num+1,lis+[num])
            saiki(num+1,lis+[24-num])
        elif dp[num]==1:
            saiki(num+1,lis+[num])
            saiki(num+1,lis+[24-num])
        else:
            saiki(num+1,lis)            


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

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

ans=[0]
saiki(0,[])

print(max(ans))

Submission status: Wrong Answer

Solution code:
INF = 1001001001
N = int(input())
D = [0] + list(map(int, input().split()))

ans = 0
for i in range(1<<(N+1)):
    tmp = INF
    for j in range(N+1):
        if i>>j & 1:
            d1 = D[j]
        else:
            d1 = 24 - D[j]
        for k in range(j+1, N+1):
            if i>>k & 1:
                d2 = D[k]
            else:
                d2 = 24 - D[k]
            tmp = min(abs(d1-d2), 24-abs(d1-d2))
    ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

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

from collections import Counter
C = Counter(D)

ans = 0
import heapq
for pattern in range(1<<11):
    if C[0] >= 1: continue
    if C[12] >= 2: continue
    if C.most_common(1)[0][1] >= 3: continue
    q = [24]
    for d in range(1,12):
        if C[d] == 1:
            if pattern & 1: heapq.heappush(q, d)
            else: heapq.heappush(q, 24-d)
        elif C[d] == 2:
            heapq.heappush(q, d)
            heapq.heappush(q, 24-d)
        pattern>>=1
    if C[12] == 1: heapq.heappush(q, 12)
    pre = 0
    tmp = 24
    for _ in range(N):
        d = heapq.heappop(q)
        tmp = min(tmp, d-pre)
        pre = d
    ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

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

#同じ数が3個以上あるとsは0になる
#0か12が2個以上ある場合も0になる
from collections import Counter
C = Counter(D)
if C.most_common(1)[0][1] >= 3 or\
    C[0] > 1 or C[12] > 1:
    print(0)
    exit()

#同じ数が2個以下、0と12は1個以下なので、Nは24以下
#2**24パターンを全調査する

def diff(a, b):
    d = abs(a-b)
    return min(d, 24-d)

ans = 0
import heapq
for pattern in range(1<<N):
    q = []
    for d in D:
        if pattern & 1:
            if d == 0 or d == 12: break
            d = 24 - d
        heapq.heappush(q, d)
        pattern>>=1
    if len(q) != N: continue
    pre = 0
    tmp = 24
    for _ in range(N):
        d = heapq.heappop(q)
        tmp = min(tmp, diff(pre, d))
        pre = d
    ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

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

#同じ数が3個以上あるとsは0になる
from collections import Counter
if Counter(D).most_common(1)[0][1] >= 3:
    print(0)
    exit()

#同じ数が2個以下なので、Nは26以下
#2**26パターンを全調査する
ans = 0
import heapq
for pattern in range(1<<N):
    q = []
    for d in D:
        if pattern & 1: d = 24 - d
        heapq.heappush(q, d)
        pattern>>=1
    pre = 0
    tmp = 24
    for _ in range(N):
        d = heapq.heappop(q)
        tmp = min(tmp, abs(pre-d))
        pre = d
    ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

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

#同じ数が3個以上あるとsは0になる
from collections import Counter
if Counter(D).most_common(1)[0][1] >= 3:
    print(0)
    exit()

#同じ数が2個以下なので、Nは26以下
#2**26パターンを全調査する

def diff(a, b):
    d = abs(a-b)
    return min(d, 24-d)

ans = 0
import heapq
for pattern in range(1<<N):
    q = []
    for d in D:
        if pattern & 1: d = 24 - d
        heapq.heappush(q, d)
        pattern>>=1
    pre = 0
    tmp = 24
    for _ in range(N):
        d = heapq.heappop(q)
        tmp = min(tmp, diff(pre, d))
        pre = d
    ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
D = list(map(int,input().split()))
dc = Counter(D)
flag = True
count = 0
cand = [0]
one = []
if 0 in dc:
    flag = False
if 12 in dc:
    if dc[12] >= 2:
        flag = False
    else:
        cand.append(12)
for i in range(1,12):
    if i not in dc:
        continue
    if dc[i] == 1:
        count += 1
        one.append(i)
    elif dc[i] >= 3:
        flag = False
        break
    else:
        cand += [24-i,i]
if flag:
    if count:
        ans = 0
        for i in range(2**count):
            candone = []
            for j in range(count):
                if (i >> j) & 1 == 1:
                    candone.append(one[j])
                else:
                    candone.append(24-one[j])
            cand2 = cand+candone
            cand2.sort()
            ans1 = cand2[-1]-cand2[0]
            for i in range(1,len(cand2)):
                ans1 = min(ans1,cand2[i]-cand2[i-1])
            ans = max(ans,ans1)
        print(ans)
    else:
        cand.sort()
        if len(cand) == 1:
            print(0)
        else:
            ans = 24
            for i in range(1,len(cand)):
                ans = min(ans,cand[i]-cand[i-1])
            print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
D = list(map(int,input().split()))
dc = Counter(D)
flag = True
count = 0
cand = [0]
one = []
if 0 in dc:
    flag = False
if 12 in dc:
    if dc[12] >= 2:
        flag = False
    else:
        cand.append(12)
for i in range(1,12):
    if i not in dc:
        continue
    if dc[i] == 1:
        count += 1
        one.append(i)
    elif dc[i] >= 3:
        flag = False
        break
    else:
        cand += [24-i,i]
if flag:
    ans = 0
    for i in range(2**count):
        candone = []
        for j in range(count):
            if (i >> j) & 1 == 1:
                candone.append(one[j])
            else:
                candone.append(24-one[j])
        cand2 = cand+candone
        cand2.sort()
        ans1 = cand2[-1]-cand2[0]
        for i in range(1,len(cand2)):
            ans1 = min(ans1,cand2[i]-cand2[i-1])
        ans = max(ans,ans1)
    print(ans)
    
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
ans = 24
for i in range(N):
    for j in range(N):
        if i != j:
            ans = min(ans,min(D[i]+D[j],24-D[i]-D[j]))
if ans == 24:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
D=[int(i) for i in input().split()]
if n>=24:
  print(0)
else:
  ans=0
  for i in range(2**(n-1)):
    C=[1]+[0]*23+[1]
    C[D[0]]+=1
    for j in range(n-1):
      if i&(1<<j):
        C[24-D[j+1]]+=1
      else:
        C[D[j+1]]+=1
    cur=24
    if max(C)==1:
      t=0
      for j in range(1,25):
        if C[j]:
          cur=min(cur,t)
          t=0
          if not cur:
            break
        else:
          t+=1
    else:
      cur=0
    ans=max(ans,cur)
  print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
D=[int(i) for i in input().split()]
if n>=24:
  print(0)
else:
  ans=0
  for i in range(2**(n-1)):
    C=[0,D[0],24]
    for j in range(n-1):
      if i&(1<<j):
        C.append(24-D[j+1])
      else:
        C.append(D[j+1])
    C.sort()
    cur=24
    for j in range(n):
      cur=min(cur,C[j+1]-C[j])
    ans=max(ans,cur)
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def calc(F):    
    res = 0
    for f in F:
        S = format(f, "023b")[24:1:-1]
        
        count = 12
        tmp = 1
        for s in S:
            if s == "1":
                count = min(count, tmp)
                tmp = 1
            else:
                tmp += 1
        count = min(count, tmp)
        res = max(res, count)
    
    return res


def g(D, F):
    if len(D) == 0:
        return calc(F)

    d = D[0]
    s = set()
    for f in F:
        r = 2 ** d
        if f & r == 0:
            s.add(f + r)
        
        r = 2 ** (24 - d)
        if f & r == 0:
            s.add(f + r)
    
    return g(D[1:], s)
    

def main():
    N = int(input())
    D = read_list()
    F = {1,}    
    print(g(D, F)) 
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def calc(F):    
    res = 0
    for f in F:
        S = format(f, "023b")[24:1:-1]
        
        count = 12
        tmp = 1
        for s in S:
            if s == "1":
                count = min(count, tmp)
                tmp = 1
            else:
                tmp += 1
        count = min(count, tmp)
        res = max(res, count)
    
    return res


def g(D, F):
    if len(D) == 0:
        return calc(F)

    d = D[0]
    s = set()
    for f in F:
        r = 2 ** d
        if f & r == 0:
            s.add(f + r)
        
        r = 2 ** (24 - d)
        if f & r == 0:
            s.add(f + r)
    
    return g(D[1:], s)
    

def main():
    N = int(input())

    D = read_list()
    if D.count(0) > 0:
        print(0)
        return

    if D.count(12) > 1:
        print(0)
        return

    count = {i: 0 for i in range(13)}
    for d in D:
        count[d] += 1

    F = {0,}    
    print(g(D, F)) 
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def calc(F):    
    res = 0
    for f in F:
        S = format(f, "024b")[24:1:-1]
        
        count = 12
        tmp = 1
        for s in S:
            if s == "1":
                count = min(count, tmp)
                tmp = 1
            else:
                tmp += 1
        count = min(count, tmp)
        res = max(res, count)
    
    return res


def g(D, F):
    if len(D) == 0:
        return calc(F)

    d = D[0]
    s = set()
    for f in F:
        r = 2 ** d
        if f & r == 0:
            s.add(f + r)
        
        r = 2 ** (24 - d)
        if f & r == 0:
            s.add(f + r)
    
    return g(D[1:], s)
    

def main():
    N = int(input())

    D = read_list()
    if D.count(0) > 0:
        print(0)
        return

    if D.count(12) > 1:
        print(0)
        return

    count = {i: 0 for i in range(13)}
    for d in D:
        count[d] += 1

    F = {0,}    
    print(g(D, F)) 
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def calc(F):    
    res = 0
    for f in F:
        S = format(f, "024b")[24:1:-1]
        
        count = 12
        tmp = 1
        for s in S:
            if s == "1":
                count = min(count, tmp)
                tmp = 1
            else:
                tmp += 1

        res = max(res, count)
    return res


def g(D, F):
    if len(D) == 0:
        return calc(F)

    d = D[0]
    s = set()
    for f in F:
        r = 2 ** d
        if f & r == 0:
            s.add(f + r)
        
        r = 2 ** (24 - d)
        if f & r == 0:
            s.add(f + r)
    
    return g(D[1:], s)
    

def main():
    N = int(input())

    D = read_list()
    if D.count(0) > 0:
        print(0)
        return

    if D.count(12) > 1:
        print(0)
        return

    count = {i: 0 for i in range(13)}
    for d in D:
        count[d] += 1

    F = {0,}    
    print(g(D, F)) 
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def calc(F):    
    res = 0
    for f in F:
        S = format(f, "024b")[24:1:-1]
        
        count = 12
        tmp = 1
        for s in S:
            if s == "1":
                count = min(count, tmp)
                tmp = 1
            else:
                tmp += 1

        res = max(res, count)
    return res


def g(D, F):
    if len(D) == 0:
        return calc(F)

    d = D[0]
    s = set()
    for f in F:
        r = 2 ** d
        if f & r == 0:
            s.add(f + r)
        
        r = 2 ** (24 - d)
        if f & r == 0:
            s.add(f + r)
    
    return g(D[1:], s)
    

def main():
    N = int(input())
    if N >= 24:
        print(0)
        return

    D = read_list()
    if D.count(0) > 0:
        print(0)
        return

    if D.count(12) > 1:
        print(0)
        return

    count = {i: 0 for i in range(13)}
    for d in D:
        count[d] += 1

    F = {0,}    
    print(g(D, F)) 
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)

n = int(input())
D = list(map(int, input().split()))
def dfs(i, j, former):
  if j==n:
    return True
  s = (D[j]-former)%24
  t = (-D[j]-former)%24
  a, b = False, False
  if min(s, 24-s) >= i:
    a = dfs(i, j+1, D[j])
  if min(t, 24-t) >= i:
    b = dfs(i, j+1, 24-D[j])
  return a|b
for i in range(min(D), -1, -1):
  if dfs(i, 0, 0):
    print(i)
    break

Submission status: Wrong Answer

Solution code:
n = int(input())
D = list(map(int, input().split()))
for i in range(min(D), -1, -1):
  L = [0]*(n+1)
  for j in range(n):
    s = (D[j]-L[j])%24
    t = (-D[j]-L[j])%24
    if min(s, 24-s) >= i:
      L[j+1] = D[j]
    elif min(t, 24-t) >= i:
      L[j+1] = 24-D[j]
    else:
      break
  else:
    ans = i
    break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
d.sort()
time=[0]*24
time[0]=1
for i in range(n):
  if i%2:
    time[d[i]]+=1
  else:
    time[d[i]-24]+=1
if max(time)>1:
  print(0)
  exit()
ans=[]
cnt=1
for i in range(1,25):
  i=i%24
  if time[i]==0:
    cnt+=1
  else:
    ans.append(cnt)
    cnt=1
print(min(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
d.sort()
time=[0]*24
time[0]=1
for i in range(n):
  if i%2:
    time[d[i]]+=1
  else:
    time[d[i]-24]+=1
if max(time)>1:
  print(0)
  exit()
ans=[]
cnt=1
for i in range(25):
  i=i%24
  if time[i]==0:
    cnt+=1
  else:
    ans.append(cnt)
    cnt=1
print(min(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
d.sort()
time=[0]*24
time[0]=1
for i in range(n):
  if i%2:
    time[d[i]]+=1
  else:
    time[d[i]-24]+=1
if max(time)>1:
  print(0)
  exit()
ans=[]
cnt=0
for i in range(25):
  i=i%24
  if time[i]==0:
    cnt+=1
  else:
    if cnt:
      ans.append(cnt)
    cnt=0
print(min(ans)+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
d.sort()
time=[0]*24
time[0]=1
if n==0:
  print(0)
  exit()
for i in range(n):
  if i%2:
    time[d[i]]+=1
  else:
    time[d[i]-23]+=1
if max(time)>1:
  print(0)
  exit()
ans=0
cnt=0
for i in range(25):
  i=i%24
  if time[i]==0:
    cnt+=1
  else:
    ans=max(ans,cnt)
    cnt=0
print(ans+1)