Problem:


Problem B: GPA JANKEN

Problem

GPAとは「Galaxy Point of Aizu」の略で、0から4までの実数値を取る。

GPAじゃんけんは二人で行うゲームである。各々が「じゃんけん、ぽん（ほい）」の合図で互いにグー、チョキ、パーのどれか好きな手を出した後、GPAが高い人が勝者となり、低い人が敗者となる。同じ場合は引き分けとなる。

N 人のGPAのデータが与えられるので、総当たり戦をした時のそれぞれの勝ち点を出力せよ。

ただし、勝ち点は勝ちの時3、引き分けの時1、負けの時0とする。

    総当たり戦とはすべての参加者が自分以外の参加者と丁度一回ずつ対戦する方式である。

Input

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

N
a1
a2
...
aN

一行目にGPAじゃんけんをする人数 N が与えられる。

    続く N 行に i 番目の人のGPAのデータ ai が一行に与えられる。

Constraints

入力は以下の条件を満たす。

    
2 ≤ N ≤ 105

    
N は整数

    
0.000 ≤ ai ≤ 4.000 ( 1 ≤ i ≤ N )

    
ai は実数 ( 1 ≤ i ≤ N )

    
各GPAは小数点以下3桁まで与えられる

Output

  i 行目に i 番目の人の勝ち点を一行に出力せよ。
  ( 1 ≤ i  ≤ N )

Sample Input 1

3
1.000
3.000
3.000

Sample Output 1

0
4
4

Sample Input 2

3
1.000
2.000
3.000

Sample Output 2

0
3
6



Sample input:
3
1.000
3.000
3.000


Sample output:
0
4
4

Submission status: Wrong Answer

Solution code:
n = int(input())
grade = [[] for i in range(4001)]
for i in range(n):
    gpa = float(input())
    grade[(int(gpa*1000))].append(i)
win = 0
point = [0]*n
for elm in grade:
    tie = len(elm)
    for p in elm:
        point[p] = win+tie-1
    win += 3*tie
for p in point:
    print(p)

Submission status: Wrong Answer

Solution code:
from math import factorial
from collections import defaultdict
from itertools import combinations, chain

def nC2(n):
    return factorial(n) // (factorial(2) * factorial(n-2))

def pairs(iterable):
    s = list(iterable)
    return combinations(s, 2)

N = int(input())

points = defaultdict(int)
for i in range(1, N+1):
    gpa = float(input())
    points[(i, gpa)]

battles = list(pairs(points))
for battle in battles:
    if (battle[0][1] > battle[1][1]):
        points[battle[0]] += 3
    elif (battle[0][1] < battle[1][1]):
        points[battle[1]] += 3
    else:
        points[battle[0]] += 1
        points[battle[1]] += 1
    # print(battle)

for info, point in points.items():
    print(point)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from itertools import combinations

'''
def nC2(n):
    return factorial(n) // (factorial(2) * factorial(n-2))
'''

def pairs(iterable):
    s = list(iterable)
    return combinations(s, 2)

N = int(input())

points = defaultdict(int)
for i in range(1, N+1):
    gpa = float(input())
    points[(i, gpa)]

battles = list(pairs(points))
for battle in battles:
    if (battle[0][1] > battle[1][1]):
        points[battle[0]] += 3
    elif (battle[0][1] < battle[1][1]):
        points[battle[1]] += 3
    else:
        points[battle[0]] += 1
        points[battle[1]] += 1
    # print(battle)

for info, point in points.items():
    print(point)

Submission status: Wrong Answer

Solution code:
n= int(input())
lis = [[float(input()), i] for i in range(n)]
lis.sort(key = lambda x: x[0])
ans = [[0,lis[0][1]] for i in range(n)]
i = 1
while i < n:
    if lis[i][0] != lis[i-1][0]:
        ans[i][0] += (ans[i-1][0] + 3)
        ans[i][1] = lis[i][1]
    else:
        k = ans[i-1][0]
        v = i-1
        while i < n:
            if lis[i][0] != lis[v][0]:
                break
            i += 1
        i -= 1
        ans[v][0] += (i-v)
        for j in range(v,i+1):
            ans[j][0] = ans[v][0]
            ans[j][1] = lis[j][1]
    i += 1
ans.sort(key = lambda x: x[1])
for i in ans:
    print(i[0])

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

N = int(input())
points = defaultdict(int)
gpas = list()

for i in range(N):
    gpa = float(input())
    gpas.append(gpa)

for k in range(len(gpas)):
    win = 0
    draw = -1
    for comparingGpa in gpas:
        if gpas[k] > comparingGpa:
            win += 1
        elif gpas[k] == comparingGpa:
            draw += 1
    points[k] += win*3 + draw

for key, item in points.items():
    print(item)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [float(input()) for _ in range(n)]
p = [0] * n
for i in range(n):
    for j in range(i + 1, n):
        if a[i] > a[j]:
            p[i] += 3
        elif a[i] == a[j]:
            p[i] += 1
            p[j] += 1
        else:
            p[j] += 3
for i in p:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [float(input()) for _ in range(n)]
b = sorted(a)
for i in range(n):
    print(b.index(a[i]) * 3 + b.count(a[i]) - 1)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
for i in range(N):
    a = float(input())
    A.append(a)

ans = [0]*len(A)

for i in range(N-1):
    for j in range(i+1,N):
        if A[i]>A[j]:
            ans[i]+=3
        elif A[i]==A[j]:
            ans[i]+=1
            ans[j]+=1
        elif A[i]<A[j]:
            ans[j]+=3
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
from bisect import bisect_left as bl
from bisect import bisect_right as br

n = int(input())
alst = [float(input()) for _ in range(n)]
sorted_alst = sorted(alst)
for a in alst:
  li = bl(sorted_alst, a)
  ri = br(sorted_alst, a)
  print(li * 3 + (ri - li - 1))

Submission status: Accepted

Solution code:
N = int(input())
P = {}
for i in range(N):
    p = float(input())
    P.setdefault(p, []).append(i)

ans = [0]*N
c = 0
for p, s in sorted(P.items()):
    for i in s:
        ans[i] = 3*c + len(s)-1
    c += len(s)
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LS(): return input().split()
def I(): return int(input())
def F(): return float(input())
def S(): return input()


def main():
    n = I()
    a = sorted([[F(),_] for _ in range(n)])
    r = [0] * n
    ct = collections.defaultdict(int)
    for f,i in a:
        ct[f] += 1
    m = -1
    mi = 0
    for ai in range(n):
        c,i = a[ai]
        if m < c:
            m = c
            mi = ai
        r[i] = mi*3 + ct[c] - 1
    return '\n'.join(map(str,r))


print(main())

Submission status: Accepted

Solution code:

if __name__ == "__main__":
	n = input()
	a = [0.0] * int(n)
	b = [0.0] * int(n)
	count = {"6.909":0} 
	for i in range(int(n)):
		a[i] = input()
		b[i] = a[i]

	b.sort()
	for i in range(int(n)-1):
		if float(b[i]) == float(b[i+1]):
			if b[i] in count:
				x = count[b[i]]
				count[b[i]] = (x + 1)
			else:
				count[b[i]] = 2

	i = 0
	while i < int(n):
		if b[i] in count:
			x = count[b[i]]
			count[b[i]] = (3 * i + x - 1)
			i = i + x - 1
		else:
			count[b[i]] = (3 * i)
		i = i + 1

	for i in range(int(n)):
		print (count[a[i]])

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = [float(input()) for _ in range(n)]
b = sorted(a)
for i in range(n):
    x = bisect.bisect_left(b, a[i])
    y = bisect.bisect_right(b, a[i])
    print(x * 2 + y - 1)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = []
for i in range(n):
    a.append(float(input()))
a2 = sorted(a)
for i in a:
    kati = bisect.bisect_left(a2, i)
    hiki = bisect.bisect_right(a2, i) - kati - 1
    print(kati*3 + hiki)

Submission status: Accepted

Solution code:
from bisect import bisect_left as bl
from bisect import bisect_right as br

n = int(input())

gpa = []
for _ in range(n):
    gpa.append(float(input()))

gpa_s = sorted(gpa)

for g in gpa:
    less = bl(gpa_s, g)
    more = br(gpa_s, g)
    print(less * 3 + (more-less-1))

Submission status: Accepted

Solution code:
from bisect import *
a=[]
b=[]
n=int(input())
for i in range(n):
    g=float(input())
    a.append(g)
    insort_left(b,g)
for i in range(n):
    win=bisect_left(b,a[i])
    lose=n-bisect_right(b,a[i])
    print(3*win+(n-win-lose-1))

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)

ans = [0]*len(A)

for i in range(N-1):
    for j in range(i+1,N):
        if A[i]>A[j]:
            ans[i]+=3
        elif A[i]==A[j]:
            ans[i]+=1
            ans[j]+=1
        elif A[i]<A[j]:
            ans[j]+=3
for i in range(len(ans)):
    print(ans[i])