結果
問題 |
No.43 野球の試合
|
ユーザー |
|
提出日時 | 2016-03-23 23:08:08 |
言語 | Ruby (3.4.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,010 bytes |
コンパイル時間 | 56 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 24,576 KB |
最終ジャッジ日時 | 2024-10-01 21:40:14 |
合計ジャッジ時間 | 9,225 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 3 TLE * 1 -- * 3 |
コンパイルメッセージ
Syntax OK
ソースコード
def sol n,d,w,c if c == 0 return w.uniq.sort.reverse.index(w[0]) + 1 end ans = n n.times{|i| (i + 1).upto(n - 1){|j| if d[i][j] == '-' d[i][j] = 'o' d[j][i] = 'x' w[i] += 1 ans = [ans, sol(n,d,w,c - 2)].min d[i][j] = 'x' d[j][i] = 'o' w[i] -= 1 w[j] += 1 ans = [ans, sol(n,d,w,c - 2)].min d[i][j] = '-' d[j][i] = '-' w[j] -= 1 end } } return ans end n = gets.to_i d = Array.new(n) w = Array.new(n,0) c = 0 n.times{|i| d[i] = gets.chomp.split('') n.times{|j| if d[i][j] == 'o' w[i] += 1 elsif d[i][j] == '-' c += 1 end } } 1.upto(n - 1){|i| if d[0][i] == '-' d[0][i] = 'o' d[i][0] = 'x' w[0] += 1 c -= 2 end } p sol(n,d,w,c)