結果

問題 No.5024 魔法少女うなと宝集め
コンテスト
ユーザー aruru88DX
提出日時 2026-05-02 19:49:16
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,978 ms / 2,000 ms
コード長 1,260 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 132 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 84,232 KB
スコア 1,645,291
最終ジャッジ日時 2026-05-02 19:51:00
合計ジャッジ時間 102,451 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline
import random
import time

N, T = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]

best_val = -1
for i in range(N):
    for j in range(N):
        if A[i][j] > best_val:
            best_val = A[i][j]
            Sx, Sy = i, j

START = time.time()
LIMIT = 1.93

best_score = 0
best_path = []

while time.time() - START < LIMIT:
    visited = [[False]*N for _ in range(N)]
    x, y = Sx, Sy
    visited[x][y] = True

    path = [(x, y)]
    score = A[x][y]

    for k in range(T-1):
        cand = []
        for dx, dy in [(0,1),(1,0),(0,-1),(-1,0)]:
            nx, ny = x+dx, y+dy
            if 0 <= nx < N and 0 <= ny < N and not visited[nx][ny]:
                cand.append((A[nx][ny], nx, ny))

        if not cand:
            break

        cand.sort(reverse=True)
        p =p = k / T
        if random.random() < p:
            _, nx, ny = cand[0]
        else:
            _, nx, ny = random.choice(cand[:min(3,len(cand))])

        visited[nx][ny] = True
        path.append((nx, ny))
        score += A[nx][ny]
        x, y = nx, ny

    if score > best_score:
        best_score = score
        best_path = path

print(len(best_path))

for x, y in best_path:
    print(x, y)
0