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:
def examC():
    N = I(); D = LI()
    ans = -1
    d = defaultdict(int); d[0] +=1
    choice = [0]*13; choice[0] +=1
    for i in D:
        choice[i] +=1
        if choice[i]>2:
            ans = 0
            break
    if choice[0]==2 or choice[12]==2:
        ans = 0
#    print(choice)
    curT = [0]; cur = []
    for i in range(1,12):
        if choice[i]==1:
            cur.append(i)
        elif choice[i]==2:
            curT.append(i)
            curT.append(24-i)
    ne = Counter(choice)
    if choice[12]==1:
        ne[1] -=1
        curT.append(12)
    loop = 2**(ne[1]-1)
#    print(loop)
    if ans==0:
        print(ans)
        exit()
    ans = 0
    for i in range(loop):
        now = copy.deepcopy(curT); ansC = 12
        for j in range(ne[1]-1):
            if i&(1<<j)==1:
                now.append(cur[j])
            else:
                now.append(12+cur[j])
        now.sort()
        for k in range(len(now)):
            if k != len(now) - 1:
                ansC = min(ansC, now[k + 1] - now[k], 24 - (now[k + 1] - now[k]))
            else:
                ansC = min(ansC, now[k], 24 - now[k])
        ans = max(ans, ansC)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()

Submission status: Wrong Answer

Solution code:
def examC():
    N = I(); D = LI()
    ans = -1
    d = defaultdict(int); d[0] +=1
    choice = [0]*13; choice[0] +=1
    for i in D:
        choice[i] +=1
        if choice[i]>2:
            ans = 0
            break
    if choice[0]==2 or choice[12]==2:
        ans = 0
#    print(choice)
    curT = [0]; cur = []
    for i in range(1,12):
        if choice[i]==1:
            cur.append(i)
        elif choice[i]==2:
            curT.append(i)
            curT.append(24-i)
    ne = Counter(choice)
    if choice[12]==1:
        ne[1] -=1
        curT.append(12)
    loop = 2**(ne[1]-1)
#    print(loop)
    if ans==0:
        print(ans)
        exit()
    ans = 0
    for i in range(loop):
        now = copy.deepcopy(curT); ansC = 12
        for j in range(ne[1]-1):
            print(j)
            if i&(1<<j)==1:
                now.append(cur[j])
            else:
                now.append(12+cur[j])
        now.sort()
        for k in range(len(now)):
            if k != len(now) - 1:
                ansC = min(ansC, now[k + 1] - now[k], 24 - (now[k + 1] - now[k]))
            else:
                ansC = min(ansC, now[k], 24 - now[k])
        ans = max(ans, ansC)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read

N, *D = map(int, read().split())

if N == 1:
    print(0)
    exit()

D_1 = [D.count(i) for i in range(13)]
D_1[0] += D_1.pop()

for i in range(12):
    if i == 0:
        if D_1[i] > 1:
            print(0)
            exit()
    if D_1[i] > 2:
        print(0)
        exit()

d = [False] * (12 + 1 + 12)

# 高橋君
d[12] = True

rl = True
for i in range(12):
    for _ in range(D_1[i]):
        if i == 0:
            i = 12
        if rl:
            d[12 + i] = True
            rl = False
        else:
            d[12 - i] = True
            rl = True

a = [i for i, j in enumerate(d) if j]
a.append(24 + a[0])
s = 24
for i, j in zip(a, a[1:]):
    if j - i < s:
        s = j - i

print(s)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read

N, *D = map(int, read().split())

if N == 1:
    print(0)
    exit()

D.sort()
d = [False] * (12 + 1 + 12)

# 高橋君
d[12] = True

rl = True
for i in D:
    if i == 0:
        i += 12
    
    if rl:
        if not d[12 + i]:
            d[12 + i] = True
            rl = False
        else:
            print(0)
            exit()
    else:
        if not d[12 - i]:
            d[12 - i] = True
            rl = True
        else:
            print(0)
            exit()

a = [i for i, j in enumerate(d) if j]
a.append(24 + a[0])
s = 24
for i, j in zip(a, a[1:]):
    if j - i < s:
        s = j - i

print(s)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read

N, *D = map(int, read().split())

if N == 1:
    print(0)
    exit()

D.sort()
d = [False] * (12 + 1 + 12)

# 高橋君
d[12] = True

rl = True
for i in D:
    if rl:
        if not d[12 + i]:
            d[12 + i] = True
            rl = False
        else:
            print(0)
            exit()
    else:
        if not d[12 - i]:
            d[12 - i] = True
            rl = True
        else:
            print(0)
            exit()

a = [i for i, j in enumerate(d) if j]
a.append(24 + a[0])
s = 24
for i, j in zip(a, a[1:]):
    if j - i < s:
        s = j - i

print(s)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read

N, *D = map(int, read().split())

if N == 1:
    print(0)
    exit()

D.sort()
d = [False] * (12 + 1 + 12)

# 高橋君
d[12] = True

rl = True
for i in D:
    if rl:
        d[12 + i] = True
        rl = False
    else:
        d[12 - i] = True
        rl = True

a = [i for i, j in enumerate(d) if j]
a.append(24 + a[0])
s = 24
for i, j in zip(a, a[1:]):
    if j - i < s:
        s = j - i

print(s)

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

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


def dist(h, counts):
    i = 0
    while counts[(h - i) % 24] == counts[(h + i) % 24] == 0:
        i += 1
    return i


counts = [0] * 25
counts[0] = 1
counts[24] = 1
for i in range(N):
    if dist(D[i], counts) > dist(24 - D[i], counts):
        counts[D[i]] += 1
    else:
        counts[24 - D[i]] += 1

if max(counts) >= 2:
    print(0)
    exit()

cc = []
for i in range(len(counts)):
    if counts[i]:
        cc.append(i)

ans = 24
for a, b in zip(cc, cc[1:]):
    ans = min(ans, abs(a - b))
print(ans)

Submission status: Wrong Answer

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

DC = {}
for d in D:
  if d == 0:
    print(0)
    exit()
  if d in DC:
    DC[d] += 1
  else:
    DC[d] = 1

def Gap(T):
  res = 10**18
  mn = 0
  for i in range(1,len(T)):
    if T[i]:
      res = min(res,i-mn)
      mn = i
  return res

T = [True] + [False for _ in range(23)] + [True]
DD = []
for k,v in DC.items():
  if v == 1:
    DD.append(k)
  elif v > 1:
    T[k] = True
    T[24-k] = True

if len(DD) == 0:
  print(Gap(T))
else:
  ans = 0
  for i in range(1<<len(DD)):
    TT = T[:]
    for j in range(len(DD)):
      if (i>>j)&1 == 1:
        TT[DD[j]] = True
      else:
        TT[24-DD[j]] = True
    ans = max(ans,Gap(TT))
  print(ans)

Submission status: Wrong Answer

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

DC = {}
for d in D:
  if d == 0:
    print(0)
    exit()
  if d in DC:
    DC[d] += 1
  else:
    DC[d] = 1

def Gap(T):
  res = 10**18
  mn = 0
  for i in range(1,len(T)):
    if T[i]:
      res = min(res,i-mn)
      mn = i
  return res

T = [True] + [False for _ in range(22)] + [True]
DD = []
for k,v in DC.items():
  if v == 1:
    DD.append(k)
  elif v > 1:
    T[k] = True
    T[24-k] = True

if len(DD) == 0:
  print(Gap(T))
else:
  ans = 0
  for i in range(1<<len(DD)):
    TT = T[:]
    for j in range(len(DD)):
      if (i>>j)&1 == 1:
        TT[DD[j]] = True
      else:
        TT[24-DD[j]] = True
    ans = max(ans,Gap(TT))
  print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=[int(j) for j in input().split()]+[0]
ans=[]
import collections
c=collections.Counter(d)
l=c.most_common()
l.sort()
ll=[]
p=1
for i,j in l:
    if j>=3 or (i==0 and j>=2):
        print(0)
        exit()
    elif j==2:
        ll.append(i)
        ll.append(24-i)
    else:
        ll.append(p*i)
        p*=-1
import itertools
for i,j in itertools.combinations(ll,2):
    ans.append(min(abs(i-j),24-abs(i-j)))
print(min(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
d=[int(j) for j in input().split()]+[0]
ans=[]

import itertools
for i,j in itertools.combinations(d,2):
    l=[abs(i-j),abs(24-i-j),abs(i-24+j)]
    ll=[]
    for k in l:
        ll.append(min(k,24-k))
    ans.append(max(ll))
print(min(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
D=list(map(int,input().split()))
c=Counter(D)
  
S=[]
D=[]
for i in c:
  if c[i]==1:
    S.append(i)
  elif c[i]==2:
    D.append(i)
    D.append(24-i)
  else:
    print(0)
    exit()

n=len(S)
ans=-1
for i in range(2**n):
  L=[d for d in D]
  for j in range(n):
    if (i>>j)&1==0:
      L.append(S[j])
    else:
      L.append(24-S[j])
      
  L.sort()
  m=25
  for i in range(N):
    d=abs(L[i]-L[i-1])
    m=min(d,24-d,m)
  ans=max(ans,m)
  
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, D):
    D.append(0)
    C = Counter(D)
    if C[0] + C[12] > 1:
        return 0
    

    K = []
    F = []
    for k in C:
        if C[k] > 2:
            return 0
        elif C[k] == 2:
            F.append(24-k)
            F.append(k)
        else:
            K.append(k)
    M = len(K)
    ans = 0
    for S in product([1, -1], repeat=M):
        tmp = []
        for s, v in zip(S, K):
            tmp.append(s*v)
        tmp.extend(F)
        tmp.sort()
        cand = INF
        for i in range(len(tmp)):
            d = abs(tmp[i] - tmp[i-1])
            cand = min(cand, min(24-d, d))

        ans = max(ans, cand)

    return ans

def main():
    N = read_int()
    D = read_int_n()
    print(slv(N, D))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, D):
    D.append(0)
    C = Counter(D)
    if C[0] + C[12] > 1:
        return 0
    

    K = []
    F = []
    for k in C:
        if C[k] > 2:
            return 0
        elif C[k] == 2:
            F.append(-k)
            F.append(k)
        else:
            K.append(k)
    M = len(K)
    ans = 0
    for S in product([1, -1], repeat=M):
        tmp = []
        for s, v in zip(S, K):
            tmp.append(s*v)
        tmp.extend(F)
        tmp.sort()
        cand = INF
        for i in range(len(tmp)):
            d = abs(tmp[i] - tmp[i-1])
            cand = min(cand, min(24-d, d))

        ans = max(ans, cand)

    return ans

def main():
    N = read_int()
    D = read_int_n()
    print(slv(N, D))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, D):
    D.append(0)
    C = Counter(D)
    if C[0] + C[12] > 1:
        return 0
    

    K = []
    for k in C:
        for _ in range(2 if C[k] >= 2 else 1):
            K.append(k)
    M = len(K)
    ans = 0
    for S in product([1, -1], repeat=M):
        tmp = []
        for s, v in zip(S, K):
            tmp.append(s*v)
        tmp.sort()
        cand = INF
        for i in range(M):
            d = abs(tmp[i] - tmp[i-1])
            cand = min(cand, min(24-d, d))
        ans = max(ans, cand)

    return ans

def main():
    N = read_int()
    D = read_int_n()
    print(slv(N, D))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#time gap
n=int(input())
lists=list(map(int,input().split()))
if n>24:
    print(0)
else:
    timelist=[0 for i in range(13)]
    #timelist[i]ってところでi=0,1,2,....12に代入する
    for i in lists:
        timelist[i]+=1
    flag=True
    for j in range(13):
        if j==0:
            if timelist[j]>0:
                flag=False
        else:
            if timelist[j]>2:
                flag=False
    if flag:
        uselist1=[]
        uselist2_=[]
        for i in range(13):
            if timelist[i]==1:
                uselist1.append((i))
            if timelist[i]==2:
                uselist2_.append((i))
            else:
                continue
        uselist2=[]
        for j in uselist2_:
            uselist2.append(j)
            uselist2.append(24-j)
        lens=len(uselist1)
        minilist=[]
        for i in range(2**lens):
            sublist=[0]
            mini=100
            sublist=sublist+uselist2
            j=format(i,"0%ib"%lens)
            for k in range(lens):
                if j[k]=="0":
                    sublist.append(uselist1[k])
                else:
                    sublist.append(24-uselist1[k])
            sublist=sorted(sublist)
            sublist=list(set(sublist))
            lenss=len(sublist)
            for k in range(1,lenss):
                mini=min(mini,sublist[k]-sublist[k-1])
            minilist.append(mini)
        else:
            print(max(minilist))
    if not flag:
        print(0)

Submission status: Wrong Answer

Solution code:
#time gap
n=int(input())
lists=list(map(int,input().split()))
if n>24:
    print(0)
else:
    timelist=[0 for i in range(13)]
    #timelist[i]ってところでi=0,1,2,....12に代入する
    for i in lists:
        timelist[i]+=1
    flag=True
    for j in range(13):
        if j==0 or j==12:
            if timelist[j]>1:
                flag=False
        else:
            if timelist[j]>2:
                flag=False
    if flag:
        uselist1=[]
        uselist2_=[]
        for i in range(13):
            if timelist[i]==1:
                uselist1.append((i))
            if timelist[i]==2:
                uselist2_.append((i))
            else:
                continue
        uselist2=[]
        for j in uselist2_:
            uselist2.append(j)
            uselist2.append(24-j)
        lens=len(uselist1)
        minilist=[]
        for i in range(2**lens):
            sublist=[]
            mini=100
            sublist=sublist+uselist2
            j=format(i,"0%ib"%lens)
            for k in range(lens):
                if j[k]=="0":
                    sublist.append(uselist1[k])
                else:
                    sublist.append(24-uselist1[k])
            sublist=sorted(sublist)
            lenss=len(sublist)
            for k in range(1,lenss):
                mini=min(mini,sublist[k]-sublist[k-1])
            minilist.append(mini)
        if   n==1:
            print(lists[0])
        else:
            print(max(minilist))
    if not flag:
        print(0)

Submission status: Wrong Answer

Solution code:
#time gap
n=int(input())
lists=list(map(int,input().split()))
if n>24:
    print(0)
else:
    timelist=[0 for i in range(13)]
    #timelist[i]ってところでi=0,1,2,....12に代入する
    for i in lists:
        timelist[i]+=1
    flag=True
    for j in range(13):
        if j==0 or j==12:
            if timelist[j]>1:
                flag=False
        else:
            if timelist[j]>2:
                flag=False
    if flag:
        uselist1=[]
        uselist2_=[]
        for i in range(13):
            if timelist[i]==1:
                uselist1.append((i))
            if timelist[i]==2:
                uselist2_.append((i))
            else:
                continue
        uselist2=[]
        for j in uselist2_:
            uselist2.append(j)
            uselist2.append(24-j)
        lens=len(uselist1)
        mini=100
        for i in range(2**lens):
            sublist=[]
            sublist=sublist+uselist2
            j=format(i,"0%ib"%lens)
            for k in range(lens):
                if j[k]=="0":
                    sublist.append(uselist1[k])
                else:
                    sublist.append(24-uselist1[k])
            sublist=sorted(sublist)

            lenss=len(sublist)
            for k in range(1,lenss):
                mini=min(mini,sublist[k]-sublist[k-1])
        if   n==1:
            print(lists[0])
        else:
            print(mini)
    if not flag:
        print(0)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
d = [0] + list(map(int, input().split()))
rres = 0
if N == 1:
  print(d[1])
  exit(0)
for t in range(13):
  res = True
  l = sorted(d)
  nl = sorted(d)
  for _ in range(N + 1):
    l.sort()
    for i in range(N):
      if abs(l[i] - l[i + 1]) < t:
        nl.append(24 - l[i + 1])
        nl.remove(l[i + 1])
    nl.sort()
    l = nl
  for i in range(N):
    if abs(nl[i] - nl[i + 1]) < t:
      res = False
  if res:
    rres = t
    #print(nl)
  else:
    break
 #print(res, t)
print(rres)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
d = [0] + list(map(int, input().split()))
rres = 0
if N == 1:
  print(d[1])
  exit(0)
for t in range(13):
  res = True
  l = sorted(d)
  for i in range(N):
    if abs(l[i] - l[i + 1]) < t:
      l.append(24 - l.pop(i + 1))
      l.sort()
  for i in range(N):
    if abs(l[i] - l[i + 1]) < t:
      res = False
  if res:
    rres = t
  else:
    break
 #print(res, t)
print(rres)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
d = [0] + list(map(int, input().split()))
rres = 0
if N == 1:
  print(d[0])
  exit(0)
for t in range(13):
  res = True
  l = sorted(d)
  for i in range(N):
    if abs(l[i] - l[i + 1]) < t:
      l.append(24 - l.pop(i + 1))
      l.sort()
  for i in range(N):
    if abs(l[i] - l[i + 1]) < t:
      res = False
  if res:
    rres = t
  else:
    break
 #print(res, t)
print(rres)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
if n>=24:
    print(0)
    exit()
if n>=22:
    print(1)
    exit()
op=2**n-1
ans=0
for i in range(op):
    t=[0]
    for j in range(n):
        if i&(2**j)>0:
            t.append(d[j])
        else:
            t.append(24-d[j])
    a=10000
    for p in range(1,1+n):
        for q in range(p):
            b=abs(t[p]-t[q])
            a=min(a,min(b,24-b))
    ans=max(ans,a)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
m = 24
d = list(map(int, input().split()))
d.sort()
d1 = [0] + [m - d[i] if i % 2 and d[i] else d[i] for i in range(n)]
d2 = [0] + [m - d[i] if not i % 2 and d[i] else d[i] for i in range(n)]
m1, m2 = m, m
for i in range(1, n+1):
    m1 = min(m1, abs(d1[i] - d1[i-1]))
    m2 = min(m2, abs(d2[i] - d2[i-1]))
print(max(m1, m2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
d = list(map(int,input().split())) + [0]

data = Counter(d).most_common()
if data[0][1] >= 3:
    print(0)
    exit()
ans = 0
#print(data)
for bit in range(2**11):
    this_time = []
    for x,c in data:
        if c == 2:
            if x == 0 or x == 12:
                print(0)
                exit()
            this_time.append(x)
            this_time.append(24-x)
        else:
            if x == 0 or x == 12:
                this_time.append(x)
            elif bit>>(x-1) & 1:
                this_time.append(x)
            else:
                this_time.append(24-x)
    #print(this_time)
    ans_now = 50
    m = len(this_time)
    for i in range(m):
        for j in range(i+1,m):
            ans_now = min(ans_now,abs(this_time[i]-this_time[j]))
    ans = max(ans,ans_now)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
d = list(map(int,input().split())) + [0]

data = Counter(d).most_common()
if data[0][1] >= 3:
    print(0)
    exit()
ans = 0
#print(data)
for bit in range(2**11):
    this_time = []
    for x,c in data:
        if c == 2:
            if x == 0 or x == 12:
                print(0)
                exit()
            this_time.append(x)
            this_time.append(24-x)
        else:
            if x == 0 or x == 12:
                this_time.append(x)
            elif bit>>(x-1) & 1:
                this_time.append(x)
            else:
                this_time.append(24-x)
    #print(this_time)
    ans_now = 20
    m = len(this_time)
    for i in range(m):
        for j in range(i+1,m):
            ans_now = min(ans_now,abs(this_time[i]-this_time[j]))
    ans = max(ans,ans_now)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [0] + [24] + list(map(int, input().split()))
D.sort()
for i in range(1, N, 2):
    D[i] = 24 - D[i]
D.sort()
answer = 24
for i in range(N):
    answer = min(answer, abs(D[i+1]-D[i]))
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [0, 24] + list(map(int, input().split()))
D.sort()
for i in range(1, N, 2):
    D[i] = 24 - D[i]
D.sort()
answer = 24
for i in range(N):
    answer = min(answer, abs(D[i+1]-D[i]))
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [0, 24] + list(map(int, input().split()))
D.sort()
for i in range(1, N, 2):
    D[i] = 24 - D[i]
D.sort()
answer = 24
for i in range(N+1):
    answer = min(answer, abs(D[i+1]-D[i]))
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [0, 24] + list(map(int, input().split()))
D.sort()
for i in range(1, N, 2):
    D[i] = 24 - D[i]
D.sort()
answer = 24
for i in range(N+1):
    answer = min(answer, D[i+1]-D[i])
print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
D = [0] + list(map(int, input().split()))

for i in range(13):
    if D.count(i) >= 3:
        print(0)
        exit()

# 深さ優先探索で全通りを探索 curは０からスタート
def dfs(cur, times):
    global answer
    if cur == N+1:
        times.sort()
        arr = np.array(times)
        result = (arr[1:] - arr[:-1]).min()
        if result > answer:
            answer = result
            if answer == 1:
                print(1)
                exit()
    else:
        x = D[cur]
        dfs(cur+1, times + [x])
        dfs(cur+1, times + [24-x])

answer = 0
dfs(0, [24])
print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
D = [0] + list(map(int, input().split()))

for i in range(0, 13):
    if D.count(i) >= 3:
        print(0)
        exit()
for i in range(13):
    if (D.count(i) + D.count(i+1)) >= 3:
        print(1)
        exit()

# 深さ優先探索で全通りを探索できるのでは curは０からスタート
def dfs(cur, times):
    global answer
    if cur == N:
        times.sort()
        arr = np.array(times)
        result = (arr[1:] - arr[:-1]).min()
        if result > answer:
            answer = result
    else:
        x = D[cur]
        dfs(cur+1, times + [x])
        dfs(cur+1, times + [24-x])

answer = 0
dfs(0, [0, 24])
print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
D = [0] + list(map(int, input().split()))

if D.count(0) >= 2:
    print(0)
    exit()
for i in range(1, 13):
    if D.count(i) >= 3:
        print(0)
        exit()
for i in range(13):
    if (D.count(i) + D.count(i+1)) >= 3:
        print(1)
        exit()

# 深さ優先探索で全通りを探索できるのでは curは０からスタート
def dfs(cur, times):
    global answer
    if cur == N:
        times.sort()
        arr = np.array(times)
        result = (arr[1:] - arr[:-1]).min()
        if result > answer:
            answer = result
    else:
        x = D[cur]
        dfs(cur+1, times + [x])
        dfs(cur+1, times + [24-x])

answer = 0
dfs(0, [0, 24])
print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
D = list(map(int, input().split()))
if N > 23:
    print(0)
    exit()
if D.count(0) >= 2:
    print(0)
    exit()
for i in range(1, 13):
    if D.count(i) >= 3:
        print(0)
        exit()
for i in range(13):
    if (D.count(i) + D.count(i+1)) >= 3:
        print(1)
        exit()

# 深さ優先探索で全通りを探索できるのでは curは０からスタート
def dfs(cur, times):
    global answer
    if cur == N:
        times.sort()
        arr = np.array(times)
        result = (arr[1:] - arr[:-1]).min()
        if result > answer:
            answer = result
    else:
        x = D[cur]
        dfs(cur+1, times + [x])
        dfs(cur+1, times + [24-x])

answer = 0
dfs(0, [0, 24])
print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
D = list(map(int, input().split()))
if N > 23:
    print(0)
    exit()
for i in range(13):
    if D.count(i) >= 3:
        print(0)
        exit()
for i in range(13):
    if (D.count(i) + D.count(i+1)) >= 3:
        print(1)
        exit()

# 深さ優先探索で全通りを探索できるのでは curは０からスタート
def dfs(cur, times):
    global answer
    if cur == N:
        times.sort()
        arr = np.array(times)
        result = (arr[1:] - arr[:-1]).min()
        if result > answer:
            answer = result
    else:
        x = D[cur]
        dfs(cur+1, times + [x])
        dfs(cur+1, times + [24-x])

answer = 0
dfs(0, [0, 24])
print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
D = list(map(int, input().split()))
if N > 23:
    print(0)
    exit()
for i in range(13):
    if D.count(i) >= 3:
        print(0)
        exit()
for i in range(13):
    if (D.count(i) + D.count(i+1)) == 3:
        print(1)
        exit()

# 深さ優先探索で全通りを探索できるのでは curは０からスタート
def dfs(cur, times):
    global answer
    if cur == N:
        times.sort()
        arr = np.array(times)
        result = (arr[1:] - arr[:-1]).min()
        if result > answer:
            answer = result
    else:
        x = D[cur]
        dfs(cur+1, times + [x])
        dfs(cur+1, times + [24-x])

answer = 0
dfs(0, [0, 24])
print(answer)