結果

問題 No.5004 Room Assignment
ユーザー negibose2020negibose2020
提出日時 2021-12-01 22:25:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,098 ms / 5,000 ms
コード長 3,537 bytes
コンパイル時間 748 ms
実行使用メモリ 107,232 KB
スコア 59,891,352
平均クエリ数 6868.30
最終ジャッジ日時 2021-12-01 22:27:27
合計ジャッジ時間 106,880 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,020 ms
105,048 KB
testcase_01 AC 1,072 ms
102,888 KB
testcase_02 AC 1,004 ms
103,872 KB
testcase_03 AC 996 ms
104,488 KB
testcase_04 AC 1,011 ms
104,132 KB
testcase_05 AC 966 ms
105,752 KB
testcase_06 AC 962 ms
101,836 KB
testcase_07 AC 1,029 ms
104,436 KB
testcase_08 AC 926 ms
103,748 KB
testcase_09 AC 970 ms
103,144 KB
testcase_10 AC 958 ms
103,624 KB
testcase_11 AC 969 ms
104,032 KB
testcase_12 AC 977 ms
104,092 KB
testcase_13 AC 948 ms
105,240 KB
testcase_14 AC 1,001 ms
101,476 KB
testcase_15 AC 1,003 ms
104,964 KB
testcase_16 AC 1,015 ms
104,772 KB
testcase_17 AC 951 ms
102,076 KB
testcase_18 AC 1,014 ms
105,556 KB
testcase_19 AC 960 ms
104,376 KB
testcase_20 AC 1,018 ms
102,672 KB
testcase_21 AC 931 ms
101,884 KB
testcase_22 AC 947 ms
101,776 KB
testcase_23 AC 1,014 ms
102,948 KB
testcase_24 AC 898 ms
101,764 KB
testcase_25 AC 1,023 ms
101,460 KB
testcase_26 AC 1,019 ms
107,232 KB
testcase_27 AC 948 ms
100,872 KB
testcase_28 AC 967 ms
103,456 KB
testcase_29 AC 1,023 ms
104,096 KB
testcase_30 AC 960 ms
101,300 KB
testcase_31 AC 981 ms
104,236 KB
testcase_32 AC 953 ms
102,424 KB
testcase_33 AC 971 ms
103,372 KB
testcase_34 AC 1,008 ms
104,524 KB
testcase_35 AC 976 ms
103,680 KB
testcase_36 AC 1,031 ms
107,060 KB
testcase_37 AC 952 ms
101,104 KB
testcase_38 AC 1,086 ms
102,308 KB
testcase_39 AC 897 ms
101,928 KB
testcase_40 AC 1,080 ms
102,808 KB
testcase_41 AC 1,033 ms
105,048 KB
testcase_42 AC 1,003 ms
105,252 KB
testcase_43 AC 991 ms
103,832 KB
testcase_44 AC 988 ms
105,576 KB
testcase_45 AC 991 ms
104,580 KB
testcase_46 AC 1,027 ms
105,536 KB
testcase_47 AC 956 ms
101,620 KB
testcase_48 AC 1,080 ms
102,200 KB
testcase_49 AC 1,010 ms
103,492 KB
testcase_50 AC 1,055 ms
102,692 KB
testcase_51 AC 979 ms
103,316 KB
testcase_52 AC 1,015 ms
100,784 KB
testcase_53 AC 1,011 ms
105,116 KB
testcase_54 AC 1,009 ms
101,736 KB
testcase_55 AC 1,031 ms
104,452 KB
testcase_56 AC 1,004 ms
102,688 KB
testcase_57 AC 973 ms
103,692 KB
testcase_58 AC 945 ms
101,716 KB
testcase_59 AC 950 ms
101,488 KB
testcase_60 AC 979 ms
104,440 KB
testcase_61 AC 936 ms
102,492 KB
testcase_62 AC 996 ms
103,748 KB
testcase_63 AC 966 ms
103,260 KB
testcase_64 AC 1,005 ms
104,340 KB
testcase_65 AC 987 ms
103,368 KB
testcase_66 AC 990 ms
102,244 KB
testcase_67 AC 948 ms
103,864 KB
testcase_68 AC 1,011 ms
105,476 KB
testcase_69 AC 1,010 ms
105,352 KB
testcase_70 AC 965 ms
103,436 KB
testcase_71 AC 963 ms
101,400 KB
testcase_72 AC 974 ms
101,852 KB
testcase_73 AC 966 ms
102,056 KB
testcase_74 AC 981 ms
104,612 KB
testcase_75 AC 1,058 ms
105,404 KB
testcase_76 AC 920 ms
103,900 KB
testcase_77 AC 1,048 ms
105,208 KB
testcase_78 AC 969 ms
103,344 KB
testcase_79 AC 991 ms
103,840 KB
testcase_80 AC 900 ms
102,140 KB
testcase_81 AC 986 ms
106,160 KB
testcase_82 AC 945 ms
102,864 KB
testcase_83 AC 944 ms
103,360 KB
testcase_84 AC 968 ms
102,608 KB
testcase_85 AC 957 ms
103,236 KB
testcase_86 AC 1,019 ms
103,992 KB
testcase_87 AC 961 ms
102,444 KB
testcase_88 AC 1,098 ms
101,264 KB
testcase_89 AC 905 ms
102,924 KB
testcase_90 AC 995 ms
104,108 KB
testcase_91 AC 1,006 ms
105,452 KB
testcase_92 AC 988 ms
103,264 KB
testcase_93 AC 930 ms
103,560 KB
testcase_94 AC 1,002 ms
102,852 KB
testcase_95 AC 995 ms
104,392 KB
testcase_96 AC 985 ms
105,448 KB
testcase_97 AC 1,004 ms
104,460 KB
testcase_98 AC 993 ms
102,616 KB
testcase_99 AC 992 ms
103,364 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] >200:
                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]) < 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)

        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