結果
問題 | No.43 野球の試合 |
ユーザー |
|
提出日時 | 2016-03-22 21:04:55 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 13 ms / 5,000 ms |
コード長 | 1,851 bytes |
コンパイル時間 | 1,037 ms |
コンパイル使用メモリ | 82,764 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-01 13:08:06 |
合計ジャッジ時間 | 1,590 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <cmath>int main() {std::ios::sync_with_stdio(false);std::cin.tie(0);class Pos{public:int row;int col;Pos(int i, int j) : row(i), col(j) {}};int n;std::cin >> n;std::vector<std::vector<int>> s(n, std::vector<int>(n));std::vector<std::vector<int>> evaluation(n, std::vector<int>(n));std::vector<Pos> position;std::vector<int> point(n, 0);int noBattleNum = 0;for (int i = 0; i < n; ++i) {for (int j = 0; j < n; ++j) {char c;std::cin >> c;switch (c) {case '#': s[i][j] = 99; break;case 'o': s[i][j] = 1; break;case 'x': s[i][j] = -1; break;case '-':s[i][j] = 0;if (i < j) {++noBattleNum;position.push_back(Pos(i, j));}break;}}}int min = 10;for (int k = 0; k < std::pow(2, noBattleNum); ++k) {int tmp = k;evaluation = s;for (int i = 0; i < noBattleNum; ++i) {if (tmp % 2 == 1) {evaluation[position[i].col][position[i].row] = 1;evaluation[position[i].row][position[i].col] = -1;}else {evaluation[position[i].col][position[i].row] = -1;evaluation[position[i].row][position[i].col] = 1;}tmp /= 2;}for (int i = 0; i < n; ++i) {int sum = 0;for (int j = 0; j < n; ++j) {if (evaluation[i][j] == 99) continue;sum += evaluation[i][j];}point[i] = sum;}int pointZero = point[0];std::sort(point.begin(), point.end());std::reverse(point.begin(), point.end());std::vector<int> rank;for (int i = 0; i < n; ++i) {if (std::find(rank.begin(), rank.end(), point[i]) == rank.end()) {rank.push_back(point[i]);}}for (int i = 0; i < rank.size(); ++i) {if (rank[i] == pointZero) {min = (min > i + 1) ? i + 1 : min;}}}std::cout << min << "\n";return 0;}