Problem:


路線バスの時刻表

バスマニアの健次郎君は、Ａ市内のバスをよく利用しています。ある日ふと、健次郎君の家の前のバス停から出発するすべてのバスを写真に収めることを思い立ちました。このバス停には飯盛山行きと鶴ケ城行きの２つのバス路線が通ります。各路線の時刻表は手に入れましたが、１つの時刻表としてまとめた方がバス停で写真が撮りやすくなります。

健次郎君を助けるために、２つの路線の時刻表を、０時０分を基準として出発時刻が早い順に１つの時刻表としてまとめるプログラムを作成してください。

入力

入力は以下の形式で与えられる。

N h1 m1 h2 m2 ... hN mN
M k1 g1 k2 g2 ... kM gM

１行目に、飯盛山行きのバスの数を表す整数 N (1 ≤ N ≤ 100) と、それに続いて飯盛山行きのバス出発時刻が早い順に与えられる。出発時刻は整数 hi (0 ≤ hi ≤ 23) と mi (0 ≤ mi ≤ 59) からなり、hi 時 mi 分に i 番目のバスが出発することを表す。２行目に、鶴ケ城行きのバスの数を表す整数 M (1 ≤ M ≤ 100) と、それに続いて鶴ケ城行きのバス出発時刻が早い順に与えられる。出発時刻は整数 ki (0 ≤ ki ≤ 23) と gi (0 ≤ gi ≤ 59) からなり、ki 時 gi 分に i 番目のバスが出発することを表す。同じ路線には、同じ時刻に出発するバスはないものとする。

出力

２つの路線の時刻表を、０時０分を基準として出発時刻が早い順に１つにまとめた時刻表を１行に出力する。ただし、同じ時刻に複数のバスが出発するときは１つだけを出力する。出発時刻の時と分を : で区切る。分が１桁のときは左に０をひとつ加えて２桁で出力する。時刻と時刻の間は空白1 つで区切る。

入出力例

入力例１ 

2 9 8 15 59
1 8 27

出力例１

8:27 9:08 15:59

入力例２ 

2 0 0 21 0
3 7 30 21 0 23 7

出力例２

0:00 7:30 21:00 23:07



Sample input:
2 9 8 15 59
1 8 27


Sample output:
8:27 9:08 15:59

Submission status: Wrong Answer

Solution code:
hm = map(int,raw_input().split())[1:] + map(int,raw_input().split())[1:]
hm = [[hm[i],hm[i+1]] for i in xrange(0,len(hm),2)]
hm = sorted(sorted(hm, key = lambda x:x[1]))
print " ".join("%d:%02d"%(h,m) for h,m in hm)

Submission status: Wrong Answer

Solution code:
a = map(int,raw_input().split())[1:] + map(int,raw_input().split())[1:]
a = sorted([60*a[i]+a[i+1] for i in xrange(0,len(a),2)])
print " ".join("%d:%02d"%(ai/60,ai%60) for ai in a)

Submission status: Wrong Answer

Solution code:
v = []
for i in range(2):
    x = list(map(int, input().split()))
    N, x = x[0], x[1:]
    for j in range(N):
        v.append(x[j * 2] * 60 + x[j * 2 + 1])
for i in sorted(set(v)):
    print("{0}:{1:02d}".format(i // 60, i % 60))

Submission status: Wrong Answer

Solution code:
t = []
a = map(int, raw_input().split())
n = a[0]
for i in xrange(n):
    t.append(a[2*i+1]*60+a[2*i+2])
for time in t:
    print time
b = map(int, raw_input().split())
n = b[0]
for i in xrange(n):
    t.append(b[2*i+1]*60+b[2*i+2])
t.sort()
print " ".join(":".join([str(time/60).zfill(2),str(time%60).zfill(2)]) for time in t)

Submission status: Wrong Answer

Solution code:
t = []
a = map(int, raw_input().split())
n = a[0]
for i in xrange(n):
    t.append(a[2*i+1]*60+a[2*i+2])
b = map(int, raw_input().split())
n = b[0]
for i in xrange(n):
    t.append(b[2*i+1]*60+b[2*i+2])
t.sort()
print " ".join(":".join([str(time/60).zfill(2),str(time%60).zfill(2)]) for time in t)

Submission status: Wrong Answer

Solution code:
t = []
a = map(int, raw_input().split())
n = a[0]
for i in xrange(n):
    t.append(a[2*i+1]*60+a[2*i+2])
b = map(int, raw_input().split())
n = b[0]
for i in xrange(n):
    t.append(b[2*i+1]*60+b[2*i+2])
t.sort()
print " ".join(":".join([str(time/60),str(time%60).zfill(2)]) for time in t)

Submission status: Wrong Answer

Solution code:
n, m, j = list(map(int,input().split())), list(map(int,input().split())), []
[j.append((n[2 * i + 1],n[2 * i + 2])) for i in range(n[0])]
[j.append((m[2 * i + 1],m[2 * i + 2])) for i in range(m[0])]
j.sort(key = lambda x:x[1])
j.sort(key = lambda x:x[0])
print(*["{0}:{1:02d}".format(i[0],i[1]) for i in j])

Submission status: Accepted

Solution code:
a = map(int,raw_input().split())[1:] + map(int,raw_input().split())[1:]
a = sorted(list(set([60*a[i]+a[i+1] for i in xrange(0,len(a),2)])))
print " ".join("%d:%02d"%(ai/60,ai%60) for ai in a)

Submission status: Accepted

Solution code:
import sys
import itertools
f = sys.stdin

nhm, mkg = [map(int, f.readline().split()) for _ in range(2)]
n = next(nhm)
m = next(mkg)

goto_iimoriyama = list(zip(*[nhm]*2))
goto_turugajyo = list(zip(*[mkg]*2))

mixed = sorted(list(set(goto_iimoriyama + goto_turugajyo)))

mixed = ['{}:{:02d}'.format(h, m) for h,m in mixed]
print(*mixed)

Submission status: Accepted

Solution code:
v = []
for i in range(2):
    x = list(map(int, input().split()))
    N, x = x[0], x[1:]
    for j in range(N):
        v.append(x[j * 2] * 60 + x[j * 2 + 1])
print(' '.join(['{0}:{1:02d}'.format(i // 60, i % 60) for i in sorted(set(v))]))

Submission status: Accepted

Solution code:
i1 = map(int, raw_input().split())
i2 = map(int, raw_input().split())
li = []
n1 = i1[0]; n2 = i2[0];
i = j = 0
while i<n1 and j<n2:
    l1 = (i1[2*i+1], i1[2*i+2])
    l2 = (i2[2*j+1], i2[2*j+2])
    if l1==l2:
        li.append(l1)
        i += 1; j += 1;
    elif l1<l2:
        li.append(l1)
        i += 1
    else:
        li.append(l2)
        j += 1
while i<n1:
    li.append((i1[2*i+1], i1[2*i+2]))
    i += 1
while j<n2:
    li.append((i2[2*j+1], i2[2*j+2]))
    j += 1
print ' '.join(map(lambda x: "%d:%02d"%x, li))

Submission status: Accepted

Solution code:
t = set([])
a = map(int, raw_input().split())
n = a[0]
for i in xrange(n):
    t.add(a[2*i+1]*60+a[2*i+2])
b = map(int, raw_input().split())
n = b[0]
for i in xrange(n):
    t.add(b[2*i+1]*60+b[2*i+2])
tl = []
tl = list(t)
tl.sort()
print " ".join(":".join([str(time/60),str(time%60).zfill(2)]) for time in tl)

Submission status: Accepted

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0297

NIn = input()
N = int(NIn.split(" ")[0])
NTime = []
for i in range(N):
	NTime.append(int(NIn.split(" ")[(i + 1) * 2 - 1]) * 60 + int(NIn.split(" ")[(i + 1) * 2]))
#print(NTime)

MIn = input()
M = int(MIn.split(" ")[0])
MTime = []
for i in range(M):
	MTime.append(int(MIn.split(" ")[(i + 1) * 2 - 1]) * 60 + int(MIn.split(" ")[(i + 1) * 2]))
#print(MTime)

AllTime = NTime + MTime
AllTime = sorted(list(set(AllTime)))

AllTime2 = []
for i in range(len(AllTime)):
	hour = AllTime[i] // 60
	minute = AllTime[i] % 60
	if minute < 10:
		AllTime2.append(str(hour) + ":0" + str(minute))
	else:
		AllTime2.append(str(hour) + ":" + str(minute))
for i in range(len(AllTime2)):
	if i == 0:
		results = AllTime2[i]
	else:
		results += " " + AllTime2[i]
print(results)

Submission status: Accepted

Solution code:
ns = map(int, raw_input().split())
ms = map(int, raw_input().split())
dic = {}
N = ns[0]
M = ms[0]

for i in xrange(N):
  h = ns[i*2+1]
  m = ns[i*2+2]
  if h not in dic:
    dic[h] = {}
  dic[h][m] = True
for i in xrange(M):
  h = ms[i*2+1]
  m = ms[i*2+2]
  if h not in dic:
    dic[h] = {}
  dic[h][m] = True

ans = ""
for k,v in sorted(dic.items()):
  for t,a in sorted(v.items()):
    h = str(k)
    m = str(t)
    if t < 10:
      m = "0" + m
    ans += h + ":" + m + " "

print ans.rstrip()

Submission status: Accepted

Solution code:
t=[]
for _ in [0]*2:
    a=list(map(int,input().split()))
    for i in range(a[0]):
        t+=[a[i*2+1]*60+a[i*2+2]]
print(*['%d:%02d'%(x//60,x%60)for x in sorted(set(t))])

Submission status: Accepted

Solution code:
import sys

def main():
    n_s = list(map(int, input().split()))
    m_s = list(map(int, input().split()))

    timetable = {}
    for h, m in zip(n_s[1::2], n_s[2::2]):
        timetable['{0:2d}:{1:02d}'.format(h, m)] = '{0}:{1:02d}'.format(h, m)
    for k, g in zip(m_s[1::2], m_s[2::2]):
        timetable['{0:2d}:{1:02d}'.format(k, g)] = '{0}:{1:02d}'.format(k, g)

    keys = list(timetable.keys())
    keys.sort()
    print(" ".join([timetable[key] for key in keys]))

    return 0

if __name__ == '__main__':
    sys.exit(main())

Submission status: Accepted

Solution code:
n, m, j = list(map(int,input().split())), list(map(int,input().split())), set()
[j.add((n[2 * i + 1],n[2 * i + 2])) for i in range(n[0])]
[j.add((m[2 * i + 1],m[2 * i + 2])) for i in range(m[0])]
j = list(j)
j.sort(key = lambda x:x[1])
j.sort(key = lambda x:x[0])
print(*["{0}:{1:02d}".format(i[0],i[1]) for i in j])

Submission status: Accepted

Solution code:
# AOJ 0298: Bus Timetable
# Python3 2018.6.25 bal4u

tbl = set()
for i in range(2):
	t = list(map(int, input().split()))
	for j in range(1, 2*t[0], 2): tbl.add((t[j], t[j+1]))
print(*[("{}:{:02}".format(*i)) for i in sorted(tbl)])

Submission status: Accepted

Solution code:
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
agg = set()
for i in range(s1[0]):
  agg.add(tuple(s1[i * 2 + 1:i * 2 + 3]))
for i in range(s2[0]):
  agg.add(tuple(s2[i * 2 + 1:i * 2 + 3]))
agg = list(agg)
agg.sort()
print(*list(map(lambda t:str(t[0])+":"+str(t[1]).zfill(2), agg)))

Submission status: Accepted

Solution code:
tbl = set()
for i in range(2):
    c = [int(x) for x in input().split()]
    for hm in zip(c[1::2], c[2::2]):
        #print(hm)
        tbl.add((hm[0],hm[1]))

L = []
for h, m in sorted(tbl):
    L.append("{}:{:02d}".format(h,m))

print(*L)

Submission status: Accepted

Solution code:
I=list(map(int,input().split()))
T=list(map(int,input().split()))
N=I[0]
M=T[0]
I=[[I[i],I[i+1]] for i in range(1,2*N+1,2)]
T=[[T[i],T[i+1]] for i in range(1,2*M+1,2)]
result=list(map(list,set(map(tuple,I+T))))
result.sort()

print(str(result[0][0])+":"+'{0:02d}'.format(result[0][1]),end="")
for i in range(1,len(result)):
    print(" "+str(result[i][0])+":"+'{0:02d}'.format(result[i][1]),end="")
print()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

class Bustime:
    h = 0
    mm = 0
    t = 0
    def __init__(self, h, mm):
        self.h = h
        self.mm = mm
        self.t = h * 60 + mm
    def __str__(self):
        if self.mm < 10:
            return str(self.h) + ":0" + str(self.mm)
        else:
            return str(self.h) + ":" + str(self.mm)
    def __lt__(self, other):
        return self.t < other.t


line1 = [int(i) for i in input().split()]
line2 = [int(i) for i in input().split()]

times = []

for i in range(line1[0]):
    times.append(Bustime(line1[2*i + 1], line1[2*i + 2]))

for i in range(line2[0]):
    times.append(Bustime(line2[2*i + 1], line2[2*i + 2]))

times.sort()
prev = ""
flag = True
for i in range(len(times)):
    if prev != str(times[i]):
        if flag:
            print(times[i],end="")
            flag = False
        else:
            print(" " + str(times[i]),end="")
            
    prev = str(times[i])

print("")

Submission status: Accepted

Solution code:
import itertools as ite
import math

INF = 10 ** 18

ls = set()
ls1 = map(int, raw_input().split())
ls2 = map(int, raw_input().split())
for i in range(1, len(ls1), 2):
    h, m = ls1[i], ls1[i + 1]
    ls.add((h, m))
for i in range(1, len(ls2), 2):
    h, m = ls2[i], ls2[i + 1]
    ls.add((h, m))
ls = sorted(list(ls))
for i in range(len(ls)):
    h, m = ls[i]
    if m >= 10:
        ls[i] = str(h) + ":" + str(m)
    else:
        ls[i] = str(h) + ":0" + str(m)
print " ".join(ls)

Submission status: Accepted

Solution code:
bus = []
for i in range(2):
    l = list(map(int, input().split()))
    N = l[0]
    t = l[1:]
    for j in range(N):
        bus.append(t[j * 2] * 60 + t[j * 2 + 1])
print(' '.join(['{0}:{1:02d}'.format(i // 60, i % 60) for i in sorted(set(bus))]))

Submission status: Accepted

Solution code:
time=[]
n=list(map(int,input().split()))
for i in range(n[0]):
    keep=str(n[i*2+1]).zfill(2)+":"+str(n[i*2+2]).zfill(2)
    if not(keep in time):
        time.append(keep)
n=list(map(int,input().split()))
for i in range(n[0]):
    keep=str(n[i*2+1]).zfill(2)+":"+str(n[i*2+2]).zfill(2)
    if not(keep in time):
        time.append(keep)
time.sort()
for i,j in enumerate(time):
    if j[0]=="0":
        time[i]=j[1:]
    else:break
print(" ".join(time))

Submission status: Accepted

Solution code:
def unique(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


imori = list(map(int, input().split()))
n = imori.pop(0)
tsuru = list(map(int, input().split()))
m = tsuru.pop(0)

time = []
for _ in range(n):
    k = imori.pop(0)
    g = imori.pop(0)
    time.append([k, g])

for _ in range(m):
    k = tsuru.pop(0)
    g = tsuru.pop(0)
    time.append([k, g])

time = unique(time)
time = sorted(time, key=lambda x: (x[0], x[1]))
ans = []
for t in time:
    ans.append(str(t[0]) + ":" + str(t[1]).zfill(2))

print(' '.join(ans))