結果
問題 | No.5004 Room Assignment |
ユーザー | negibose2020 |
提出日時 | 2021-12-03 17:00:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 4,938 ms / 5,000 ms |
コード長 | 6,065 bytes |
コンパイル時間 | 305 ms |
実行使用メモリ | 112,028 KB |
スコア | 130,720,193 |
平均クエリ数 | 122672.70 |
最終ジャッジ日時 | 2021-12-03 17:07:49 |
合計ジャッジ時間 | 437,495 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4,442 ms
107,584 KB |
testcase_01 | AC | 3,989 ms
109,364 KB |
testcase_02 | AC | 4,875 ms
105,360 KB |
testcase_03 | AC | 4,452 ms
108,592 KB |
testcase_04 | AC | 3,791 ms
109,800 KB |
testcase_05 | AC | 4,242 ms
109,484 KB |
testcase_06 | AC | 3,529 ms
106,152 KB |
testcase_07 | AC | 4,870 ms
106,672 KB |
testcase_08 | AC | 3,660 ms
110,484 KB |
testcase_09 | AC | 3,982 ms
107,752 KB |
testcase_10 | AC | 3,627 ms
108,564 KB |
testcase_11 | AC | 4,006 ms
104,780 KB |
testcase_12 | AC | 3,935 ms
110,892 KB |
testcase_13 | AC | 4,493 ms
110,904 KB |
testcase_14 | AC | 4,938 ms
108,200 KB |
testcase_15 | AC | 4,913 ms
106,396 KB |
testcase_16 | AC | 3,766 ms
107,064 KB |
testcase_17 | AC | 4,271 ms
106,524 KB |
testcase_18 | AC | 4,114 ms
110,300 KB |
testcase_19 | AC | 3,376 ms
106,740 KB |
testcase_20 | AC | 4,890 ms
105,904 KB |
testcase_21 | AC | 4,886 ms
110,408 KB |
testcase_22 | AC | 3,572 ms
107,588 KB |
testcase_23 | AC | 4,887 ms
107,508 KB |
testcase_24 | AC | 4,892 ms
108,084 KB |
testcase_25 | AC | 4,773 ms
108,828 KB |
testcase_26 | AC | 4,316 ms
109,336 KB |
testcase_27 | AC | 4,191 ms
108,212 KB |
testcase_28 | AC | 4,624 ms
107,728 KB |
testcase_29 | AC | 4,573 ms
105,268 KB |
testcase_30 | AC | 3,794 ms
107,228 KB |
testcase_31 | AC | 4,624 ms
109,040 KB |
testcase_32 | AC | 4,812 ms
109,480 KB |
testcase_33 | AC | 3,757 ms
107,140 KB |
testcase_34 | AC | 3,842 ms
106,124 KB |
testcase_35 | AC | 3,081 ms
108,924 KB |
testcase_36 | AC | 4,280 ms
106,952 KB |
testcase_37 | AC | 4,019 ms
107,292 KB |
testcase_38 | AC | 4,914 ms
110,112 KB |
testcase_39 | AC | 3,636 ms
107,068 KB |
testcase_40 | AC | 4,344 ms
107,164 KB |
testcase_41 | AC | 4,487 ms
106,232 KB |
testcase_42 | AC | 4,902 ms
107,488 KB |
testcase_43 | AC | 4,081 ms
106,104 KB |
testcase_44 | AC | 4,455 ms
109,144 KB |
testcase_45 | AC | 4,053 ms
110,360 KB |
testcase_46 | AC | 4,724 ms
107,104 KB |
testcase_47 | AC | 4,331 ms
106,408 KB |
testcase_48 | AC | 4,929 ms
107,212 KB |
testcase_49 | AC | 4,073 ms
108,348 KB |
testcase_50 | AC | 4,891 ms
108,280 KB |
testcase_51 | AC | 4,653 ms
107,136 KB |
testcase_52 | AC | 4,875 ms
108,172 KB |
testcase_53 | AC | 3,993 ms
106,612 KB |
testcase_54 | AC | 4,047 ms
108,148 KB |
testcase_55 | AC | 4,913 ms
108,280 KB |
testcase_56 | AC | 4,146 ms
108,196 KB |
testcase_57 | AC | 3,721 ms
105,628 KB |
testcase_58 | AC | 3,316 ms
106,468 KB |
testcase_59 | AC | 4,913 ms
107,668 KB |
testcase_60 | AC | 4,012 ms
108,996 KB |
testcase_61 | AC | 4,459 ms
106,436 KB |
testcase_62 | AC | 3,805 ms
107,148 KB |
testcase_63 | AC | 4,217 ms
108,584 KB |
testcase_64 | AC | 4,896 ms
105,912 KB |
testcase_65 | AC | 3,634 ms
105,608 KB |
testcase_66 | AC | 4,877 ms
105,364 KB |
testcase_67 | AC | 4,924 ms
106,736 KB |
testcase_68 | AC | 4,114 ms
108,120 KB |
testcase_69 | AC | 3,928 ms
105,344 KB |
testcase_70 | AC | 3,603 ms
107,912 KB |
testcase_71 | AC | 4,869 ms
108,264 KB |
testcase_72 | AC | 4,904 ms
107,132 KB |
testcase_73 | AC | 3,384 ms
111,296 KB |
testcase_74 | AC | 4,235 ms
106,748 KB |
testcase_75 | AC | 4,284 ms
112,028 KB |
testcase_76 | AC | 3,705 ms
111,504 KB |
testcase_77 | AC | 4,935 ms
108,152 KB |
testcase_78 | AC | 3,600 ms
107,396 KB |
testcase_79 | AC | 3,883 ms
108,284 KB |
testcase_80 | AC | 4,007 ms
109,256 KB |
testcase_81 | AC | 3,808 ms
108,844 KB |
testcase_82 | AC | 3,505 ms
107,280 KB |
testcase_83 | AC | 4,898 ms
107,564 KB |
testcase_84 | AC | 4,878 ms
110,756 KB |
testcase_85 | AC | 4,899 ms
109,012 KB |
testcase_86 | AC | 3,928 ms
109,000 KB |
testcase_87 | AC | 3,681 ms
109,444 KB |
testcase_88 | AC | 3,641 ms
106,904 KB |
testcase_89 | AC | 3,251 ms
108,152 KB |
testcase_90 | AC | 4,901 ms
106,448 KB |
testcase_91 | AC | 4,864 ms
108,064 KB |
testcase_92 | AC | 4,885 ms
108,128 KB |
testcase_93 | AC | 3,502 ms
107,932 KB |
testcase_94 | AC | 4,168 ms
108,012 KB |
testcase_95 | AC | 4,876 ms
109,004 KB |
testcase_96 | AC | 3,466 ms
106,832 KB |
testcase_97 | AC | 4,889 ms
108,668 KB |
testcase_98 | AC | 4,038 ms
105,200 KB |
testcase_99 | AC | 4,623 ms
109,872 KB |
ソースコード
from collections import defaultdict import sys import time class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) def clc_score(num,minskil,maxskil,x,y): a=(num*(num-1)//2) * (200-(maxskil-minskil)*(maxskil-minskil)) - (num*(num-1)//2)*(y-x) # print(a) return max(a,0) # print (clc_score(2,3,4,3,5)) # print (clc_score(2,3,4,3,14)) stime=time.perf_counter() T,R=map(int,input().split()) t=0 N=5400 uf=UnionFind(N+1) p=[-1]*(N+1) tick=[-1]*(N+1) room4set=set() # score,minskill,maxskill,x,sz scores=[[0,0,100,0,1] for i in range (N+1)] s=set() # スキル値, プレイヤーi, 出現チック s.add((-10000000,-1,-1)) s.add((100000000,-1,-1)) pi=1 t_ans=set() import bisect while t<3600 : nowtime=time.perf_counter() L=list(map(int,input().split())) if nowtime - stime >4.75: t+=1 print(0) sys.stdout.flush() continue if t %50 ==0: for e in list(s): if e == (-10000000,-1,-1) or e ==(100000000,-1,-1): continue else: if t - e[2] >100 or e[1] in room4set: s.discard(e) if L[0] == 0: t+=1 print(0) sys.stdout.flush() continue for i in range(L[0]): # print(s) nowi = (L[i+1],pi,t) p[pi] = L[i+1] tick[pi] = t scores[pi] = [0,L[i+1],L[i+1],t,1] sorteds=sorted(list(s)) target=bisect.bisect_right(sorteds,nowi) for _t in list(t_ans): if abs(p[pi] - p[_t]) < 3: score,minskill,maxskill,x,sz = scores[_t] # print(score,minskill,maxskill,x,sz) sz=len(uf.members(_t)) if sz < 4: _score = clc_score(sz+1,min(minskill,p[pi]),max(maxskill,p[pi]),x,t) if _score > score: uf.union(_t, pi) t_ans.add(pi) scores[_t] = [_score, min(minskill,p[pi]), max(maxskill,p[pi]),x,sz+1] scores[pi] = [_score, min(minskill,p[pi]), max(maxskill,p[pi]),x,sz+1] break if abs(sorteds[target-1][0] - L[i+1])<3: score1,minskill1,maxskill1,x1,sz1 = scores[sorteds[target-1][1]] sz1 = len(uf.members(sorteds[target-1][1])) # score1=1000 score2,minskill2,maxskill2,x2,sz2 = scores[pi] sz2 = len(uf.members(pi)) # score2=1000 if sz1 + sz2 <= 4: _score = clc_score((sz1+sz2),min(minskill1,minskill2),max(maxskill1,maxskill2),min(x1,x2),t) # _score = 100000000000000000000 if _score > score1 + score2: uf.union(pi, sorteds[target-1][1]) t_ans.add(pi) # scores[sorteds[target-1][1]] = [_score, min(minskill1,minskill2),max(maxskill1,maxskill2),min(x1,x2),(sz1+sz2)] # scores[pi] = [_score, min(minskill1,minskill2),max(maxskill1,maxskill2),min(x1,x2),(sz1+sz2)] # s.discard(sorteds[target-1]) if abs(sorteds[target][0] - L[i+1])<3: # score1,minskill1,maxskill1,x1,sz1 = scores[sorteds[target][1]] score1=1000 sz1 = len(uf.members(sorteds[target][1])) # score2,minskill2,maxskill2,x2,sz2 = scores[pi] score2 = 10000 sz2 = len(uf.members(pi)) if sz1 + sz2 <= 4: # _score = clc_score((sz1+sz2),min(minskill1,minskill2),max(maxskill1,maxskill2),min(x1,x2),t) _score=10000000000 if _score > score1 + score2: uf.union(pi, sorteds[target][1]) t_ans.add(pi) # scores[sorteds[target][1]] = [_score, min(minskill1,minskill2),max(maxskill1,maxskill2),min(x1,x2),(sz1+sz2)] # scores[pi] = [_score, min(minskill1,minskill2),max(maxskill1,maxskill2),min(x1,x2),(sz1+sz2)] # s.discard(sorteds[target]) s.add(nowi) pi+=1 t+=1 # print (t_ans) ans4print=[] ans4print_num=0 for ans in list(t_ans): m=uf.members(ans) if len(m)>=4: mls=[] for i in range(1,4):#len(m)) : mls.append([m[0],m[i]]) t_ans.discard(m[0]) t_ans.discard(m[i]) ans4print_num+=1 room4set.add(m[0]) room4set.add(m[i]) ans4print.append(mls) else: mls=[] for i in range (1,len(m)): mls.append([m[0],m[i]]) ans4print_num+=1 ans4print.append(mls) print(ans4print_num) sys.stdout.flush() for i in range (len(ans4print)): for e in ans4print[i]: print(*e) sys.stdout.flush()