結果
問題 | No.5004 Room Assignment |
ユーザー | negibose2020 |
提出日時 | 2021-12-03 15:51:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,297 ms / 5,000 ms |
コード長 | 5,914 bytes |
コンパイル時間 | 1,029 ms |
実行使用メモリ | 105,832 KB |
スコア | 0 |
平均クエリ数 | 3600.00 |
最終ジャッジ日時 | 2021-12-03 15:55:00 |
合計ジャッジ時間 | 223,280 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,125 ms
100,728 KB |
testcase_01 | AC | 2,107 ms
102,564 KB |
testcase_02 | AC | 2,131 ms
102,588 KB |
testcase_03 | AC | 2,108 ms
101,216 KB |
testcase_04 | AC | 2,095 ms
103,736 KB |
testcase_05 | AC | 2,131 ms
104,396 KB |
testcase_06 | AC | 2,121 ms
102,504 KB |
testcase_07 | AC | 2,135 ms
103,788 KB |
testcase_08 | AC | 2,139 ms
103,436 KB |
testcase_09 | AC | 2,038 ms
103,652 KB |
testcase_10 | AC | 2,234 ms
101,752 KB |
testcase_11 | AC | 2,071 ms
101,444 KB |
testcase_12 | AC | 2,184 ms
103,928 KB |
testcase_13 | AC | 2,070 ms
102,236 KB |
testcase_14 | AC | 2,217 ms
104,944 KB |
testcase_15 | AC | 2,201 ms
102,604 KB |
testcase_16 | AC | 2,227 ms
102,424 KB |
testcase_17 | AC | 2,143 ms
103,580 KB |
testcase_18 | AC | 2,267 ms
104,644 KB |
testcase_19 | AC | 2,153 ms
102,360 KB |
testcase_20 | AC | 2,178 ms
104,744 KB |
testcase_21 | AC | 2,176 ms
103,540 KB |
testcase_22 | AC | 2,233 ms
100,176 KB |
testcase_23 | AC | 2,125 ms
102,220 KB |
testcase_24 | AC | 2,058 ms
102,764 KB |
testcase_25 | AC | 2,207 ms
103,964 KB |
testcase_26 | AC | 2,022 ms
100,640 KB |
testcase_27 | AC | 2,124 ms
105,832 KB |
testcase_28 | AC | 2,093 ms
101,404 KB |
testcase_29 | AC | 2,191 ms
103,408 KB |
testcase_30 | AC | 2,078 ms
101,796 KB |
testcase_31 | AC | 2,197 ms
102,116 KB |
testcase_32 | AC | 2,079 ms
101,656 KB |
testcase_33 | AC | 2,106 ms
103,052 KB |
testcase_34 | AC | 2,141 ms
104,504 KB |
testcase_35 | AC | 2,110 ms
104,504 KB |
testcase_36 | AC | 2,147 ms
103,040 KB |
testcase_37 | AC | 2,097 ms
104,276 KB |
testcase_38 | AC | 2,113 ms
102,216 KB |
testcase_39 | AC | 2,122 ms
105,292 KB |
testcase_40 | AC | 2,043 ms
102,200 KB |
testcase_41 | AC | 2,121 ms
101,476 KB |
testcase_42 | AC | 2,052 ms
104,960 KB |
testcase_43 | AC | 2,083 ms
101,524 KB |
testcase_44 | AC | 2,063 ms
101,940 KB |
testcase_45 | AC | 2,297 ms
102,276 KB |
testcase_46 | AC | 2,152 ms
104,264 KB |
testcase_47 | AC | 2,165 ms
104,648 KB |
testcase_48 | AC | 2,128 ms
102,760 KB |
testcase_49 | AC | 2,133 ms
104,596 KB |
testcase_50 | AC | 2,082 ms
101,964 KB |
testcase_51 | AC | 2,147 ms
101,128 KB |
testcase_52 | AC | 2,222 ms
100,764 KB |
testcase_53 | AC | 2,124 ms
101,484 KB |
testcase_54 | AC | 2,113 ms
102,700 KB |
testcase_55 | AC | 2,177 ms
102,752 KB |
testcase_56 | AC | 2,105 ms
99,964 KB |
testcase_57 | AC | 2,075 ms
103,088 KB |
testcase_58 | AC | 2,059 ms
103,564 KB |
testcase_59 | AC | 2,159 ms
104,280 KB |
testcase_60 | AC | 2,119 ms
102,868 KB |
testcase_61 | AC | 2,115 ms
103,236 KB |
testcase_62 | AC | 2,060 ms
102,512 KB |
testcase_63 | AC | 2,106 ms
103,132 KB |
testcase_64 | AC | 2,129 ms
103,064 KB |
testcase_65 | AC | 2,158 ms
101,164 KB |
testcase_66 | AC | 2,093 ms
104,004 KB |
testcase_67 | AC | 2,141 ms
101,916 KB |
testcase_68 | AC | 2,082 ms
101,088 KB |
testcase_69 | AC | 2,076 ms
100,556 KB |
testcase_70 | AC | 2,073 ms
103,272 KB |
testcase_71 | AC | 2,099 ms
102,120 KB |
testcase_72 | AC | 2,148 ms
101,352 KB |
testcase_73 | AC | 2,075 ms
102,268 KB |
testcase_74 | AC | 2,095 ms
101,008 KB |
testcase_75 | AC | 2,095 ms
103,528 KB |
testcase_76 | AC | 2,029 ms
100,648 KB |
testcase_77 | AC | 2,133 ms
102,576 KB |
testcase_78 | AC | 2,049 ms
102,508 KB |
testcase_79 | AC | 2,027 ms
102,252 KB |
testcase_80 | AC | 2,148 ms
102,848 KB |
testcase_81 | AC | 2,170 ms
101,596 KB |
testcase_82 | AC | 2,190 ms
101,160 KB |
testcase_83 | AC | 2,063 ms
102,912 KB |
testcase_84 | AC | 2,111 ms
102,324 KB |
testcase_85 | AC | 2,120 ms
103,068 KB |
testcase_86 | AC | 2,127 ms
102,944 KB |
testcase_87 | AC | 2,120 ms
101,968 KB |
testcase_88 | AC | 2,092 ms
102,932 KB |
testcase_89 | AC | 2,091 ms
103,308 KB |
testcase_90 | AC | 2,081 ms
103,704 KB |
testcase_91 | AC | 2,108 ms
100,952 KB |
testcase_92 | AC | 2,096 ms
102,264 KB |
testcase_93 | AC | 2,042 ms
101,768 KB |
testcase_94 | AC | 2,059 ms
102,480 KB |
testcase_95 | AC | 2,038 ms
102,936 KB |
testcase_96 | AC | 2,240 ms
101,884 KB |
testcase_97 | AC | 2,030 ms
102,460 KB |
testcase_98 | AC | 2,128 ms
105,044 KB |
testcase_99 | AC | 2,160 ms
103,120 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()) 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() def clc_score(num,minskil,maxskil,x,y): a=(num*(num-1)//2) * (200-(maxskil-minskil)*(maxskil*minskil)) - (num*(num-1)//2)*(y-x) return max(a,0) import bisect while t<3600 : nowtime=time.perf_counter() L=list(map(int,input().split())) if nowtime - stime >4.70: t+=1 print(0) sys.stdout.flush() continue if L[0] == 0: 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) 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] 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 = 1 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=1 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()