結果

問題 No.5004 Room Assignment
ユーザー negibose2020negibose2020
提出日時 2021-12-02 15:28:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,460 ms / 5,000 ms
コード長 4,468 bytes
コンパイル時間 460 ms
実行使用メモリ 107,144 KB
スコア 133,675,493
平均クエリ数 62390.16
最終ジャッジ日時 2021-12-02 15:32:39
合計ジャッジ時間 260,513 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,365 ms
104,144 KB
testcase_01 AC 3,147 ms
105,872 KB
testcase_02 AC 2,316 ms
106,836 KB
testcase_03 AC 2,519 ms
105,724 KB
testcase_04 AC 2,383 ms
103,672 KB
testcase_05 AC 3,400 ms
103,276 KB
testcase_06 AC 3,448 ms
101,932 KB
testcase_07 AC 2,205 ms
103,584 KB
testcase_08 AC 2,285 ms
105,012 KB
testcase_09 AC 2,379 ms
105,020 KB
testcase_10 AC 2,371 ms
103,956 KB
testcase_11 AC 3,285 ms
102,296 KB
testcase_12 AC 2,245 ms
103,552 KB
testcase_13 AC 2,263 ms
104,428 KB
testcase_14 AC 2,496 ms
106,056 KB
testcase_15 AC 2,441 ms
102,856 KB
testcase_16 AC 2,277 ms
103,812 KB
testcase_17 AC 2,192 ms
104,616 KB
testcase_18 AC 2,241 ms
105,708 KB
testcase_19 AC 2,716 ms
105,528 KB
testcase_20 AC 2,555 ms
106,112 KB
testcase_21 AC 2,459 ms
104,244 KB
testcase_22 AC 2,482 ms
103,628 KB
testcase_23 AC 3,067 ms
104,332 KB
testcase_24 AC 2,510 ms
104,568 KB
testcase_25 AC 2,206 ms
104,588 KB
testcase_26 AC 2,219 ms
102,116 KB
testcase_27 AC 3,242 ms
103,976 KB
testcase_28 AC 2,204 ms
102,384 KB
testcase_29 AC 2,338 ms
104,888 KB
testcase_30 AC 2,332 ms
105,172 KB
testcase_31 AC 2,657 ms
103,016 KB
testcase_32 AC 2,998 ms
104,816 KB
testcase_33 AC 2,219 ms
103,668 KB
testcase_34 AC 2,435 ms
104,796 KB
testcase_35 AC 2,420 ms
104,724 KB
testcase_36 AC 2,245 ms
107,144 KB
testcase_37 AC 3,241 ms
104,960 KB
testcase_38 AC 2,448 ms
104,028 KB
testcase_39 AC 3,257 ms
103,992 KB
testcase_40 AC 2,953 ms
103,576 KB
testcase_41 AC 2,479 ms
106,932 KB
testcase_42 AC 2,144 ms
104,040 KB
testcase_43 AC 2,195 ms
105,076 KB
testcase_44 AC 3,130 ms
105,900 KB
testcase_45 AC 2,467 ms
106,092 KB
testcase_46 AC 2,200 ms
104,664 KB
testcase_47 AC 3,112 ms
104,408 KB
testcase_48 AC 2,305 ms
104,308 KB
testcase_49 AC 2,432 ms
103,184 KB
testcase_50 AC 2,270 ms
104,804 KB
testcase_51 AC 2,248 ms
105,376 KB
testcase_52 AC 2,479 ms
104,760 KB
testcase_53 AC 2,331 ms
104,696 KB
testcase_54 AC 2,429 ms
103,564 KB
testcase_55 AC 2,253 ms
104,776 KB
testcase_56 AC 2,453 ms
102,832 KB
testcase_57 AC 2,368 ms
104,096 KB
testcase_58 AC 2,350 ms
103,904 KB
testcase_59 AC 2,224 ms
105,712 KB
testcase_60 AC 3,406 ms
103,704 KB
testcase_61 AC 2,320 ms
105,856 KB
testcase_62 AC 2,155 ms
102,344 KB
testcase_63 AC 2,380 ms
104,960 KB
testcase_64 AC 2,346 ms
102,552 KB
testcase_65 AC 2,432 ms
101,496 KB
testcase_66 AC 2,215 ms
103,812 KB
testcase_67 AC 3,312 ms
105,376 KB
testcase_68 AC 2,224 ms
103,420 KB
testcase_69 AC 2,191 ms
104,884 KB
testcase_70 AC 2,398 ms
103,200 KB
testcase_71 AC 2,375 ms
104,920 KB
testcase_72 AC 2,991 ms
102,188 KB
testcase_73 AC 2,331 ms
104,572 KB
testcase_74 AC 2,354 ms
105,536 KB
testcase_75 AC 2,206 ms
104,960 KB
testcase_76 AC 2,226 ms
104,100 KB
testcase_77 AC 3,296 ms
104,792 KB
testcase_78 AC 3,010 ms
105,888 KB
testcase_79 AC 2,408 ms
104,228 KB
testcase_80 AC 2,323 ms
105,768 KB
testcase_81 AC 2,449 ms
105,480 KB
testcase_82 AC 2,452 ms
103,328 KB
testcase_83 AC 2,438 ms
102,892 KB
testcase_84 AC 3,109 ms
104,144 KB
testcase_85 AC 2,369 ms
103,184 KB
testcase_86 AC 2,440 ms
104,932 KB
testcase_87 AC 2,247 ms
103,676 KB
testcase_88 AC 3,460 ms
106,280 KB
testcase_89 AC 2,418 ms
102,956 KB
testcase_90 AC 2,441 ms
103,320 KB
testcase_91 AC 3,051 ms
103,412 KB
testcase_92 AC 2,450 ms
104,124 KB
testcase_93 AC 2,332 ms
104,848 KB
testcase_94 AC 2,302 ms
102,528 KB
testcase_95 AC 2,394 ms
103,960 KB
testcase_96 AC 2,503 ms
104,736 KB
testcase_97 AC 2,238 ms
104,284 KB
testcase_98 AC 2,162 ms
104,184 KB
testcase_99 AC 2,158 ms
106,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()

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.85:
    #     t+=1
    #     print(0)
    #     sys.stdout.flush()
    #     continue
    
    for e in list(s):
        if e == (-10000000,-1,-1) or e ==(100000000,-1,-1):
            continue
        else:
            if t - e[2] >200 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
        sorteds=sorted(list(s))
        target=bisect.bisect_right(sorteds,nowi)

        used=False
        for _t in list(t_ans):
            if abs(p[pi] - p[_t]) < 3:
                sz=len(uf.members(_t))
                if sz < 4:
                    uf.union(_t, pi)
                    t_ans.add(pi)
                    used = True
                    break

        if abs(sorteds[target-1][0] - L[i+1])<4:
            sz1 = len(uf.members(sorteds[target-1][1]))
            sz2 = len(uf.members(pi))
            if sz1 + sz2 <= 4:
                uf.union(pi, sorteds[target-1][1])
                t_ans.add(pi)
                used = True
                # s.discard(sorteds[target-1])

        if abs(sorteds[target][0] - L[i+1])<4:
            sz1 = len(uf.members(sorteds[target][1]))
            sz2 = len(uf.members(pi))
            if sz1 + sz2 <= 4:
                uf.union(pi, sorteds[target][1])
                t_ans.add(pi)
                used = True
                # s.discard(sorteds[target])

        # if used == False:
        #     s.add(nowi)
        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)

            # min_tick=10000000000
            # for i in range (len(m)):
            #     min_tick = min(min_tick, tick[m[i]])
            # if min_tick < t - 100 :
            #     mls = []
            #     for i in range (1,len(m)):
            #         mls.append([m[0],m[i]])
            #         t_ans.discard(m[0])
            #         t_ans.discard(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()
0