結果

問題 No.5004 Room Assignment
ユーザー negibose2020negibose2020
提出日時 2021-12-03 15:35:47
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 6,329 bytes
コンパイル時間 209 ms
実行使用メモリ 106,608 KB
スコア 1,119,775
平均クエリ数 87661.00
最終ジャッジ日時 2021-12-03 15:39:23
合計ジャッジ時間 212,672 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,376 ms
104,020 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 4,989 ms
103,196 KB
testcase_07 AC 4,976 ms
103,304 KB
testcase_08 RE -
testcase_09 TLE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 3,374 ms
103,324 KB
testcase_13 RE -
testcase_14 AC 4,110 ms
102,340 KB
testcase_15 TLE -
testcase_16 RE -
testcase_17 AC 4,975 ms
105,884 KB
testcase_18 RE -
testcase_19 AC 4,845 ms
102,900 KB
testcase_20 AC 3,387 ms
103,068 KB
testcase_21 TLE -
testcase_22 AC 4,475 ms
104,360 KB
testcase_23 AC 3,873 ms
105,540 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 3,754 ms
104,552 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 3,899 ms
102,824 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 AC 3,157 ms
104,052 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 AC 3,009 ms
102,128 KB
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 AC 4,410 ms
105,092 KB
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 AC 3,514 ms
104,492 KB
testcase_53 RE -
testcase_54 AC 3,431 ms
104,008 KB
testcase_55 AC 3,410 ms
102,340 KB
testcase_56 AC 4,721 ms
104,064 KB
testcase_57 AC 3,498 ms
105,308 KB
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 TLE -
testcase_64 TLE -
testcase_65 AC 4,981 ms
106,348 KB
testcase_66 AC 3,294 ms
104,692 KB
testcase_67 AC 2,947 ms
103,812 KB
testcase_68 AC 4,859 ms
103,664 KB
testcase_69 RE -
testcase_70 RE -
testcase_71 TLE -
testcase_72 AC 3,673 ms
104,636 KB
testcase_73 TLE -
testcase_74 TLE -
testcase_75 RE -
testcase_76 RE -
testcase_77 RE -
testcase_78 AC 4,997 ms
104,052 KB
testcase_79 RE -
testcase_80 RE -
testcase_81 RE -
testcase_82 AC 4,987 ms
104,472 KB
testcase_83 RE -
testcase_84 RE -
testcase_85 RE -
testcase_86 AC 3,789 ms
104,380 KB
testcase_87 TLE -
testcase_88 RE -
testcase_89 RE -
testcase_90 RE -
testcase_91 AC 4,474 ms
104,044 KB
testcase_92 AC 3,119 ms
102,844 KB
testcase_93 RE -
testcase_94 TLE -
testcase_95 RE -
testcase_96 AC 4,998 ms
106,608 KB
testcase_97 AC 4,954 ms
106,524 KB
testcase_98 RE -
testcase_99 AC 3,507 ms
104,212 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()
# score,minskill,maxskill,x,nowe
scores=[[0,0,100,0,1] for i in range (N+1)]
s=set()
# スキル値, プレイヤーi, 出現チック
s.add((-10000000,-1,-1))
s.add((100000000,-1,-1))
pi=1
t_ans=set()


def clc_score(num,minskil,maxskil,x,y):
    a=(num*(num-1)//2) * (200-(maxskil-minskil)*(maxskil*minskil)) - (num*(num-1)//2)*(y-x)
    return max(a,0)

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
    if L[0] == 0:
        t+=1
        print(0)
        sys.stdout.flush()
        continue

    
    if t %30 ==0:
        for e in list(s):
            if e == (-10000000,-1,-1) or e ==(100000000,-1,-1):
                continue
            else:
                if t - e[2] >100 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:
                score,minskill,maxskill,x,sz=scores[_t]
                
                # sz=len(uf.members(_t))

                if sz < 4:
                    _score = clc_score(sz+1,min(minskill,p[pi]),max(maxskill,p[pi]),x,t)
                    if _score > score:
                        uf.union(_t, pi)
                        t_ans.add(pi)
                        used = True
                        scores[_t] = [_score, min(minskill,p[pi]), max(maxskill,p[pi]),x,sz+1] 
                        scores[pi] = [_score, min(minskill,p[pi]), max(maxskill,p[pi]),x,sz+1] 
                        break

        if abs(sorteds[target-1][0] - L[i+1])<3:
            sz1 = len(uf.members(sorteds[target-1][1]))
            score1,minskill1,maxskill1,x1,sz1 = scores[sorteds[target-1][1]]
            sz2 = len(uf.members(pi))
            score2,minskill2,maxskill2,x2,sz2 = scores[pi]

            if sz1 + sz2 <= 4:
                _score = clc_score((sz1+sz2),min(minskill1,minskill2),max(maxskill1,maxskill2),min(x1,x2),t)
                if _score > score1 + score2:
                    uf.union(pi, sorteds[target-1][1])
                    t_ans.add(pi)
                    used = True
                    scores[sorteds[target-1][1]] = [_score, min(minskill1,minskill2),max(maxskill1,maxskill2),min(x1,x2),(sz1+sz2)]
                    scores[pi] = [_score, min(minskill1,minskill2),max(maxskill1,maxskill2),min(x1,x2),(sz1+sz2)]

                # s.discard(sorteds[target-1])

        if abs(sorteds[target][0] - L[i+1])<3:
            sz1 = len(uf.members(sorteds[target][1]))
            score1,minskill1,maxskill1,x1,sz1 = scores[sorteds[target][1]]
            sz2 = len(uf.members(pi))
            score2,minskill2,maxskill2,x2,sz2 = scores[pi]
            if sz1 + sz2 <= 4:
                _score = clc_score((sz1+sz2),min(minskill1,minskill2),max(maxskill1,maxskill2),min(x1,x2),t)
                if _score > score1 + score2:
                    uf.union(pi, sorteds[target][1])
                    t_ans.add(pi)
                    used = True
                    scores[sorteds[target][1]] = [_score, min(minskill1,minskill2),max(maxskill1,maxskill2),min(x1,x2),(sz1+sz2)]
                    scores[pi] = [_score, min(minskill1,minskill2),max(maxskill1,maxskill2),min(x1,x2),(sz1+sz2)]

                # 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