結果
問題 |
No.43 野球の試合
|
ユーザー |
|
提出日時 | 2019-01-23 22:25:50 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 54 ms / 5,000 ms |
コード長 | 850 bytes |
コンパイル時間 | 3,466 ms |
コンパイル使用メモリ | 66,664 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 10:39:29 |
合計ジャッジ時間 | 4,105 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
import sequtils,strutils,algorithm let n = stdin.readLine().parseInt() var S = newSeqWith(n,stdin.readLine) 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) if I[0].i == 0 : return 1 var rank = 1 for i in 1..<n: if I[i].win != I[i-1].win : rank += 1 if I[i].i == 0 : return rank 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 0..<n: for y in (x+1)..<n: if S[x][y] == '-': yets &= (x,y) echo S.emb(yets).rank()