結果

問題 No.43 野球の試合
ユーザー tamakorontamakoron
提出日時 2016-12-03 22:36:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,079 bytes
コンパイル時間 1,252 ms
コンパイル使用メモリ 66,344 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 10:27:47
合計ジャッジ時間 1,344 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

char m[9][9];
vector<int> win;
int n;

int calc()
{
  vector<int> copy = win;
  sort(copy.begin() + 1, copy.end());
  int rank = 1;
  int score = win[0];
  for (int i = 1; i < n; ++i)
  {
    if (copy[i] > score && copy[i - 1] != copy[i])
      ++rank;
  }
  return rank;
}

int call(int x, int y)
{
  if (x >= n)
  {
    x = ++y;
    if (y >= n)
    {
      return calc();
    }
  }
  if (m[x][y] == 'o')
  {
    ++win[x];
    int ret = call(x + 1, y);
    --win[x];
    return ret;
  }
  if (m[x][y] == 'x')
  {
    ++win[y];
    int ret = call(x + 1, y);
    --win[y];
    return ret;
  }
  if (m[x][y] == '-')
  {
    ++win[x];
    int win_rank = call(x + 1, y);
    --win[x];
    ++win[y];
    int lose_rank = call(x + 1, y);
    --win[y];
    return win_rank > lose_rank ? lose_rank : win_rank;
  }
  return call(x + 1, y);
}

int main()
{
  cin >> n;
  win = vector<int>(n, 0);
  for (int i = 0; i < n; ++i)
  {
    scanf("%s", m[i]);
  }
  printf("%d\n", call(0, 0));
}
0