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()))
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]-24]+=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)

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]-24]+=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)

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 d[i]==0:
    print(0)
    exit()
  if i%2:
    if time[d[i]]==1:
      print(0)
      exit()
    time[d[i]]=1
  else:
    if time[24-d[i]]==1:
      print(0)
      exit()
    time[24-d[i]]=1
flg=0
ans=0
cnt=0
for i in range(25):
  i=i%24
  if time[i]==0 and not flg:
    flg=1
    cnt=1
  elif time[i]==0:
    cnt+=1
  else:
    ans=max(ans,cnt)
    cnt=0
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
def f(x):
    i,j = x[0],x[1]
    return min(x[0]+x[1],24-x[0]-x[1])
N = int(input())
D = list(map(int,input().split()))
dmin = min(D)
C = {(i,j):[] for (i,j) in combinations(range(N),2)}
for x in combinations(range(N),2):
    i,j = x[0],x[1]
    C[(i,j)] = max(abs(D[i]-D[j]),f((D[i],D[j])))
dmax = dmin
while True:
    flag = 0
    for x in combinations(range(N),2):
        if C[x]>=dmax:
            continue
        else:
            flag = 1
            break
    if flag==0:
        break
    else:
        dmax -= 1
        
print(dmax)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
exist=[0 for i in range(13)]
for i in l:
  exist[i]+=1
if exist[0]>=1 or exist[-1]>=2 or 3 in exist:print(0)
else:
  single=[]
  stand=[]
  if exist[-1]==1:single.append(12)
  for i in range(1,12):
    if exist[i]==1:
      single.append(i)
    if exist[i]==2:
      stand.append(i)
      stand.append(24-i)
  m=len(single)
  def getstatus(num):
    L=[]
    for i in range(m)[::-1]:
      if num//(2**i)==1:
        L.append(single[i])
      else:
        L.append(24-single[i])
      num%=2**i
    return L
  def dif(LIST):
    ret=100
    for i in range(len(LIST)-1):
      if LIST[i+1]-LIST[i]<ret:ret=LIST[i+1]-LIST[i]
    return ret
  ans=0
  for i in range(2**m):
    if dif(sorted([0]+getstatus(i)+stand+[24]))>ans:ans=dif(sorted([0]+getstatus(i)+stand+[24]))
  print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
exist=[0 for i in range(13)]
for i in l:
  exist[i]+=1
if exist[0]>=1 or exist[-1]>=2 or 3 in exist:print(0)
else:
  single=[]
  stand=[]
  if exist[-1]==1:single.append(12)
  for i in range(1,12):
    if exist[i]==1:
      single.append(i)
    if exist[i]==2:
      stand.append(i)
      stand.append(24-i)
  m=len(single)
  def getstatus(num):
    L=[]
    for i in range(m)[::-1]:
      if num//(2**i)==1:
        L.append(single[i])
      else:
        L.append(24-single[i])
      num%=2**i
    return L
  def dif(LIST):
    ret=100
    for i in range(len(LIST)-1):
      if LIST[i+1]-LIST[i]<ret:ret=LIST[i+1]-LIST[i]
    return ret
  ans=0
  for i in range(2**m):
    if dif(sorted(getstatus(i)+stand))>ans:ans=dif(sorted(getstatus(i)+stand))
  print(ans)

Submission status: Wrong Answer

Solution code:
#n>=25なら鳩ノ巣で0
#2人以上居るdは一意
#あとはしらみつぶし

n = int(input())
if n>=25:
    print(0)
    exit()

d = list(map(int, input().split( )))
if 0 in d:##
    print(0)
    exit()
d.append(0)
dic = {}

for di in d:
    if di in dic:
        dic[di] += 1
    else:
        dic[di]= 1
solo = []
times = []
for di in dic:
    if dic[di]==1:#di=0はここに入る
        solo.append(di)
    elif dic[di]==2:
        times.append(di)
        if di!=12:###12は別扱い
            times.append(24-di)
        else:
            print(0)
            exit()
    else:
        print(0)
        exit()
        
ans = 0
m = len(solo)
bit = 1<<m

for i in range(bit):
    times2 = []
    for t in times:
        times2.append(t)
    for j in range(m):
        if i>>j&1:
            times2.append(solo[j])
        elif solo[j]:
            times2.append(24-solo[j])
    times2.sort()
    dif = 24
    if len(times2)==1:###
        print(0)
        exit()
    #print(times2)

    for k in range(len(times2)-1):
        dif = min(dif,times2[k+1]-times2[k])
    dif = min(dif,times2[0] + 24 - times2[-1])
    ans = max(ans,dif)
print(ans)

Submission status: Wrong Answer

Solution code:
#n>=25なら鳩ノ巣で0
#2人以上居るdは一意
#あとはしらみつぶし

n = int(input())
if n>=25:
    print(0)
    exit()

d = list(map(int, input().split( )))
if 0 in d:##
    print(0)
    exit()
d.append(0)
dic = {}

for di in d:
    if di in dic:
        dic[di] += 1
    else:
        dic[di]= 1
solo = []
times = []
for di in dic:
    if dic[di]==1:#di=0はここに入る
        solo.append(di)
    elif dic[di]==2:
        times.append(di)
        if di!=12:
            times.append(24-di)
    else:
        print(0)
        exit()
        
ans = 0
m = len(solo)
bit = 1<<m

for i in range(bit):
    times2 = []
    for t in times:
        times2.append(t)
    for j in range(m):
        if i>>j&1:
            times2.append(solo[j])
        elif solo[j]:
            times2.append(24-solo[j])
    times2.sort()
    dif = 24
    if len(times2)==1:###
        print(0)
        exit()
    #print(times2)

    for k in range(len(times2)-1):
        dif = min(dif,times2[k+1]-times2[k])
    dif = min(dif,times2[0] + 24 - times2[-1])
    ans = max(ans,dif)
print(ans)

Submission status: Wrong Answer

Solution code:
#n>=25なら鳩ノ巣で0
#2人以上居るdは一意
#あとはしらみつぶし

n = int(input())
if n>=25:
    print(0)
    exit()

d = list(map(int, input().split( )))
if 0 in d:##
    print(0)
    exit()
d.append(0)
dic = {}

for di in d:
    if di in dic:
        dic[di] += 1
    else:
        dic[di]= 1
solo = []
times = []
for di in dic:
    if dic[di]==1:#di=0はここに入る
        solo.append(di)
    elif dic[di]==2:
        times.append(di)
        times.append(24-di)
    else:
        print(0)
        exit()
        
ans = 0
m = len(solo)
bit = 1<<m

for i in range(bit):
    times2 = []
    for t in times:
        times2.append(t)
    for j in range(m):
        if i>>j&1:
            times2.append(solo[j])
        elif solo[j]:
            times2.append(24-solo[j])
    times2.sort()
    dif = 24
    if len(times2)==1:###
        print(0)
        exit()
    #print(times2)

    for k in range(len(times2)-1):
        dif = min(dif,times2[k+1]-times2[k])
    dif = min(dif,times2[0] + 24 - times2[-1])
    ans = max(ans,dif)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(a) for a in input().split()]
X = [0] * 13

for d in D:
    X[d] += 1
if X[0] or max(X) >= 3 or X[12] >= 2:
    print(0)
else:
    ma = 0
    for i in range(1<<13):
        Y = []
        for j in range(13):
            if X[j] == 2:
                Y.append(j)
                Y.append(24-j)
            elif X[j] == 1:
                if i >> j & 1:
                    Y.append(j)
                else:
                    Y.append(24-j)
        Y = sorted(Y)
        M = len(Y)
        ma = max(ma, min([abs((Y[i] - Y[i-1]) % 24) for i in range(M)]))
    print(ma)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(a) for a in input().split()]
X = [0] * 13

for d in D:
    X[d] += 1
if X[0] or max(X) >= 3 or X[12] >= 2:
    print(0)
else:
    ma = 0
    for i in range(1<<13):
        Y = []
        for j in range(13):
            if X[j] == 2:
                Y.append(j)
                Y.append(24-j)
            elif X[j] == 1:
                if i >> j & 1:
                    Y.append(j)
                else:
                    Y.append(24-j)
        Y = sorted(Y)
        M = len(Y)
        ma = max(ma, min([abs(Y[i] - Y[i-1]) for i in range(M)]))
    print(ma)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])


def main():
    n=inp()
    a=inpl()
    a.sort()
    dic = defaultdict(int)
    for i in range(n):
        dic[a[i]] += 1
    for e in dic:
        if dic[e] > 2:
            print(0)
            return
        if e == 0 or e == 12:
            if dic[e]>1:
                print(0)
                return
    x = [0 for _ in range(24)]
    cnt = 0
    for i in range(13):
        if dic[i]==0:
            continue
        elif dic[i] == 1:
            if cnt % 2 == 0:
                x[i] += 1
            else:
                x[24-i] += 1
        else:
            x[i] += 1
            x[24-i] += 1
        cnt += 1
    ans = 24
    for i in range(24):
        for j in range(24):
            if i==j or x[i]==0 or x[j]==0:
                continue
            ans = min(ans,abs(i-j),24-abs(i-j))
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])


def main():
    n=inp()
    a=inpl()
    M=24
    for i in range(n):
        for j in range(i+1,n):
            x1 = a[i]
            y1 = 24-a[i]
            x2 = a[j]
            y2 = 24-a[j]
            z = max( abs(x1-y1), abs(x1-y2), abs(x2-y1), abs(x2-y1))
            M = min(z,M)
    print(M)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#n>=25なら鳩ノ巣で0
#2人以上居るdは一意
#あとはしらみつぶし

n = int(input())
if n>=25:
    print(0)
    exit()

d = list(map(int, input().split( )))
if 0 in d:##
    print(0)
    exit()
d.append(0)
dic = {}

for di in d:
    if di in dic:
        dic[di] += 1
    else:
        dic[di]= 1
solo = []
times = []
for di in dic:
    if dic[di]==1:#di=0はここに入る
        solo.append(di)
    elif dic[di]==2:
        times.append(di)
        times.append(24-di)
    else:
        print(0)
        exit()
        
ans = 0
m = len(solo)
bit = 1<<m

for i in range(bit):
    times2 = []
    for t in times:
        times2.append(t)
    for j in range(m):
        if i>>j&1:
            times2.append(solo[j])
        elif solo[j]:
            times2.append(24-solo[j])
    times2.sort()
    dif = 24
    if len(times2)==1:###
        print(0)
        exit()
    #print(times2)

    for k in range(len(times2)-1):
        dif = min(dif,times2[k+1]-times2[k])
    ans = max(ans,dif)
print(ans)

Submission status: Wrong Answer

Solution code:
#n>=25なら鳩ノ巣で0
#2人以上居るdは一意
#あとはしらみつぶし

n = int(input())
if n>=25:
    print(0)
    exit()

d = list(map(int, input().split( )))
if 0 in d:##
    print(0)
    exit()
d.append(0)
dic = {}

for di in d:
    if di in dic:
        dic[di] += 1
    else:
        dic[di]= 1
solo = []
times = []
for di in dic:
    if dic[di]==1:#di=0はここに入る
        solo.append(di)
    elif dic[di]==2:
        times.append(di)
        times.append(24-di)
    else:
        print(0)
        exit()
        
ans = 0
m = len(solo)
bit = 1<<m

for i in range(bit):
    times2 = []
    for t in times:
        times2.append(t)
    for j in range(m):
        if i>>j&1:
            times2.append(solo[j])
        elif solo[j]:
            times2.append(24-solo[j])
    times2.sort()
    dif = 24
    #print(times2)

    for k in range(len(times2)-1):
        dif = min(dif,times2[k+1]-times2[k])
    ans = max(ans,dif)
print(ans)

Submission status: Wrong Answer

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

s = 24
D.sort()
D2 = D
for i in range(N):
  if D2[i] == D2[i + 1]:
    D2[i] = 24 - D2[i]

D2.sort()
for i in range(N):
  s = min(D2[i + 1] - D2[i], s)
s = min(24 - D2[N] + D2[0], s)

if s != 0 and N <= 12:
  for b in range(1 << N):
    D2 = D
    for i in range(N):
      if b & (1 << i):
        D2[i + 1] = 24 - D2[i + 1]
    D2.sort()
    s2 = 24
    for i in range(N):
      s2 = min(D2[i + 1] - D2[i], s2)
    s2 = min(24 - D2[N] + D[0], s2)
    s = max(s2, s)

print(s)

Submission status: Wrong Answer

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

s = 24
D.sort()
for i in range(N):
  if D[i] == D[i + 1]:
    D[i] = 24 - D[i]

D.sort()
for i in range(N):
  s = min(D[i + 1] - D[i], s)
s = min(24 - D[N] + D[0], s)

if s != 0 or N <= 12:
  for b in range(1 << N):
    D2 = D
    for i in range(N):
      if b & (1 << i):
        D2[i + 1] = 24 - D2[i + 1]
    D2.sort()
    s2 = 24
    for i in range(N):
      s2 = min(D2[i + 1] - D2[i], s2)
    s2 = min(24 - D2[N] + D[0], s2)
    s = max(s2, s)

print(s)

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
print(0)

Submission status: Wrong Answer

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

s = 24
D.sort()
for i in range(N):
  if D[i] == D[i + 1]:
    D[i] = 24 - D[i]

D.sort()
for i in range(N):
  s = min(D[i + 1] - D[i], s)
s = min(24 - D[N] + D[0], s)

if s != 0 and N <= 15:
  for b in range(1 << N):
    D2 = D
    for i in range(N):
      if b & (1 << i):
        D2[i + 1] = 24 - D2[i + 1]
    D2.sort()
    s2 = 24
    for i in range(N):
      s2 = min(D2[i + 1] - D2[i], s2)
    s2 = min(24 - D2[N] + D[0], s2)
    s = max(s2, s)

print(s)

Submission status: Wrong Answer

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

s = 24
D.sort()
for i in range(N):
  if D[i] == D[i + 1]:
    D[i] = 24 - D[i]

D.sort()
for i in range(N):
  s = min(D[i + 1] - D[i], s)
s = min(24 - D[N] + D[0], s)

if s != 0 and N <= 12:
  for b in range(1 << N):
    D2 = D
    for i in range(N):
      if b & (1 << i):
        D2[i + 1] = 24 - D2[i + 1]
    D2.sort()
    s2 = 24
    for i in range(N):
      s2 = min(D2[i + 1] - D2[i], s2)
    s2 = min(24 - D2[N] + D[0], s2)
    s = max(s2, s)

print(s)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = [int(i) for i in input().split()]

cnt = Counter(D)

ret = 0
for i in range(pow(3, len(cnt))) :
  L = [0, 24]
  tmp = float('inf')
  for j, (k, v) in enumerate(cnt.items()) :
    if i % 3 == 0 :
      if v < 2 :
        break
      L.append(k)
      L.append(24 - k)
    elif i % 3 == 1 :
      L.append(k)
    elif i % 3 == 2 :
      L.append(24 - k)
    i //= 3
  else :
    L.sort()
    for i in range(1, len(L)) :
      tmp = min(tmp, L[i] -  L[i-1])
    if tmp != float('inf') :
      ret = max(ret, tmp)

print(ret)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = [int(i) for i in input().split()]

cnt = Counter(D)

ret = 0
for i in range(pow(3, len(cnt))) :
  L = [0]
  tmp = float('inf')
  for j, (k, v) in enumerate(cnt.items()) :
    if i % 3 == 0 :
      if v < 2 :
        break
      L.append(k)
      L.append(24 - k)
    elif i % 3 == 1 :
      L.append(k)
    elif i % 3 == 2 :
      L.append(24 - k)
    i //= 3
  else :
    L.sort()
    for i in range(1, len(L)) :
      tmp = min(tmp, L[i] -  L[i-1])
    if tmp != float('inf') :
      ret = max(ret, tmp)

print(ret)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = [int(i) for i in input().split()]

cnt = Counter(D)

ret = 0
for i in range(pow(3, len(cnt))) :
  L = []
  tmp = float('inf')
  for j, (k, v) in enumerate(cnt.items()) :
    if i % 3 == 0 :
      if v < 2 :
        break
      L.append(k)
      L.append(24 - k)
    elif i % 3 == 1 :
      L.append(k)
    elif i % 3 == 2 :
      L.append(24 - k)
    i //= 3
  else :
    L.sort()
    for i in range(1, len(L)) :
      tmp = min(tmp, L[i] -  L[i-1])
    if tmp != float('inf') :
      ret = max(ret, tmp)

print(ret)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = [int(i) for i in input().split()]

cnt = Counter(D)

ret = 0
for i in range(pow(3, len(cnt))) :
  L = []
  tmp = float('inf')
  for j, (k, v) in enumerate(cnt.items()) :
    if i % 3 == 0 :
      if v < 2 :
        break
      L.append(k)
      L.append(24 - k)
    elif i % 3 == 1 :
      L.append(k)
    elif i % 3 == 2 :
      L.append(24 - k)
    i //= 3
  else :
    if len(L) < 2 :
      continue
    for a in range(len(L)) :
      for b in range(a + 1, len(L)) :
        tmp = min(tmp, abs(L[a] - L[b]))
    ret = max(ret, tmp)

print(ret)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import Counter
from itertools import groupby
def resolve():
    n=int(input())
    D=list(map(int,input().split()))
    if(n>=24):
        print(0)
        return
    for key,val in Counter(D).items():
        if(key==0):
            print(0)
            return
        elif(key==12):
            if(val>=2):
                print(0)
                return
        else:
            if(val>=3):
                print(0)
                return

    def check(V):
        T=[0]*24
        T[0]=1
        for i in range(n):
            d=D[i]
            if((V>>i)&1):
                if(T[d]): return 0
                T[d]=1
            else:
                if(T[-d]): return 0
                T[-d]=1
        score=INF
        for key,it in groupby(T):
            if(key==0):
                score=min(score,len(list(it)))
        if(score==INF): score=0
        return score+1

    N=1<<n
    ans=0
    for V in range(N):
        ans=max(ans,check(V))
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from itertools import groupby
def resolve():
    n=int(input())
    D=list(map(int,input().split()))
    if(n>=24):
        print(0)
        return

    def check(V):
        T=[0]*24
        T[0]=1
        for i in range(n):
            d=D[i]
            if((V>>i)&1):
                if(T[d]): return 0
                T[d]=1
            else:
                if(T[-d]): return 0
                T[-d]=1
        score=INF
        for key,it in groupby(T):
            if(key==0):
                score=min(score,len(list(it)))
        if(score==INF): score=0
        return score+1

    N=1<<n
    ans=0
    for V in range(N):
        ans=max(ans,check(V))
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from itertools import groupby
def resolve():
    n=int(input())
    D=list(map(int,input().split()))
    if(n>=24):
        print(0)
        return

    def check(V):
        T=[0]*24
        T[0]=1
        for i in range(n):
            d=D[i]
            if((V>>i)&1):
                if(T[d]): return 0
                T[d]=1
            else:
                if(T[-d]): return 0
                T[-d]=1
        score=INF
        for key,it in groupby(T*2):
            if(key==0):
                score=min(score,len(list(it)))
        return score+1


    N=1<<n
    ans=0
    for V in range(N):
        ans=max(ans,check(V))
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter
import copy


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

if N >= 24:
    print (0)
    exit()

lst_time = [0]
lst_candidate = []

C = Counter(D)
for i in range(13):
    if i == 0:
        if C[0] > 0:
            print (0)
            exit()
    elif i == 12:
        if C[12] >= 2:
            print (0)
            exit()
        if C[12] == 1:
            lst_time.append(12)
    else:
        if C[i] >= 3:
            print (0)
            exit()
        elif C[i] == 2:
            lst_time.append(i)
            lst_time.append(24 - i)
        elif C[i] == 1:
            lst_candidate.append(i)

# print (lst_time)
# print (lst_candidate)

def calc(lst):
    tmp = 10 ** 9
    for i in range(len(lst)):
        for j in range(i + 1, len(lst)):
            tmp = min(tmp, abs(lst[i] - lst[j]))
    return tmp



s = 0 #ans
n = len(lst_candidate)
for i in range(2 ** n):
    tmp_lst = copy.deepcopy(lst_time)
    for j in range(n):
        if (i >> j) & 1:
            tmp_lst.append(lst_candidate[j])
        else:
            tmp_lst.append(24 - lst_candidate[j])
    
    # print (tmp_lst)
    # tmp = calc(tmp_lst)
    s = max(s, calc(tmp_lst))

print (s)

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 = 24
        for j in range(ne[1]-1):
            if i&(1<<j)==1:
                now.append(cur[j])
            else:
                now.append(24-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):
            if i&(1<<j)==1:
                now.append(cur[j])
            else:
                now.append(24-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)
        elif choice[i]>=3:
            ans = 0
    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)
        else:
            ans = 0
    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()