結果

問題 No.43 野球の試合
ユーザー not_522not_522
提出日時 2015-07-17 09:05:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 761 bytes
コンパイル時間 1,253 ms
コンパイル使用メモリ 153,080 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 16:55:23
合計ジャッジ時間 2,027 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 10 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int solve(vector<string>& s, int i, int j) {
  int n = s.size();
  if (i == n) {
    for (int y = 0; y < n; ++y) {
      for (int x = y + 1; x < n; ++x) s[y][x] = s[x][y] ^ 'o' ^ 'x';
    }
    set<int> w;
    for (const auto& i : s) w.insert(count(i.begin(), i.end(), 'x'));
    return distance(w.begin(), w.find(count(s[0].begin(), s[0].end(), 'x'))) + 1;
  }
  if (i == j) return solve(s, i + 1, 0);
  if (s[i][j] != '-') return solve(s, i, j + 1);
  s[i][j] = 'o';
  int res = solve(s, i, j + 1);
  s[i][j] = 'x';
  res = min(res, solve(s, i, j + 1));
  s[i][j] = '-';
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (auto& i : s) cin >> i;
  cout << solve(s, 0, 0) << endl;
}
0