結果

問題 No.2521 Don't be Same
コンテスト
ユーザー tnakao0123
提出日時 2024-06-19 22:55:07
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,238 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 153 ms
コンパイル使用メモリ 53,108 KB
実行使用メモリ 9,264 KB
平均クエリ数 9.75
最終ジャッジ日時 2026-07-05 01:15:06
合計ジャッジ時間 2,662 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 2521.cc:  No.2521 Don't be Same - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* subroutines */

int read(int &i, int &z) {
  char op[4];
  scanf("%s", op);

  i = z = -1;
  if (op[0] == 'A') scanf("%d%d", &i, &z), i--;
  return op[0] - 'A';
}

/* main */

int main() {
  int x, y;
  scanf("%d%d", &x, &y);

  if (((x & 1) && y == x + 1) || ((y & 1) && x == y + 1)) {
    puts("Second"); fflush(stdout);

    int i, z;
    int r = read(i, z);
    if (r >= 2) return 0;
    if (i == 0) x -= z;
    else y -= z;
  }
  else {
    puts("First"); fflush(stdout);
  }

  while (x > 0 || y > 0) {
    if (x == y) {
      puts("B");
      x = y = 0;
    }
    else if (x == 0) {
      printf("A 2 %d\n", y);
      y = 0;
    }
    else if (y == 0) {
      printf("A 1 %d\n", x);
      x = 0;
    }
    else if (x < y) {
      int z = (x & 1) ? y - (x + 1) : y - (x - 1);
      printf("A 2 %d\n", z);
      y -= z;
    }
    else { // x > y
      int z = (y & 1) ? x - (y + 1) : x - (y - 1);
      printf("A 1 %d\n", z);
      x -= z;
    }
    fflush(stdout);

    int i, z;
    int r = read(i, z);

    if (r >= 2) break;
    if (i == 0) x -= z;
    else y -= z;
  }

  return 0;
}
0