結果
| 問題 | No.5024 魔法少女うなと宝集め |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-02 19:32:58 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,291 bytes |
| 記録 | |
| コンパイル時間 | 268 ms |
| コンパイル使用メモリ | 85,760 KB |
| 実行使用メモリ | 84,696 KB |
| スコア | 0 |
| 最終ジャッジ日時 | 2026-05-02 19:34:47 |
| 合計ジャッジ時間 | 105,680 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 50 |
ソースコード
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.995
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 _ 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 =0.3+0.5*((time.time() - START) / LIMIT)
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)