結果
| 問題 |
No.1169 Row and Column and Diagonal
|
| コンテスト | |
| ユーザー |
c-yan
|
| 提出日時 | 2020-08-14 23:10:38 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,008 bytes |
| コンパイル時間 | 146 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 18,336 KB |
| 最終ジャッジ日時 | 2024-10-10 16:36:52 |
| 合計ジャッジ時間 | 4,270 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 RE * 1 |
| other | AC * 4 TLE * 1 -- * 8 |
ソースコード
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)
N = int(input())
result = [[-1] * N for _ in range(N)]
usedT = [[False] * N for _ in range(N)]
usedY = [[False] * N for _ in range(N)]
def dfs(i, j):
if result[i][j] != -1:
if i == N - 1 and j == N - 1:
return True
elif j == N - 1:
return dfs(i + 1, 0)
else:
return dfs(i, j + 1)
for k in range(N):
if usedT[j][k]:
continue
if usedY[i][k]:
continue
result[i][j] = k + 1
usedT[j][k] = True
usedY[i][k] = True
if j == N - 1:
t = dfs(i + 1, 0)
else:
t = dfs(i, j + 1)
if t:
return True
else:
result[i][j] = -1
usedT[j][k] = False
usedY[i][k] = False
return False
for i in range(N):
result[i][i] = i + 1
usedT[i][i] = True
usedY[i][i] = True
dfs(0, 1)
for i in range(N):
print(*result[i])
c-yan