結果
| 問題 |
No.43 野球の試合
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-23 22:17:31 |
| 言語 | Nim (2.2.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 880 bytes |
| コンパイル時間 | 3,500 ms |
| コンパイル使用メモリ | 67,120 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-01 10:39:21 |
| 合計ジャッジ時間 | 4,221 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 5 WA * 2 |
ソースコード
import sequtils,strutils,algorithm
let n = stdin.readLine().parseInt()
var S = newSeqWith(n,stdin.readLine)
for i in 1..<n:
if S[0][i] != '-' : continue
S[0][i] = 'o'
S[i][0] = 'x'
let win = S[0].count('o')
proc rank(S:seq[string]) : int =
let SI = toSeq(0..<n).mapIt((i:it,win:S[it].count('o')))
let I = SI.sortedByIt(-it.win).mapIt(it.i)
for i in 0..<n:
if I[i] == 0 : return i + 1
proc emb(S:seq[string],yets:seq[tuple[x,y:int]]) : seq[string] =
if yets.len == 0 : return S
let yet = yets[0]
var SA = S
SA[yet.x][yet.y] = 'o'
SA[yet.y][yet.x] = 'x'
SA = SA.emb(yets[1..^1])
var SB = S
SB[yet.x][yet.y] = 'x'
SB[yet.y][yet.x] = 'o'
SB = SB.emb(yets[1..^1])
if SA.rank < SB.rank : return SA
return SB
var yets = newSeq[tuple[x,y:int]]()
for x in 1..<n:
for y in (x+1)..<n:
if S[x][y] == '-': yets &= (x,y)
echo S.emb(yets).rank()