結果

問題 No.43 野球の試合
ユーザー tamakorontamakoron
提出日時 2016-12-03 22:33:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,269 bytes
コンパイル時間 727 ms
コンパイル使用メモリ 75,428 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-05 15:55:19
合計ジャッジ時間 1,253 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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]);
  }
  for (int i = 0; i < n; ++i)
  {
    if (m[0][i] == '-')
    {
      m[0][i] = 'o';
    }
  }
  for (int i = 0; i < n; ++i)
  {
    if (m[i][0] == '-')
    {
      m[i][0] = 'x';
    }
  }
  printf("%d\n", call(0, 0));
}
0