結果

問題 No.5019 Hakai Project
ユーザー hirayuu_ychirayuu_yc
提出日時 2023-10-20 20:53:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 299 ms / 3,000 ms
コード長 3,129 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 79,656 KB
スコア 1,610,764,944
最終ジャッジ日時 2023-11-17 09:32:01
合計ジャッジ時間 18,768 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 291 ms
78,788 KB
testcase_01 AC 257 ms
78,408 KB
testcase_02 AC 245 ms
78,260 KB
testcase_03 AC 249 ms
78,284 KB
testcase_04 AC 271 ms
79,036 KB
testcase_05 AC 250 ms
78,420 KB
testcase_06 AC 241 ms
77,964 KB
testcase_07 AC 270 ms
78,668 KB
testcase_08 AC 244 ms
78,388 KB
testcase_09 AC 249 ms
78,260 KB
testcase_10 AC 277 ms
78,768 KB
testcase_11 AC 248 ms
78,360 KB
testcase_12 AC 287 ms
78,768 KB
testcase_13 AC 263 ms
78,344 KB
testcase_14 AC 271 ms
79,044 KB
testcase_15 AC 252 ms
78,356 KB
testcase_16 AC 268 ms
78,440 KB
testcase_17 AC 244 ms
77,964 KB
testcase_18 AC 242 ms
77,964 KB
testcase_19 AC 271 ms
78,944 KB
testcase_20 AC 257 ms
78,420 KB
testcase_21 AC 267 ms
78,648 KB
testcase_22 AC 251 ms
78,400 KB
testcase_23 AC 258 ms
78,424 KB
testcase_24 AC 257 ms
78,404 KB
testcase_25 AC 265 ms
78,380 KB
testcase_26 AC 256 ms
77,964 KB
testcase_27 AC 245 ms
78,284 KB
testcase_28 AC 284 ms
78,752 KB
testcase_29 AC 242 ms
78,480 KB
testcase_30 AC 259 ms
78,524 KB
testcase_31 AC 267 ms
78,524 KB
testcase_32 AC 281 ms
78,748 KB
testcase_33 AC 260 ms
78,408 KB
testcase_34 AC 240 ms
77,964 KB
testcase_35 AC 244 ms
77,964 KB
testcase_36 AC 262 ms
78,464 KB
testcase_37 AC 261 ms
78,712 KB
testcase_38 AC 230 ms
77,964 KB
testcase_39 AC 264 ms
78,432 KB
testcase_40 AC 249 ms
77,836 KB
testcase_41 AC 257 ms
78,420 KB
testcase_42 AC 280 ms
78,768 KB
testcase_43 AC 248 ms
78,276 KB
testcase_44 AC 241 ms
77,964 KB
testcase_45 AC 246 ms
77,964 KB
testcase_46 AC 251 ms
78,460 KB
testcase_47 AC 257 ms
78,404 KB
testcase_48 AC 299 ms
79,656 KB
testcase_49 AC 255 ms
78,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy

N,M=map(int,input().split())
A=[]
for i in range(N):
    A.append(list(input()))
bomb=[]
maxi=0
num=0
for i in range(M):
    C,L=map(int,input().split())
    bomb.append([C,[]])
    if maxi<L:
        maxi=L
        num=i
    for j in range(L):
        bomb[-1][-1].append(tuple(map(int,input().split())))
cnt=0
am=0
plus=-1
posx=0
posy=0
ans=[]
for a in range(3):
    for b in range(3):
        lf=a*17
        ri=min(50,17+lf)
        up=b*17
        if a%2==1:
            up=(2-b)*17
        dn=min(50,17+up)
        use=[]
        x=-1
        y=-1
        near=998244353
        for i in range(N):
            for j in range(N):
                if A[i][j]=="@":
                    if near>(abs(posx-i)+abs(posy-j))*(1+(not(up<=i<dn and lf<=j<ri))):
                        near=(abs(posx-i)+abs(posy-j))*(1+(not(up<=i<dn and lf<=j<ri)))
                        x=i
                        y=j
        if x==-1:
            x=posx
            y=posy
            if plus==-1:
                plus=cnt
        for i in range(x-posx):
            ans.append([1,"D"])
        for i in range(y-posy):
            ans.append([1,"R"])
        for i in range(posx-x):
            ans.append([1,"U"])
        for i in range(posy-y):
            ans.append([1,"L"])
        while True:
            maxi=0
            xp=-1
            yp=-1
            for i in range(up,dn):
                for j in range(lf,ri):
                    cnt=0
                    for k,l in bomb[num][1]:
                        if up<=i+k<dn and lf<=j+l<ri:
                            if A[i+k][j+l]!=".":
                                cnt+=1
                    if cnt>maxi:
                        maxi=cnt
                        xp=i
                        yp=j
            if xp==-1:
                break
            use.append((xp,yp))
            for k,l in bomb[num][1]:
                if 0<=xp+k<N and 0<=yp+l<N:
                    A[xp+k][yp+l]="."
        if plus==-1:
            for i in range(len(use)):
                ans.append([2,num+1])
        else:
            am+=len(use)
        used=set()
        for i in range(len(use)):
            go=-1
            near=998244353
            for j in range(len(use)):
                if j in used:
                    continue
                if near>abs(x-use[j][0])+abs(y-use[j][1]):
                    near=abs(x-use[j][0])+abs(y-use[j][1])
                    go=j
            for i in range(use[go][0]-x):
                ans.append([1,"D"])
            for i in range(x-use[go][0]):
                ans.append([1,"U"])
            for i in range(use[go][1]-y):
                ans.append([1,"R"])
            for i in range(y-use[go][1]):
                ans.append([1,"L"])
            x=use[go][0]
            y=use[go][1]
            ans.append([3,num+1])
            used.add(go)
        posx=x
        posy=y
        cnt+=1
print(len(ans)+am)
n=0
for i,j in enumerate(ans):
    if j[0]!=2:
        if ans[i-1][0]==2:
            if n==plus:
                for i in range(am):
                    print(2,num+1)
            n+=1
    print(*j)
0