結果

問題 No.5004 Room Assignment
ユーザー negibose2020negibose2020
提出日時 2021-12-02 00:35:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,778 ms / 5,000 ms
コード長 4,147 bytes
コンパイル時間 261 ms
実行使用メモリ 105,708 KB
スコア 127,422,254
平均クエリ数 14718.17
最終ジャッジ日時 2021-12-02 00:38:50
合計ジャッジ時間 199,552 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,923 ms
103,616 KB
testcase_01 AC 1,767 ms
103,220 KB
testcase_02 AC 1,799 ms
103,320 KB
testcase_03 AC 1,918 ms
103,820 KB
testcase_04 AC 1,871 ms
102,872 KB
testcase_05 AC 1,899 ms
103,536 KB
testcase_06 AC 1,916 ms
101,908 KB
testcase_07 AC 1,759 ms
102,488 KB
testcase_08 AC 1,829 ms
102,028 KB
testcase_09 AC 2,704 ms
103,016 KB
testcase_10 AC 1,742 ms
103,416 KB
testcase_11 AC 1,888 ms
103,108 KB
testcase_12 AC 1,829 ms
104,408 KB
testcase_13 AC 2,551 ms
104,132 KB
testcase_14 AC 1,866 ms
103,260 KB
testcase_15 AC 1,880 ms
101,768 KB
testcase_16 AC 1,790 ms
102,028 KB
testcase_17 AC 1,783 ms
103,316 KB
testcase_18 AC 1,782 ms
103,252 KB
testcase_19 AC 1,904 ms
102,612 KB
testcase_20 AC 1,927 ms
102,700 KB
testcase_21 AC 1,977 ms
103,612 KB
testcase_22 AC 1,865 ms
101,580 KB
testcase_23 AC 1,790 ms
103,380 KB
testcase_24 AC 1,902 ms
103,596 KB
testcase_25 AC 1,723 ms
103,336 KB
testcase_26 AC 1,701 ms
102,524 KB
testcase_27 AC 1,800 ms
103,172 KB
testcase_28 AC 1,795 ms
102,484 KB
testcase_29 AC 1,797 ms
102,656 KB
testcase_30 AC 1,682 ms
102,240 KB
testcase_31 AC 2,078 ms
102,944 KB
testcase_32 AC 1,699 ms
102,052 KB
testcase_33 AC 1,720 ms
103,588 KB
testcase_34 AC 1,841 ms
102,444 KB
testcase_35 AC 1,921 ms
102,496 KB
testcase_36 AC 1,876 ms
105,304 KB
testcase_37 AC 1,862 ms
103,492 KB
testcase_38 AC 1,938 ms
103,448 KB
testcase_39 AC 2,008 ms
103,312 KB
testcase_40 AC 1,733 ms
102,380 KB
testcase_41 AC 1,857 ms
103,288 KB
testcase_42 AC 2,424 ms
104,008 KB
testcase_43 AC 1,834 ms
102,680 KB
testcase_44 AC 1,953 ms
102,536 KB
testcase_45 AC 2,005 ms
104,304 KB
testcase_46 AC 1,880 ms
103,392 KB
testcase_47 AC 1,752 ms
102,768 KB
testcase_48 AC 1,732 ms
102,708 KB
testcase_49 AC 2,659 ms
103,672 KB
testcase_50 AC 1,749 ms
103,964 KB
testcase_51 AC 1,857 ms
104,920 KB
testcase_52 AC 1,843 ms
102,048 KB
testcase_53 AC 1,861 ms
101,632 KB
testcase_54 AC 1,851 ms
104,032 KB
testcase_55 AC 1,725 ms
102,580 KB
testcase_56 AC 1,876 ms
102,376 KB
testcase_57 AC 1,896 ms
104,268 KB
testcase_58 AC 1,801 ms
103,136 KB
testcase_59 AC 1,813 ms
103,360 KB
testcase_60 AC 1,925 ms
104,848 KB
testcase_61 AC 2,676 ms
105,708 KB
testcase_62 AC 1,851 ms
102,812 KB
testcase_63 AC 2,552 ms
104,296 KB
testcase_64 AC 1,902 ms
103,308 KB
testcase_65 AC 2,778 ms
104,560 KB
testcase_66 AC 1,899 ms
104,240 KB
testcase_67 AC 1,977 ms
102,568 KB
testcase_68 AC 1,753 ms
102,808 KB
testcase_69 AC 1,751 ms
102,396 KB
testcase_70 AC 1,889 ms
105,168 KB
testcase_71 AC 1,896 ms
102,960 KB
testcase_72 AC 1,768 ms
103,508 KB
testcase_73 AC 1,935 ms
103,248 KB
testcase_74 AC 1,909 ms
102,596 KB
testcase_75 AC 1,798 ms
103,176 KB
testcase_76 AC 1,748 ms
103,336 KB
testcase_77 AC 1,956 ms
103,752 KB
testcase_78 AC 2,368 ms
101,900 KB
testcase_79 AC 1,908 ms
103,440 KB
testcase_80 AC 1,864 ms
101,776 KB
testcase_81 AC 1,938 ms
103,516 KB
testcase_82 AC 1,877 ms
103,136 KB
testcase_83 AC 1,895 ms
101,808 KB
testcase_84 AC 1,773 ms
104,300 KB
testcase_85 AC 2,566 ms
103,800 KB
testcase_86 AC 1,834 ms
102,368 KB
testcase_87 AC 1,816 ms
103,488 KB
testcase_88 AC 1,787 ms
104,120 KB
testcase_89 AC 1,924 ms
103,456 KB
testcase_90 AC 2,121 ms
102,400 KB
testcase_91 AC 1,743 ms
105,004 KB
testcase_92 AC 1,930 ms
104,760 KB
testcase_93 AC 1,851 ms
103,332 KB
testcase_94 AC 1,758 ms
102,932 KB
testcase_95 AC 1,884 ms
103,904 KB
testcase_96 AC 2,036 ms
103,664 KB
testcase_97 AC 1,785 ms
103,632 KB
testcase_98 AC 1,750 ms
102,784 KB
testcase_99 AC 1,760 ms
103,600 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)


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] >250:
                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]) < 4:
                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)

        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
            ans4print.append(mls)
        else:
            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