結果

問題 No.5004 Room Assignment
ユーザー negibose2020negibose2020
提出日時 2021-12-01 22:31:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,113 ms / 5,000 ms
コード長 3,538 bytes
コンパイル時間 504 ms
実行使用メモリ 107,708 KB
スコア 56,163,129
平均クエリ数 7688.28
最終ジャッジ日時 2021-12-01 22:33:50
合計ジャッジ時間 108,241 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,017 ms
102,792 KB
testcase_01 AC 992 ms
103,524 KB
testcase_02 AC 1,063 ms
102,396 KB
testcase_03 AC 960 ms
103,464 KB
testcase_04 AC 951 ms
102,440 KB
testcase_05 AC 956 ms
102,436 KB
testcase_06 AC 997 ms
104,192 KB
testcase_07 AC 1,047 ms
106,940 KB
testcase_08 AC 969 ms
102,356 KB
testcase_09 AC 993 ms
102,852 KB
testcase_10 AC 972 ms
104,576 KB
testcase_11 AC 1,113 ms
103,024 KB
testcase_12 AC 986 ms
102,324 KB
testcase_13 AC 1,016 ms
105,804 KB
testcase_14 AC 1,064 ms
105,220 KB
testcase_15 AC 988 ms
103,840 KB
testcase_16 AC 969 ms
103,132 KB
testcase_17 AC 1,043 ms
102,856 KB
testcase_18 AC 978 ms
101,956 KB
testcase_19 AC 962 ms
104,236 KB
testcase_20 AC 1,019 ms
105,080 KB
testcase_21 AC 990 ms
103,208 KB
testcase_22 AC 1,027 ms
104,376 KB
testcase_23 AC 995 ms
104,720 KB
testcase_24 AC 1,016 ms
103,232 KB
testcase_25 AC 1,044 ms
104,104 KB
testcase_26 AC 1,000 ms
103,560 KB
testcase_27 AC 981 ms
104,316 KB
testcase_28 AC 956 ms
102,864 KB
testcase_29 AC 1,018 ms
102,392 KB
testcase_30 AC 973 ms
103,300 KB
testcase_31 AC 971 ms
103,744 KB
testcase_32 AC 1,046 ms
105,988 KB
testcase_33 AC 955 ms
100,452 KB
testcase_34 AC 1,029 ms
104,316 KB
testcase_35 AC 1,010 ms
104,504 KB
testcase_36 AC 938 ms
102,448 KB
testcase_37 AC 1,013 ms
105,736 KB
testcase_38 AC 1,007 ms
104,064 KB
testcase_39 AC 995 ms
103,892 KB
testcase_40 AC 1,001 ms
104,664 KB
testcase_41 AC 994 ms
102,208 KB
testcase_42 AC 969 ms
103,632 KB
testcase_43 AC 980 ms
101,128 KB
testcase_44 AC 987 ms
102,520 KB
testcase_45 AC 964 ms
102,416 KB
testcase_46 AC 997 ms
101,360 KB
testcase_47 AC 1,019 ms
104,768 KB
testcase_48 AC 960 ms
102,160 KB
testcase_49 AC 1,060 ms
104,532 KB
testcase_50 AC 1,037 ms
104,968 KB
testcase_51 AC 1,015 ms
103,784 KB
testcase_52 AC 960 ms
103,672 KB
testcase_53 AC 929 ms
101,876 KB
testcase_54 AC 1,039 ms
105,316 KB
testcase_55 AC 997 ms
103,312 KB
testcase_56 AC 1,037 ms
103,480 KB
testcase_57 AC 1,051 ms
104,640 KB
testcase_58 AC 999 ms
104,396 KB
testcase_59 AC 1,082 ms
107,708 KB
testcase_60 AC 996 ms
104,232 KB
testcase_61 AC 956 ms
103,900 KB
testcase_62 AC 985 ms
103,352 KB
testcase_63 AC 973 ms
105,272 KB
testcase_64 AC 991 ms
101,920 KB
testcase_65 AC 1,051 ms
106,664 KB
testcase_66 AC 989 ms
102,820 KB
testcase_67 AC 1,021 ms
104,468 KB
testcase_68 AC 974 ms
104,624 KB
testcase_69 AC 1,034 ms
106,248 KB
testcase_70 AC 964 ms
102,332 KB
testcase_71 AC 1,003 ms
104,828 KB
testcase_72 AC 1,046 ms
106,068 KB
testcase_73 AC 971 ms
102,724 KB
testcase_74 AC 1,037 ms
105,952 KB
testcase_75 AC 1,019 ms
104,224 KB
testcase_76 AC 996 ms
103,728 KB
testcase_77 AC 1,045 ms
105,784 KB
testcase_78 AC 983 ms
103,712 KB
testcase_79 AC 995 ms
104,840 KB
testcase_80 AC 1,016 ms
102,904 KB
testcase_81 AC 986 ms
103,320 KB
testcase_82 AC 1,026 ms
104,380 KB
testcase_83 AC 971 ms
103,392 KB
testcase_84 AC 1,020 ms
102,684 KB
testcase_85 AC 990 ms
103,676 KB
testcase_86 AC 947 ms
101,704 KB
testcase_87 AC 1,004 ms
103,344 KB
testcase_88 AC 1,091 ms
102,840 KB
testcase_89 AC 978 ms
100,820 KB
testcase_90 AC 944 ms
100,832 KB
testcase_91 AC 999 ms
102,820 KB
testcase_92 AC 1,031 ms
104,620 KB
testcase_93 AC 963 ms
102,116 KB
testcase_94 AC 1,019 ms
104,280 KB
testcase_95 AC 949 ms
101,212 KB
testcase_96 AC 1,018 ms
102,276 KB
testcase_97 AC 988 ms
102,480 KB
testcase_98 AC 1,000 ms
107,208 KB
testcase_99 AC 1,084 ms
106,656 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)

s=set()
# スキル値, プレイヤーi, 出現チック
s.add((-10000000,-1,-1))
s.add((100000000,-1,-1))
pi=1

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] >100:
                s.discard(e)

    t_ans=set()
    for i in range(L[0]):
        # print(s)
        nowi=(L[i+1],pi,t)
        p[pi]=L[i+1]
        sorteds=sorted(list(s))
        target=bisect.bisect_right(sorteds,nowi)

        used=False

        for _t in list(t_ans):
            if abs(p[pi] - p[_t]) < 8:
                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])<10:
            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)

        pi+=1
    t+=1

    # print (t_ans)

    ans4print=[]
    ans4print_num=0
    for ans in t_ans:
        m=uf.members(ans)
        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()
0