Problem:


A : Soccer / サッカー

問題文

A国とB国の間でAIサッカーの試合をした。あなたの手元には、ある時刻にボールを持っていた選手とその位置を記録した表がある。表は N 行からなり、上から i 番目の行は次に示す要素からなる。

フレーム数 f_i

ボールを持っている選手の背番号 a_i

その選手が属するチーム t_i

その選手の位置を表す座標 x_i , y_i

フレーム数とは、ゲームの開始時刻に 0 に設定され、 1/60 秒ごとに 1 加算される整数のことである。例えば、ゲーム開始からちょうど 1.5 秒後のフレーム数は 90 である。 背番号は各チーム内の 11 人の選手に一意にふられる整数である。さらに、表中の連続する 2 つの記録において、同じチームの異なる背番号の選手がボールを持っているとき、その間に「パス」が行われたとする。記録に存在しないフレームは考慮しなくてよい。

さて、エンジニアであるあなたの仕事は、各チームの選手間で行われたパスのうち、 最も距離(ユークリッド距離)が長いものの距離と、それにかかった時間を求めることである。 距離が最長となるパスが複数ある場合は、かかった時間が最も短いものを出力せよ。

入力

入力は以下の形式で与えられる。t_i=0 のときA国、 t_i=1 のときB国を表す。

N
f_0 a_0 t_0 x_0 y_0
…
f_{N&minus;1} a_{N&minus;1} t_{N&minus;1} x_{N&minus;1} y_{N&minus;1}

制約

入力はすべて整数である

1 \≤ N \≤ 100

0 \≤ f_i \lt f_{i+1} \≤ 324\,000

 1 \≤ a_i \≤ 11

 t_i = 0,1

 0 \≤ x_i \≤ 120

 0 \≤ y_i \≤ 90

出力

A国の最長のパスにかかった距離と時間、B国の最長のパスにかかった距離と時間を、それぞれ1行に出力せよ。時間は秒単位とし、距離、時間ともに 10^{&minus;3} 以下の絶対誤差は許される。パスが一度も行われなかった場合はともに &minus;1 と出力せよ。

サンプル

サンプル入力1

5
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2

サンプル出力1

5.00000000 1.00000000
1.41421356 0.20000000

A国は長さ 5 のパスを 30 フレームの時刻に 60 フレーム =1 秒でし、B国は長さ √2 のパスを 120 フレームの時刻に 12 フレーム =0.2 秒でした。これらがそれぞれの最長のパスである。

サンプル入力2

2
0 1 0 0 0
10 1 1 0 0

サンプル出力2

-1 -1
-1 -1

サンプル入力3

3
0 1 0 0 0
30 2 0 1 1
40 1 0 2 2

サンプル出力3

1.4142135624 0.1666666667
-1 -1

サンプル入力4

3
0 1 0 0 0
10 2 0 1 1
40 1 0 3 3

サンプル出力4

2.8284271247 0.5000000000
-1 -1



Sample input:
5
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2


Sample output:
5.00000000 1.00000000
1.41421356 0.20000000

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
ball = [[0,0,0,0],[0,0,0,0]]
ans = [[-1,-1],[-1,-1]]
for loop in xrange(N):
    f,a,t,x,y = map(int,raw_input().split())
    if ball[t][0] != 0 and ball[t][0] != a :
        bf,bx,by = ball[t][1:]
        dist = (x-bx)**2+(y-by)**2
        if dist > ans[t][0]:
            ans[t] = [dist,(f-bf)/60.0]
        elif dist == ans[t][0]:
            ans[t] = [dist,min(ans[t][1], (f-bf)/60.0)]
        ball[t] = [a,f,x,y]
    else:
        ball[t] = [a,f,x,y]

if ans[0][0] == -1:
    print -1,-1
else:
    print "%.6f %.6f"%(ans[0][0]**0.5,ans[0][1])
if ans[1][0] == -1:
    print -1,-1
else:
    print "%.6f %.6f"%(ans[1][0]**0.5,ans[1][1])

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
ball = [[0,0,0,0],[0,0,0,0]]
ans = [[-1,-1],[-1,-1]]
for loop in xrange(N):
    f,a,t,x,y = map(int,raw_input().split())
    if ball[t][0] != 0 and ball[t][0] != a :
        bf,bx,by = ball[t][1:]
        dist = (x-bx)**2+(y-by)**2
        if   dist  > ans[t][0]:
            ans[t] = [dist,(f-bf)/60.0]
        elif dist == ans[t][0]:
            ans[t][1] = min(ans[t][1], (f-bf)/60.0)
            
    ball[t] = [a,f,x,y]

if ans[0][0] == -1:
    print -1,-1
else:
    print "%.6f %.6f"%(ans[0][0]**0.5,ans[0][1])
if ans[1][0] == -1:
    print -1,-1
else:
    print "%.6f %.6f"%(ans[1][0]**0.5,ans[1][1])

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
last = [-1] * 5
At = -1
Al = -1
Bt = -1
Bl = -1

for _ in range(n):
    
    l = list(map(int, input().split()))
    if last[2] != l[2] or last[1] == -1 or last[1] == l[1]:
        last = l
    elif last[1] != l[1]:
        len=math.sqrt((last[3] - l[3])**2 + (last[4] - l[4])**2)
        tim= l[0] -last[0]
        if l[2] == 0:
            if At < tim: At = tim
            if Al < len: Al = len
        elif l[2] == 1:
            if Bt < tim: Bt = tim
            if Bl < len: Bl = len

print("{0:.8f}".format(Al), end = " ")
print("{0:.8f}".format(At/60))
print("{0:.8f}".format(Bl), end = " ")
print("{0:.8f}".format(Bt/60))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
last = [-1] * 5
At = -1
Al = -1
Bt = -1
Bl = -1

for _ in range(n):
    
    l = list(map(int, input().split()))
    if last[2] != l[2] or last[1] == -1 or last[1] == l[1]:
        last = l
    elif last[1] != l[1]:
        len=math.sqrt((last[3] - l[3])**2 + (last[4] - l[4])**2)
        tim= l[0] -last[0]
        if l[2] == 0:
            if At < tim: At = tim
            if Al < len: Al = len
        elif l[2] == 1:
            if Bt < tim: Bt = tim
            if Bl < len: Bl = len

if Al != -1:
    print("{0:.8f}".format(Al), end = " ")
    print("{0:.8f}".format(At/60))
else:
    print("-1 -1")
if Bl != -1:
    print("{0:.8f}".format(Bl), end = " ")
    print("{0:.8f}".format(Bt/60))
else:
    print("-1 -1")

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
last = [-1] * 5
At = -1
Al = -1
Bt = -1
Bl = -1

for _ in range(n):
    
    l = list(map(int, input().split()))
    if last[2] != l[2] or last[1] == -1 or last[1] == l[1]:
        last = l
    elif last[1] != l[1]:
        len=math.sqrt((last[3] - l[3])**2 + (last[4] - l[4])**2)
        tim= l[0] - last[0]
        if l[2] == 0:
            if At < tim: At = tim
            if Al < len: Al = len
        elif l[2] == 1:
            if Bt < tim: Bt = tim
            if Bl < len: Bl = len
    last = l

if Al != -1:
    print("{0:.10f}".format(Al), end = " ")
    print("{0:.10f}".format(At/60))
else:
    print("-1 -1")
if Bl != -1:
    print("{0:.10f}".format(Bl), end = " ")
    print("{0:.10f}".format(Bt/60))
else:
    print("-1 -1")

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
last = [-1] * 5
At = -1
Al = -1
Bt = -1
Bl = -1

for _ in range(n):
    
    l = list(map(int, input().split()))
    if last[2] != l[2] or last[1] == -1 or last[1] == l[1]:
        last = l
    elif last[1] != l[1]:
        len=math.sqrt((last[3] - l[3])**2 + (last[4] - l[4])**2)
        tim= l[0] - last[0]
        if l[2] == 0:
            if At < tim: At = tim
            if Al < len: Al = len
        elif l[2] == 1:
            if Bt < tim: Bt = tim
            if Bl < len: Bl = len
    last = l

if Al != -1:
    print("{}".format(Al), end = " ")
    print("{}".format(At/60))
else:
    print("-1 -1")
if Bl != -1:
    print("{}".format(Bl), end = " ")
    print("{}".format(Bt/60))
else:
    print("-1 -1")

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
last = [-1] * 5
At = -1
Al = -1
Bt = -1
Bl = -1

for _ in range(n):
    
    l = list(map(int, input().split()))
    if last[2] != l[2] or last[1] == -1 or last[1] == l[1]:
        last = l
    elif last[1] != l[1]:
        len=math.sqrt((last[3] - l[3])**2 + (last[4] - l[4])**2)
        tim= l[0] - last[0]
        if l[2] == 0:
            if At < tim: At = tim
            if Al < len: Al = len
        elif l[2] == 1:
            if Bt < tim: Bt = tim
            if Bl < len: Bl = len
    last = l

if Al != -1:
    print("{0:.10f}".format(round(Al,10)), end = " ")
    print("{0:.10f}".format(round(At/60),10))
else:
    print("-1 -1")
if Bl != -1:
    print("{0:.10f}".format(round(Bl,10)), end = " ")
    print("{0:.10f}".format(round(Bt/60),10))
else:
    print("-1 -1")

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
last = [-1] * 5
At = -1
Al = -1
Bt = -1
Bl = -1

for _ in range(n):
    
    l = list(map(int, input().split()))
    if last[2] != l[2] or last[1] == -1 or last[1] == l[1]:
        last = l
    elif last[1] != l[1]:
        len=math.sqrt((last[3] - l[3])**2 + (last[4] - l[4])**2)
        tim= l[0] - last[0]
        if l[2] == 0:
            if Al <= len:
                Al = len
                At = tim
        elif l[2] == 1:
            if Bl <= len:
                Bl = len
                Bl = tim
    last = l

if Al != -1:
    print("{0:.10f}".format(round(Al,10)), end = " ")
    print("{0:.10f}".format(At/60))
else:
    print("-1 -1")
if Bl != -1:
    print("{0:.10f}".format(round(Bl,10)), end = " ")
    print("{0:.10f}".format(Bt/60))
else:
    print("-1 -1")

Submission status: Accepted

Solution code:
import math

n = int(input())

prev = list(map(int, input().split()))
max_disA = -1
max_disB = -1
min_timeA = 10**9
min_timeB = 10**9

for _ in range(n-1):
    curr = list(map(int, input().split()))
    if prev[1] != curr[1] and prev[2] == curr[2]:
        dis = math.sqrt((prev[3] - curr[3])**2 + (prev[4] - curr[4])**2)
        if max_disA < dis and prev[2] == 0:
            max_disA = dis
            min_timeA = curr[0] - prev[0]
        elif max_disB < dis and prev[2] == 1:
            max_disB = dis
            min_timeB = curr[0] - prev[0]
        elif dis == max_disA and prev[2] == 0 and min_timeA > curr[0] - prev[0]:
            max_disA = dis
            min_timeA = curr[0] - prev[0]
        elif dis == max_disB and prev[2] == 0 and min_timeB > curr[0] - prev[0]:
            max_disB = dis
            min_timeB = curr[0] - prev[0]
    prev = curr

if max_disA == -1:
    print(-1, -1)
else:
    print(max_disA, min_timeA / 60)

if max_disB == -1:
    print(-1, -1)
else:
    print(max_disB, min_timeB / 60)

Submission status: Accepted

Solution code:
import math

n = int(input())

prev = list(map(int, input().split()))
max_disA = -1
max_disB = -1
min_timeA = 10**9
min_timeB = 10**9

for _ in range(n-1):
    curr = list(map(int, input().split()))
    if prev[1] != curr[1] and prev[2] == curr[2]:
        dis = math.sqrt((prev[3] - curr[3])**2 + (prev[4] - curr[4])**2)
        if max_disA < dis and prev[2] == 0:
            max_disA = dis
            min_timeA = curr[0] - prev[0]
        elif max_disB < dis and prev[2] == 1:
            max_disB = dis
            min_timeB = curr[0] - prev[0]
        elif dis == max_disA and prev[2] == 0 and min_timeA > curr[0] - prev[0]:
            max_disA = dis
            min_timeA = curr[0] - prev[0]
        elif dis == max_disB and prev[2] == 1 and min_timeB > curr[0] - prev[0]:
            max_disB = dis
            min_timeB = curr[0] - prev[0]
    prev = curr

if max_disA == -1:
    print(-1, -1)
else:
    print(max_disA, min_timeA / 60)

if max_disB == -1:
    print(-1, -1)
else:
    print(max_disB, min_timeB / 60)

Submission status: Accepted

Solution code:
N = int(raw_input())
#ball[t] = [f,a,x,y]
ball = [[0,0,0,0],[0,0,0,0]]
#ans[t] = [dist,flame]
ans = [[-1,-1],[-1,-1]]
bt = -1
for loop in xrange(N):
    f,a,t,x,y = map(int,raw_input().split())
    if bt == t and ball[t][0] != a :
        bf,bx,by = ball[t][1:]
        dist = (x-bx)**2+(y-by)**2
        if   dist  > ans[t][0]:
            ans[t] = [dist,f-bf]
        elif dist == ans[t][0]:
            ans[t][1] = min(ans[t][1], f-bf)
            
    ball[t] = [a,f,x,y]
    bt = t

if ans[0][0] == -1:
    print -1,-1
else:
    print "%.6f %.6f"%(ans[0][0]**0.5,ans[0][1]/60.0)
if ans[1][0] == -1:
    print -1,-1
else:
    print "%.6f %.6f"%(ans[1][0]**0.5,ans[1][1]/60.0)

Submission status: Accepted

Solution code:
import math
n = int(input())
last = [-1] * 5
At = -1
Al = -1
Bt = -1
Bl = -1

for _ in range(n):
    
    l = list(map(int, input().split()))
    if last[2] != l[2] or last[1] == -1 or last[1] == l[1]:
        last = l
    elif last[1] != l[1]:
        len=math.sqrt((last[3] - l[3])**2 + (last[4] - l[4])**2)
        tim= l[0] - last[0]
        if l[2] == 0:
            if Al <= len:
                Al = len
                At = tim
        elif l[2] == 1:
            if Bl <= len:
                Bl = len
                Bt = tim
    last = l

if Al != -1:
    print("{0:.10f}".format(round(Al,10)), end = " ")
    print("{0:.10f}".format(At/60))
else:
    print("-1 -1")
if Bl != -1:
    print("{0:.10f}".format(round(Bl,10)), end = " ")
    print("{0:.10f}".format(Bt/60))
else:
    print("-1 -1")

Submission status: Accepted

Solution code:
N  = int(input())

data = [list(map(int,input().split())) for _ in range(N)]
team = data[0][2]
player = data[0][1]
t1 = 0
t2 = 0
f1 = 0
f2 = 0
for i in range(1,N):
    if data[i][2] == team:
        if data[i][1] != player:
            if team == 0:
                if t1 < ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2):
                    t1 = ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2)
                    f1 = (data[i][0]- data[i-1][0])/60
                if t1 == ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2):
                    if f1 > (data[i][0]- data[i-1][0])/60:
                        f1 = (data[i][0]- data[i-1][0])/60
            if team == 1:
                if t2 < ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2):
                    t2 = ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2)
                    f2 = (data[i][0] - data[i-1][0])/60
                if t2 == ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2):
                    if f2 > (data[i][0]- data[i-1][0])/60:
                        f2 = (data[i][0]- data[i-1][0])/60
    player = data[i][1]
    team = data[i][2]
if t1 == 0 :
    print(-1,-1)
else:
    print(t1,f1)
if t2 == 0:
    print(-1,-1)
else:
    print(t2,f2)