結果

問題 No.5004 Room Assignment
ユーザー negibose2020negibose2020
提出日時 2021-12-02 16:22:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,192 ms / 5,000 ms
コード長 4,467 bytes
コンパイル時間 205 ms
実行使用メモリ 106,904 KB
スコア 125,122,643
平均クエリ数 53461.47
最終ジャッジ日時 2021-12-02 16:26:50
合計ジャッジ時間 223,437 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,954 ms
102,704 KB
testcase_01 AC 2,583 ms
104,092 KB
testcase_02 AC 1,942 ms
104,468 KB
testcase_03 AC 2,018 ms
105,100 KB
testcase_04 AC 2,028 ms
105,060 KB
testcase_05 AC 2,098 ms
105,508 KB
testcase_06 AC 2,278 ms
103,648 KB
testcase_07 AC 1,891 ms
104,784 KB
testcase_08 AC 2,031 ms
104,884 KB
testcase_09 AC 2,034 ms
106,632 KB
testcase_10 AC 2,039 ms
103,672 KB
testcase_11 AC 1,984 ms
103,292 KB
testcase_12 AC 2,009 ms
104,764 KB
testcase_13 AC 2,183 ms
106,896 KB
testcase_14 AC 2,119 ms
106,636 KB
testcase_15 AC 2,204 ms
106,904 KB
testcase_16 AC 2,014 ms
103,004 KB
testcase_17 AC 1,876 ms
103,820 KB
testcase_18 AC 1,844 ms
104,272 KB
testcase_19 AC 3,192 ms
103,500 KB
testcase_20 AC 2,835 ms
104,620 KB
testcase_21 AC 2,075 ms
104,008 KB
testcase_22 AC 2,108 ms
105,192 KB
testcase_23 AC 2,003 ms
103,224 KB
testcase_24 AC 2,341 ms
105,612 KB
testcase_25 AC 1,957 ms
102,300 KB
testcase_26 AC 2,664 ms
103,476 KB
testcase_27 AC 2,123 ms
104,896 KB
testcase_28 AC 2,044 ms
104,452 KB
testcase_29 AC 2,050 ms
103,488 KB
testcase_30 AC 2,081 ms
104,240 KB
testcase_31 AC 2,334 ms
103,780 KB
testcase_32 AC 2,019 ms
103,940 KB
testcase_33 AC 2,055 ms
103,112 KB
testcase_34 AC 2,170 ms
103,312 KB
testcase_35 AC 2,099 ms
102,832 KB
testcase_36 AC 2,692 ms
105,712 KB
testcase_37 AC 2,858 ms
104,696 KB
testcase_38 AC 2,034 ms
105,624 KB
testcase_39 AC 2,244 ms
104,232 KB
testcase_40 AC 1,986 ms
103,868 KB
testcase_41 AC 2,158 ms
103,080 KB
testcase_42 AC 1,890 ms
102,612 KB
testcase_43 AC 1,927 ms
103,820 KB
testcase_44 AC 2,064 ms
104,104 KB
testcase_45 AC 2,357 ms
106,348 KB
testcase_46 AC 1,913 ms
104,704 KB
testcase_47 AC 2,811 ms
103,780 KB
testcase_48 AC 2,001 ms
104,292 KB
testcase_49 AC 2,135 ms
105,124 KB
testcase_50 AC 1,982 ms
105,788 KB
testcase_51 AC 1,954 ms
103,548 KB
testcase_52 AC 2,137 ms
104,292 KB
testcase_53 AC 2,023 ms
105,444 KB
testcase_54 AC 1,966 ms
102,888 KB
testcase_55 AC 1,981 ms
105,476 KB
testcase_56 AC 2,058 ms
104,884 KB
testcase_57 AC 2,790 ms
105,372 KB
testcase_58 AC 2,225 ms
104,264 KB
testcase_59 AC 1,914 ms
102,848 KB
testcase_60 AC 2,266 ms
104,584 KB
testcase_61 AC 1,975 ms
106,080 KB
testcase_62 AC 2,583 ms
101,576 KB
testcase_63 AC 2,014 ms
105,584 KB
testcase_64 AC 2,228 ms
103,732 KB
testcase_65 AC 2,145 ms
101,992 KB
testcase_66 AC 2,013 ms
102,748 KB
testcase_67 AC 2,836 ms
103,184 KB
testcase_68 AC 1,918 ms
103,052 KB
testcase_69 AC 1,973 ms
105,196 KB
testcase_70 AC 2,256 ms
102,944 KB
testcase_71 AC 2,146 ms
106,620 KB
testcase_72 AC 1,944 ms
102,812 KB
testcase_73 AC 2,074 ms
104,324 KB
testcase_74 AC 2,079 ms
105,248 KB
testcase_75 AC 1,876 ms
103,400 KB
testcase_76 AC 1,955 ms
104,176 KB
testcase_77 AC 2,121 ms
104,248 KB
testcase_78 AC 1,993 ms
105,228 KB
testcase_79 AC 2,112 ms
104,860 KB
testcase_80 AC 2,088 ms
102,596 KB
testcase_81 AC 2,118 ms
103,016 KB
testcase_82 AC 2,053 ms
103,320 KB
testcase_83 AC 2,104 ms
103,452 KB
testcase_84 AC 1,983 ms
103,876 KB
testcase_85 AC 2,037 ms
104,900 KB
testcase_86 AC 1,982 ms
105,012 KB
testcase_87 AC 1,976 ms
102,820 KB
testcase_88 AC 2,974 ms
105,212 KB
testcase_89 AC 2,089 ms
105,448 KB
testcase_90 AC 2,124 ms
103,872 KB
testcase_91 AC 1,899 ms
103,236 KB
testcase_92 AC 2,138 ms
102,516 KB
testcase_93 AC 2,190 ms
105,036 KB
testcase_94 AC 2,110 ms
105,500 KB
testcase_95 AC 2,051 ms
103,768 KB
testcase_96 AC 2,262 ms
103,976 KB
testcase_97 AC 1,986 ms
103,968 KB
testcase_98 AC 2,059 ms
103,372 KB
testcase_99 AC 2,777 ms
104,820 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] >50 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])<5:
            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])<5:
            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