結果
問題 | No.43 野球の試合 |
ユーザー |
![]() |
提出日時 | 2016-07-29 02:11:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 13 ms / 5,000 ms |
コード長 | 1,256 bytes |
コンパイル時間 | 624 ms |
コンパイル使用メモリ | 71,708 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 18:18:51 |
合計ジャッジ時間 | 1,421 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
#include <iostream> #include <vector> #include <utility> #include <set> using namespace std; typedef pair<int, int> PII; const int kMaxN = 6; string s[kMaxN]; int N; vector<PII> matchs; int Judge() { vector<int> win(N, 0); for (int r = 0; r < N; r++) { for (int c = 0; c < N; c++) { if (s[r][c] == 'o') win[r]++; } } set<int> win_set; for (int i = 0; i < N; i++) { win_set.insert(win[i]); } int rank = 1; for (auto it = win_set.rbegin(); it != win_set.rend(); it++) { if (win[0] == *it) return rank; rank++; } return rank; } int DFS(int index) { if (index == matchs.size()) { return Judge(); } PII match = matchs[index]; int row = match.first, col = match.second, rank = N; s[row][col] = 'o'; s[col][row] = 'x'; rank = min(rank, DFS(index + 1)); s[row][col] = 'x'; s[col][row] = 'o'; rank = min(rank, DFS(index + 1)); return rank; } int main() { cin >> N; for (int r = 0; r < N; r++) { cin >> s[r]; for (int c = 0; c < r; c++) { if (s[r][c] == '-') { matchs.push_back(PII(r, c)); } } } cout << DFS(0) << endl; return 0; }