結果
問題 | No.43 野球の試合 |
ユーザー |
|
提出日時 | 2015-02-06 22:25:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 7 ms / 5,000 ms |
コード長 | 1,227 bytes |
コンパイル時間 | 728 ms |
コンパイル使用メモリ | 71,552 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-23 10:21:14 |
合計ジャッジ時間 | 1,247 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
#include <iostream>#include <cstdio>#include <vector>#include <algorithm>#include <utility>using namespace std;int n_games;vector< pair<int, int> > games;int get_rank(vector<int> vec, int stat) {for (int i = 0; i < n_games; i++) {if ((stat >> i) & 1) {vec[ games[i].first ]++;} else {vec[ games[i].second ]++;}}int wins0 = vec[0];sort(vec.begin(), vec.end(), greater<int>());vec.erase(unique(vec.begin(), vec.end()), vec.end());for (int i = 0; i < vec.size(); i++) {if (vec[i] == wins0) {return i + 1;}}return -1;}int main() {int n;cin >> n;vector<string> result(n);for (int i = 0; i < n; i++) {cin >> result[i];}games.clear();vector<int> wins(n, 0);for (int i = 0; i < n; i++) {for (int j = i + 1; j < n; j++) {switch (result[i][j]) {case '-':games.push_back(make_pair(i, j));break;case 'o':wins[i]++;break;case 'x':wins[j]++;break;default:break;}}}int ans = 1000;n_games = games.size();if (n_games == 0) {ans = get_rank(wins, 0);} else {for (int i = (1 << n_games) - 1; i >= 0; i--) {ans = min(ans, get_rank(wins, i));}}cout << ans << endl;return 0;}