Submission #14690527
Source Code Expand
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
'''
以下、方針
・Aから、各要素の出現回数を取得する。
・出現回数から、組み合わせを計算する。
'''
uni,cou=np.unique(A,return_counts=True)
# print(uni)
# print(cou)
com=[]
for i in range(len(cou)):
nforc=cou[i]
c=nforc*(nforc-1)//2
com.append(c)
# print(com)
totalcombination=sum(com)
'''
以下方針
・Aから数字を取得
・その数字に対応する組み合わせを減らす。
・その数字の出現回数を1減らした状態の組み合わせの数を足す。
'''
dic={}
for num in uni:
dic.setdefault(num)
#print(dic)
for j in range (N):
n=A[j] #nはAの数列の数字
if dic[n]==None:
f=np.where(uni==n)[0][0]
t=com[f]
nfore=cou[f]
e=(nfore-1)*(nfore-2)//2
a=totalcombination-t+e
dic[n]=a
print(a)
else:
print(dic[n])
Submission Info
| Submission Time | |
|---|---|
| Task | D - Banned K |
| User | negibose2020 |
| Language | Python (3.8.2) |
| Score | 0 |
| Code Size | 993 Byte |
| Status | TLE |
| Exec Time | 2207 ms |
| Memory | 51564 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 400 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
| All | equal_01.txt, equal_02.txt, large_ans_01.txt, large_ans_02.txt, large_ans_03.txt, rand_01.txt, rand_02.txt, rand_03.txt, rand_04.txt, rand_05.txt, rand_06.txt, rand_07.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| equal_01.txt | AC | 382 ms | 51564 KiB |
| equal_02.txt | AC | 376 ms | 49924 KiB |
| large_ans_01.txt | AC | 361 ms | 30644 KiB |
| large_ans_02.txt | AC | 361 ms | 30668 KiB |
| large_ans_03.txt | AC | 368 ms | 30872 KiB |
| rand_01.txt | TLE | 2207 ms | 50956 KiB |
| rand_02.txt | TLE | 2207 ms | 51052 KiB |
| rand_03.txt | TLE | 2207 ms | 50960 KiB |
| rand_04.txt | TLE | 2207 ms | 50876 KiB |
| rand_05.txt | TLE | 2207 ms | 50740 KiB |
| rand_06.txt | TLE | 2207 ms | 50916 KiB |
| rand_07.txt | TLE | 2207 ms | 50668 KiB |
| sample_01.txt | AC | 112 ms | 27112 KiB |
| sample_02.txt | AC | 118 ms | 27236 KiB |
| sample_03.txt | AC | 116 ms | 27092 KiB |
| sample_04.txt | AC | 115 ms | 27100 KiB |