結果

問題 No.43 野球の試合
ユーザー HimatsubushinHimatsubushin
提出日時 2021-03-09 16:09:19
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,373 bytes
コンパイル時間 1,525 ms
コンパイル使用メモリ 31,744 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-19 20:16:17
合計ジャッジ時間 2,279 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int check(int[7][7], int, int);
void swap(int*, int*);

int main(int argc, const char * argv[]) {
  int i, j, n;
  int s[7][7];
  char d[7];

  scanf("%d", &n);
  for (j = 0; j < n; j++) {
    scanf("%s", d);
    for (i = 0; i < n; i++) {
      if (d[i] == '-')
        s[j][i] = 0;
      else if (d[i] == 'x')
        s[j][i] = -1;
      else if (d[i] == 'o')
        s[j][i] = 1;
      else
        s[j][i] = 9;
    }
  }

  i = check(s, n, 1);
  j = check(s, n, -1);

  if (i < j)
    printf("%d\n", i);
  else
    printf("%d\n", j);

  return EXIT_SUCCESS;
}

int check(int d[7][7], int n, int a) {
  int i, j, z, r = 1;
  int c[7][7], num[7] = {0, 0, 0, 0, 0, 0, 0};

  for (j = 0; j < n; j++) {
    for (i = 0; i < n; i++) {
      c[j][i] = d[j][i];
      if (d[j][i] == 0) {
        if (j < i)
          c[j][i] = a;
        else
          c[j][i] = -a;
      }
    }
  }

  for (j = 0; j < n; j++)
    for (i = 0; i < n; i++)
      if (c[j][i] == 1)
        num[j]++;
  z = num[0];

  for (j = 0; j < n -1; j++)
    for (i = j + 1; i < n; i++)
      if (num[j] < num[i])
        swap(&num[j], &num[i]);

  i = num[0];
  for (j = 1; j < n; j++) {
    if (num[j] == z)
      break;
    if (num[j] < i) {
      r++;
      i = num[j];
    }
  }

  return r + 1;
}

void swap(int *a, int *b) {
  int c = *a;
  *a = *b;
  *b = c;
}
0