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 diff(s, t):
    return min(abs(s-t), 24 - abs(s-t))
def main():
    N = int(input())
    D = [int(x) for x in input().split()]
    print(solve(D))

def solve(D):
    def check(d, di, dj, i, j):
        for k in range(N):
            if k == i or k == j:
                continue
            if diff(D[k], di) < d:
                return None
            if diff(D[k], dj) < d:
                return None
        return d

    D = [0]+D
    D.sort()
    N = len(D)
    answer = None
    for i in range(N):
        Di = D[i]
        Di_ = 24 - D[i]
        for j in range(i+1, N):
            Dj = D[j]
            Dj_ = 24 - D[j]

            m = None
            for di, dj in [(Di, Dj), (Di_, Dj), (Di, Dj_), (Di_, Dj_)]:
                Dij = diff(di, dj)
                dm = check(Dij, di, dj, i, j)
                #print(D, "\t", (i, j), "diff(%2d, %2d) = %2d "%(di, dj, Dij), dm, m)
                if dm is None:
                    continue
                if m is None:
                    m = dm
                m = max(m, dm)
            if answer is None and m is not None:
                answer = m
            answer = max(answer, m) if m else answer
            #print(answer, m)
    if answer is None:
        None[1]
    return answer

def test(D):
    print(D, solve(D))
#test([7, 8, 12])
#test([11, 11])
test([11, 11, 11])
test([0])
main()

Submission status: Wrong Answer

Solution code:
def diff(s, t):
    return min(abs(s-t), 24 - abs(s-t))
def main():
    N = int(input())
    D = [int(x) for x in input().split()]
    print(solve(D))

def solve(D):
    def check(d, di, dj, i, j):
        for k in range(N):
            if k == i or k == j:
                continue
            if diff(D[k], di) < d:
                return None
            if diff(D[k], dj) < d:
                return None
        return d

    D = [0]+D
    D.sort()
    N = len(D)
    answer = None
    for i in range(N):
        Di = D[i]
        Di_ = 24 - D[i]
        for j in range(i+1, N):
            Dj = D[j]
            Dj_ = 24 - D[j]

            m = None
            for di, dj in [(Di, Dj), (Di_, Dj), (Di, Dj_), (Di_, Dj_)]:
                Dij = diff(di, dj)
                dm = check(Dij, di, dj, i, j)
                #print(D, "\t", (i, j), "diff(%2d, %2d) = %2d "%(di, dj, Dij), dm, m)
                if dm is None:
                    continue
                if m is None:
                    m = dm
                m = max(m, dm)
            if answer is None and m is not None:
                answer = m
            answer = max(answer, m) if m else answer
            #print(answer, m)
    return answer

def test(D):
    return
    print(D, solve(D))
#test([7, 8, 12])
#test([11, 11])
test([0])
main()

Submission status: Wrong Answer

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

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

option_times = []
for i in range(len(D)):
    time_a, time_b = D[i], 24-D[i]
    option_times.append((time_a, time_a))


selected_times = [0, option_times[1][0]]
for i in range(1, len(option_times)):
    time_a = 0
    time_b = 0
    for j in range(len(selected_times)):
        if abs(selected_times[j]-option_times[i][0]) > time_a:
            time_a = abs(selected_times[j]-option_times[i][0])
            hoge = option_times[i][0]
    for j in range(len(selected_times)):
        if abs(selected_times[j]-option_times[i][1]) > time_b:
            time_b = abs(selected_times[j]-option_times[i][1])
            hoge = option_times[i][1]

    if time_a > time_b:
        if time_a not in selected_times:
            selected_times.append(time_a)
        else:
            selected_times.append(24-time_a)
    else:
        if time_b not in selected_times:
            selected_times.append(time_b)
        else:
            selected_times.append(24-time_b)

ans = 999
for i in range(len(selected_times)):
    for j in range(len(selected_times)):
        if i == j:
            continue
        ans = min(ans, abs(selected_times[i]-selected_times[j]))

print(ans)

Submission status: Wrong Answer

Solution code:
def diff(s, t):
    return min(abs(s-t), 24 - abs(s - t))
def main():
    N = int(input())
    D = [int(x) for x in input().split()]
    print(solve(D))

def solve(D):
    def check(d, di, dj, i, j):
        for k in range(N):
            if k == i or k == j:
                continue
            if diff(D[k], di) < d:
                return None
            if diff(D[k], dj) < d:
                return None
        return d

    D = [0]+D
    D.sort()
    N = len(D)
    answer = 0
    for i in range(N-1):
        Di = D[i]
        Di_ = 24 - D[i]
        for j in range(i+1, N):
            Dj = D[j]
            Dj_ = 24 - D[j]

            m = None
            for di, dj in [(Di, Dj), (Di_, Dj), (Di, Dj_), (Di_, Dj_)]:
                Dij = diff(di, dj)
                dm = check(Dij, di, dj, i, j)
                #print(D, "\t", (i, j), "diff(%2d, %2d) = %2d "%(di, dj, Dij), dm, m)
                if dm is None:
                    continue
                if m is None:
                    m = dm
                m = max(m, dm)
            answer = max(answer, m) if m else answer
            #print(answer)
    return answer

def test(D):
    return
    print(D, solve(D))
test([7, 12, 8])
test([11, 11])
test([0])
main()

Submission status: Wrong Answer

Solution code:
def diff(s, t):
    return min(abs(s-t), 24 - abs(s - t))
def main():
    N = int(input())
    D = [int(x) for x in input().split()]
    solve(D)

def solve(D):
    def check(d, di, dj, i, j):
        for k in range(N):
            if k == i or k == j:
                continue
            if diff(D[k], di) < d:
                return None
            if diff(D[k], dj) < d:
                return None
        return d

    D = [0]+D
    D.sort()
    N = len(D)
    answer = 0
    for i in range(N-1):
        Di = D[i]
        Di_ = 24 - D[i]
        for j in range(i+1, N):
            Dj = D[j]
            Dj_ = 24 - D[j]

            m = None
            for di, dj in [(Di, Dj), (Di_, Dj), (Di, Dj_), (Di_, Dj_)]:
                Dij = diff(di, dj)
                dm = check(Dij, di, dj, i, j)
                #print(D, "\t", (i, j), "diff(%2d, %2d) = %2d "%(di, dj, Dij), dm, m)
                if dm is None:
                    continue
                if m is None:
                    m = dm
                m = max(m, dm)
            answer = max(answer, m) if m else answer
            #print(answer)
    return answer

def test(D):
    return
    print(D, solve(D))
test([7, 12, 8])
test([11, 11])
test([0])
main()

Submission status: Wrong Answer

Solution code:
n,*d=map(int,open(0).read().split())
if 0 in d or d.count(12)>1 or any(d.count(x)>2 for x in range(1,12)) or n>24:
	print(0)
elif n>12:
	print(1)
else:
	if n==1:
		print(d[0])
	else:
		m=0
		for i in range(2**n):
			l=[0]
			for j in range(n):
				if i>>j&1:
					l.append(24-d[j])
				else:
					l.append(d[j])
			l.sort()
			m=max(m,min(j-i for i,j in zip(l,l[1:])))
		print(m)

Submission status: Wrong Answer

Solution code:
n,*d=map(int,open(0).read().split())
if 0 in d or d.count(12)>1 or any(d.count(x)>2 for x in range(1,12)) or n>23:
	print(0)
elif n>12:
	print(1)
else:
	if n==1:
		print(d[0])
	else:
		m=0
		for i in range(2**n):
			l=[0]
			for j in range(n):
				if i>>j&1:
					l.append(24-d[j])
				else:
					l.append(d[j])
			l.sort()
			m=max(m,min(j-i for i,j in zip(l,l[1:])))
		print(m)

Submission status: Wrong Answer

Solution code:
n,*d=map(int,open(0).read().split())
if n==1:
	print(d[0])
if 0 in d or d.count(12)>1 or any(d.count(x)>2 for x in range(1,12)) or n>23:
	print(0)
elif n>12:
	print(1)
else:
	m=0
	for i in range(2**n):
		l=[0]
		for j in range(n):
			if i>>j&1:
				l.append(24-d[j])
			else:
				l.append(d[j])
		l.sort()
		m=max(m,min(j-i for i,j in zip(l,l[1:])))
	print(m)

Submission status: Wrong Answer

Solution code:

n=int(input())
x=list(map(int,input().split()))

if n==1:
  print(x[0])
  exit()
  
#xC=collections.Counter(x)
result=[]
for i in range(n-1):
  for j in range(i+1,n):
    result.append(max(abs(max(x[i],24-x[i])-min(x[j],24-x[j])),abs(min(x[i],24-x[i])-max(x[j],24-x[j]))))
#print(result)
print(min(result))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#CODEFESTIVAL2017 Final C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
D = LI()
D.sort()
a = D[:]
b = D[:]
if n == 1:
    print(D[0])
    quit()
for i in range(n):
    if i % 2:
        continue
    a[i] = 24 - a[i]
a.sort()
for i in range(n):
    if i % 2:
        b[i] = 24 - b[i]
b.sort()
d = [0] + a
ans1 = inf
for i in range(n):
    ans1 = min(ans1,d[i+1] - d[i])
d = [0] + b
ans2 = inf
for i in range(n):
    ans2 = min(ans2,d[i+1] - d[i])
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#CODEFESTIVAL2017 Final C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
D = LI()
D.sort()
a = D[:]
b = D[:]
if n == 1:
    print(D[0])
    quit()
for i in range(n):
    if i % 2:
        continue
    a[i] = 24 - a[i]
a.sort()
for i in range(n):
    if i % 2:
        b[i] = 24 - b[i]
d = [0] + a
ans1 = inf
for i in range(n):
    ans1 = min(ans1,d[i+1] - d[i])
d = [0] + b
ans2 = inf
for i in range(n):
    ans2 = min(ans2,d[i+1] - d[i])
print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#CODEFESTIVAL2017 Final C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
D = LI()
D.sort()
if n == 1:
    print(D[0])
    quit()
for i in range(n):
    if i % 2:
        continue
    D[i] = 24 - D[i]
D.sort()
d = [0] + D
ans = inf
for i in range(n):
    ans = min(ans,d[i+1] - d[i])
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#CODEFESTIVAL2017 Final C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
d = LI()
if n == 1:
    print(0)
    quit()
lst = []
for i in range(n):
    lst.append(d[i])
    lst.append(24-d[i])
lst.sort()
ans = 0
for i in range(2*n-1):
    ans = max(ans,lst[i+1]-lst[i])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D.sort()
d = D[-1]
D = [(d * (-1) ** i) % 24 for i, d in enumerate(D)]
D.sort()
for i in range(N - 1):
  d = min(D[i + 1] - D[i], d)
print(d)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
h = [0]*13
for i in d:
    h[i] += 1

# 1~11時までの11通りを左右に振る
# 2以上の時の処理が面倒だから再帰で書く
ans = 0
def rec(now, state):
    global ans
    # nowを処理して次に行くか決める
    # 終了
    if now == 13:
        state.sort()
        m = float("Inf")
        for i in range(len(state)):
            m = min(m, min(abs(state[i-1]-state[i]), 24-abs(state[i-1]-state[i])))
        ans = max(ans, m)
    elif now == 0:
        if h[now]:
            return
        rec(now+1, state)
    elif now == 12:
        if h[now]==0:
            rec(now+1, state)
        elif h[now]==1:
            state.append(now)
            rec(now+1, state)
    else:
        if h[now]==0:
            rec(now+1, state)
        elif h[now]==1:
            s = state[:]
            s.append(now)
            rec(now+1,s)
            s = state[:]
            s.append(24-now)
            rec(now+1, s)
        elif h[now]==2:
            state.append(now)
            state.append(24-now)
            rec(now+1, state)
rec(0, [])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
h = [0]*13
for i in d:
    h[i] += 1

# 1~11時までの11通りを左右に振る
# 2以上の時の処理が面倒だから再帰で書く
ans = 0
def rec(now, state):
    global ans
    if now == 13:
        state.sort()
        m = float("Inf")
        for i in range(len(state)):
            m = min(m, abs(state[i-1]-state[i]))
        ans = max(ans, m)
    elif now == 0:
        if h[now]:
            return
        rec(now+1, state)
    elif now == 12:
        if h[now]==0:
            rec(now+1, state)
        elif h[now]==1:
            state.append(now)
            rec(now+1, state)
    else:
        if h[now]==0:
            rec(now+1, state)
        elif h[now]==1:
            s = state[:]
            s.append(now)
            rec(now+1,s)
            s = state[:]
            s.append(24-now)
            rec(now+1, s)
        elif h[now]==2:
            state.append(now)
            state.append(24-now)
            rec(now+1, state)
rec(0, [])
print(ans)

Submission status: Wrong Answer

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

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

def minGap(h):
    ret = float('inf')
    for i in range(len(h)):
        for j in range(i + 1, len(h)):
            hi, hj = h[i] - min(h[i], h[j]), h[j] - min(h[i], h[j])
            gap = max(hi, hj)
            ret = min(ret, gap, 24 - gap)
    return ret

ans = 0

hour = [0, D[0]]
for d in D[1:]:
    back = minGap(hour + [d])
    front = minGap(hour + [24 - d])
    if back > front:
        hour += [d]
    else:
        hour += [24 - d]
ans = max(ans, minGap(hour))

hour = [0, 24 - D[0]]
for d in D[1:]:
    back = minGap(hour + [d])
    front = minGap(hour + [24 - d])
    if back > front:
        hour += [d]
    else:
        hour += [24 - d]
ans = max(ans, minGap(hour))

print(ans)

Submission status: Wrong Answer

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

def minGap(h):
    ret = float('inf')
    for i in range(len(h)):
        for j in range(i + 1, len(h)):
            hi, hj = h[i] - min(h[i], h[j]), h[j] - min(h[i], h[j])
            gap = max(hi, hj)
            ret = min(ret, gap, 24 - gap)
    return ret

ans = 0

hour = [0, D[0]]
for d in D[1:]:
    back = minGap(hour + [d])
    front = minGap(hour + [24 - d])
    if back > front:
        hour += [d]
    else:
        hour += [24 - d]
ans = max(ans, minGap(hour))

hour = [0, 24 - D[0]]
for d in D[1:]:
    back = minGap(hour + [d])
    front = minGap(hour + [24 - d])
    if back > front:
        hour += [d]
    else:
        hour += [24 - d]
ans = max(ans, minGap(hour))

print(ans)

Submission status: Wrong Answer

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

hour = [0]

def minGap(h):
    ret = float('inf')
    for i in range(len(h)):
        for j in range(i + 1, len(h)):
            hi, hj = h[i] - min(h[i], h[j]), h[j] - min(h[i], h[j])
            gap = max(hi, hj)
            ret = min(ret, gap, 24 - gap)
    return ret

for d in D:
    back = minGap(hour + [d])
    front = minGap(hour + [24 - d])
    if back > front:
        hour += [d]
    else:
        hour += [24 - d]

print(minGap(hour))

Submission status: Wrong Answer

Solution code:
e=enumerate
n,*d=map(int,open(0).read().split())
d.sort()
for i in range(12,-1,-1):
  b=[0]+d[:]
  for j,(t,u)in enumerate(zip(b,b[1:]),1):
    if u-t<i:
      if t<1or abs(24-u-t)<i:break
      b[j]=24-u
  else:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
e=enumerate
n,*d=map(int,open(0).read().split())
d.sort()
for i in range(12,-1,-1):
  b=[0]+d[:]
  for j,(t,u)in enumerate(zip(b,b[1:]),1):
    if u-t<i:
      if t<1or 24-u-t<i:break
      b[j]=24-u
  else:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
e=enumerate
n,*d=map(int,open(0).read().split())
d.sort()
for i in range(24,-1,-1):
  b=[0]+d[:]
  for j,(t,u)in enumerate(zip(b,b[1:]),1):
    if abs(u-t)<i:
      if t<1or abs(24-u-t)<i:break
      b[j]=24-u
  else:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
e=enumerate
n,*d=map(int,open(0).read().split())
d.sort()
for i in range(12,-1,-1):
  b=[0]+d[:]
  for j,(t,u)in enumerate(zip(b,b[1:]),1):
    if abs(u-t)<i:
      if t<1or abs(24-u-t)<i:break
      b[j]=24-u
  else:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
e=enumerate
n,*d=map(int,open(0).read().split())
for i in range(12,-1,-1):
  b=[0]+d[:]
  for j,(t,u)in enumerate(zip(b,b[1:]),1):
    if abs(u-t)<i:
      if t<1or abs(24-u-t)<i:break
      b[j]=24-u
  else:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
e=enumerate
n,*d=map(int,open(0).read().split())
d.sort()
for i in range(12,-1,-1):
  b=[0]+d[:]
  for j,t in enumerate(b,1):
    for k,u in enumerate(b[j:],j):
      if abs(u-t)<i:
        if t<1or abs(24-u-t)<i:break
        b[k]=24-u
    else:continue
    break
  else:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
e=enumerate
n,*d=map(int,open(0).read().split()) 
for i in range(12,-1,-1):
  b=[0]+d[:]
  for j,t in enumerate(b,1):
    for k,u in enumerate(b[j:],j):
      if abs(u-t)<i:
        if t<1or abs(24-u-t)<i:break
        b[k]=24-u
    else:continue
    break
  else:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
e=enumerate
n,*d=map(int,open(0).read().split()) 
d.sort()
for i in range(12,-1,-1):
  b=[0]+d[:]
  for j,t in enumerate(b,1):
    for k,u in enumerate(b[j:],j):
      if abs(u-t)<i:
        if t+u<1or abs(24-u-t)<i:break
        b[k]=24-u
    else:continue
    break
  else:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
e=enumerate
n,*d=map(int,open(0).read().split())
for i in range(12,-1,-1):
  b=[0]+d[:]
  for j,t in enumerate(b,1):
    for k,u in enumerate(b[j:],j):
      if abs(u-t)<i:
        if t+u<1or abs(24-u-t)<i:break
        b[k]=24-u
    else:continue
    break
  else:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
e=enumerate
n,*d=map(int,open(0).read().split())
for i in range(12,-1,-1):
  b=[0]+d[:]
  for j,t in enumerate(b,1):
    for k,u in enumerate(b[j:],j):
      if abs(u-t)<i:
        if u<1or abs(24-u-t)<i:break
        b[k]=24-u
    else:continue
    break
  else:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [int(i) for i in input().split()]
ans = []
for i in range(2 ** n):
    dd = [0]
    k = (n - len(bin(i)[2:])) * "0" + bin(i)[2:]
    for j, kk in enumerate(k):
        if kk == "1":
            dd.append(24 - d[j])
        else:
            dd.append(d[j])
    dd.sort()
    ddd = [min(abs(dd[i + 1] - dd[i]), abs(24 - dd[i + 1] + dd[i])) for i in range(n)]
    ddd.append(min(abs(dd[0] - dd[-1]), abs(24 - dd[0] + dd[-1])))
    ans.append(min(ddd))
print(max(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
li = [0]+[int(x) for x in input().split()]
li.sort(reverse=True)
print(max(li[0]-li[1],24-li[1]-li[0]))

Submission status: Wrong Answer

Solution code:
N = int(input())
li = [0]+[int(x) for x in input().split()]
li.sort(reverse=True)
print(min(li[0]-li[1],24-li[1]-li[0]))

Submission status: Wrong Answer

Solution code:
#C問題
N = int(input())
D = list(map(int,input().split()))

D.sort()
left = 0
flag = 0
cir = [0 for i in range(24)]
for i in range(N):
    if D[i] == 0 or D[i] == 12:
        cir[D[i]] += 1
        if cir[D[i]] == 2:
            flag = 1
            break
    else:
        if left == 0:
            cir[D[i]]+=1
            left = 1
            if cir[D[i]] == 2:
                flag = 1
                break
        else:
            cir[24-D[i]]+=1
            left = 0
            if cir[24-D[i]] == 2:
                flag = 1
                break
                
if flag == 1:
    print(0)
else:
    MIN = 12
    point = [0]
    for i in range(24):
        if cir[i] == 1:
            point.append(i)
            if len(point) == 2:
                memo = i
    point.append(memo)
    #print(point)
    for i in range(len(point)-1):
        MIN = min(MIN,abs(point[i+1]-point[i]))
    print(MIN)

Submission status: Wrong Answer

Solution code:
#C問題
N = int(input())
D = list(map(int,input().split()))

D.sort()
left = 0
flag = 0
cir = [0 for i in range(24)]
for i in range(N):
    if D[i] == 0 or D[i] == 12:
        cir[D[i]] += 1
        if cir[D[i]] == 2:
            flag = 1
            break
    else:
        if left == 0:
            cir[D[i]]+=1
            left = 1
            if cir[D[i]] == 2:
                flag = 1
                break
        else:
            cir[24-D[i]]+=1
            left = 0
            if cir[24-D[i]] == 2:
                flag = 1
                break
                
if flag == 1:
    print(0)
else:
    MIN = 12
    point = []
    for i in range(24):
        if cir[i] == 1:
            point.append(i)
            if len(point) == 1:
                memo = i
    point.append(memo)
    #print(point)
    for i in range(len(point)-1):
        MIN = min(MIN,abs(point[i+1]-point[i]))
    print(MIN)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
d = wi()

time = [[] for _ in range(13)]

for t in d:
    if t <= 12:
        time[t].append(t)
    else:
        time[24 - t].append(t)

for idx, kosu in enumerate(time):
    if len(kosu) >= 3:
        print(0)
        exit()
    if len(kosu) == 2:
        time[idx] = [idx, 24 - idx]

if len(d) > 11:
    print(1)
    exit()

time = functools.reduce(lambda a, b: a + b, time)
ans = INF; A = 0

for ti in itertools.product([0, 1], repeat=len(time)):#3**2
    kyu = []
    for kk in range(len(ti)):
        if ti[kk] == 0:
            kyu.append(time[kk])
        else:
            kyu.append(24 - time[kk])
    kyu.append(0)

    for k in itertools.combinations(kyu, 2):
        ans = min(ans, abs(k[0] - k[1]), 24 - abs(k[0] - k[1]))
    A = max(ans, A)
    ans = INF  # 初期化を忘れない
print(A)

Submission status: Wrong Answer

Solution code:
s=[0]*25
s[11]=1
n=int(input())
a=list(map(int,input().split()))
d=[a.count(i)for i in range(13)]
d[0]+=1
if max(d[0],d[12])<2 and max(d[1:-1])<3:
    if d[12]==1:
        s[0]=1
        s[-1]=1
    t=[]
    for i in range(1,12):
        if d[i]==2:
            s[12-i]=1
            s[12+i]=1
        elif d[i]==1:
            t.append(i)
    k=0
    for i in range(2**len(t)):
        p=bin(i)[2:]
        p="0"*(len(t)-len(p))+p
        r=s[:]
        for j in range(len(t)):
            if p[j]=="0":
                r[12-t[j]]=1
            else:
                r[12+t[j]]=1
        r=r+r[1:]
        h=0
        q=0
        ans=30
        for j in r:
            if j==1:
                if h==0:
                    q=1
                    h=1
                else:
                    ans=min(q,ans)
                    q=1
            else:
                q+=1
        k=max(ans,k)
    print(k)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
s=[0]*25
s[11]=1
n=int(input())
a=list(map(int,input().split()))
d=[a.count(i)for i in range(13)]
if max(d[0],d[12])<2 and max(d[1:-1])<3:
    if d[12]==1:
        s[0]=1
        s[-1]=1
    t=[]
    for i in range(1,12):
        if d[i]==2:
            s[12-i]=1
            s[12+i]=1
        elif d[i]==1:
            t.append(i)
    k=0
    for i in range(2**len(t)):
        p=bin(i)[2:]
        p="0"*(len(t)-len(p))+p
        r=s[:]
        for j in range(len(t)):
            if p[j]=="0":
                r[12-t[j]]=1
            else:
                r[12+t[j]]=1
        r=r+r[1:]
        h=0
        q=0
        ans=30
        for j in r:
            if j==1:
                if h==0:
                    q=1
                    h=1
                else:
                    ans=min(q,ans)
                    q=1
            else:
                q+=1
        k=max(ans,k)
    print(k)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
s=[0]*25
s[11]=1
d=[0]*13
n=int(input())
a=list(map(int,input().split()))
d=[a.count(i)for i in range(13)]
if max(d[0],d[12])<2 and max(d[1:12])<3:
    if d[12]==1:
        s[0]=1
        s[-1]=1
    t=[]
    for i in range(1,12):
        if d[i]==2:
            s[12-i]=1
            s[12+i]=1
        elif d[i]==1:
            t.append(i)
    k=0
    for i in range(2**len(t)):
        p=bin(i)[2:]
        p="0"*(len(t)-len(p))+p
        r=s[:]
        for j in range(len(t)):
            if p[j]=="0":
                r[12-t[j]]=1
            else:
                r[12+t[j]]=1
        r=2*r
        h=0
        q=0
        ans=0
        for j in r:
            if j==1:
                if h==0:
                    q=1
                    h=1
                else:
                    ans=min(q,ans)
                    q=1
            else:
                q+=1
        k=max(ans,k)
    print(k)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
s=[0]*25
s[11]=1
d=[0]*13
n=int(input())
a=list(map(int,input().split()))
d=[a.count(i)for i in range(13)]
if max(d[0],d[12])<2 and max(d[1:12])<3:
    if d[12]==1:
        s[0]=1
        s[-1]=1
    t=[]
    for i in range(1,12):
        if d[i]==2:
            s[12-i]=1
            s[12+i]=1
        elif d[i]==1:
            t.append(i)
    k=0
    for i in range(2**len(t)):
        p=bin(i)[2:]
        p="0"*(len(t)-len(p))+p
        r=s[:]
        for j in range(len(t)):
            if p[j]=="0":
                r[12-t[j]]=1
            else:
                r[12+t[j]]=1
        r=2*r
        h=0
        q=0
        ans=0
        for j in r:
            if j==1:
                if h==0:
                    q=0
                    h=1
                else:
                    ans=min(q,ans)
                    q=0
            else:
                q+=1
        k=max(ans,k)
    print(k)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=[int(i) for i in input().split()]
d.sort()
a=1
ans=[]

def dif(lout,lin):
    lo=[i for i in lout]
    li=[i for i in lin]
    if li:
        x=li.pop()
        if x in li:
            li.remove(x)
            lo.append(x)
            lo.append(24-x)
            dif(lo,li)
        else:
            dif(lo+[x],li)
            dif(lo+[24-x],li)
    else:
        pre=0
        rt=24
        lo.sort()
        for i in lo:
            rt=min(i-pre,rt)
            pre=i
        ans.append(abs(rt))
        return

for i in range(12+1):
    if d.count(i)>2:
        a=0
if 0 in d:
    a=0
if d.count(12)>=2:
    a=0

if a==0:
    print(0)
else:
    dif([],d)
    print(max(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
d=[int(i) for i in input().split()]
d.sort()
a=1

def dif(lo,li):
    #print(lo,li)
    if li:
        x=li.pop()
        if x in li:
            li.remove(x)
            lo.append(x)
            lo.append(24-x)
            return dif(lo,li)
        else:
            return max(dif(lo+[x],li), dif(lo+[24-x],li))
    else:
        pre=0
        rt=24
        for i in lo:
            rt=min(i-pre,rt)
            pre=i
        return abs(rt)

for i in range(12+1):
    if d.count(i)>2:
        a=0
if 0 in d:
    a=0
if d.count(12)>=2:
    a=0

if a==0:
    print(0)
else:
    ans=dif([],d)
    print(ans)