結果

問題 No.3120 Lower Nim
ユーザー テナガザル
提出日時 2025-04-19 15:22:07
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 235 ms / 2,000 ms
コード長 1,571 bytes
コンパイル時間 1,001 ms
コンパイル使用メモリ 101,844 KB
実行使用メモリ 26,356 KB
平均クエリ数 2685.91
最終ジャッジ日時 2025-04-19 15:22:17
合計ジャッジ時間 8,808 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int cnt[15] = {0};
  for (int i = 0; i < 15; ++i) for (int j = 0; j < n; ++j) cnt[i] += a[j] / (1 << i);
  int ret = -2;
  for (int i = 0; i < 15; ++i)
  {
    if (cnt[i] % 2)
    {
      cout << "First" << endl;
      for (int j = 0; j < n; ++j)
      {
        if (a[j] >= (1 << i))
        {
          cout << j + 1 << ' ' << (1 << i) << endl;
          for (int k = 0; k < 15; ++k) cnt[k] -= a[j] / (1 << k);
          a[j] -= (1 << i);
          for (int k = 0; k < 15; ++k) cnt[k] += a[j] / (1 << k);
          cin >> ret;
          break;
        }
      }
      break;
    }
  }
  int id, x;
  if (ret == -2) cout << "Second" << endl;
  while (true)
  {
    cin >> id >> x;
    --id;
    for (int i = 0; i < 15; ++i) cnt[i] -= a[id] / (1 << i); 
    a[id] -= x;
    for (int i = 0; i < 15; ++i) cnt[i] += a[id] / (1 << i); 
    cin >> ret;
    if (ret != 0) return 0;
    for (int i = 0; i < 15; ++i)
    {
      if (cnt[i] % 2)
      {
        for (int j = 0; j < n; ++j)
        {
          if (a[j] >= (1 << i))
          {
            cout << j + 1 << ' ' << (1 << i) << endl;
            for (int k = 0; k < 15; ++k) cnt[k] -= a[j] / (1 << k);
            a[j] -= (1 << i);
            for (int k = 0; k < 15; ++k) cnt[k] += a[j] / (1 << k);
            cin >> ret;
            if (ret != 0) return 0;
            break;
          }
        }
        break;
      }
    }
  }
}
0