結果

問題 No.524 コインゲーム
ユーザー toyon
提出日時 2020-07-05 00:58:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 880 bytes
コンパイル時間 1,538 ms
コンパイル使用メモリ 166,232 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-19 18:09:47
合計ジャッジ時間 2,642 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1LL << 60;

ll N;

int main() {
    cin >> N;
    N++;

    // xor の問題となった
    ll ans = 0;

    for (int i = 0; i < 50; i++) {
        // 周期を求める
        ll interval = 1LL << (i + 1);
        ll tmp = N / interval;
        ll cnt = tmp * (interval / 2);

        // はみ出た分
        if (N % interval != 0) {
            cnt += max(0LL, N % interval - interval / 2);
        }

        // 奇数なら足しこむ
        if (cnt % 2 == 1) {
            ans += 1LL << i;
        }
        // cout << "i: " << i << " ans: " << ans << " cnt: " << cnt << endl;
    }

    if (ans == 0) {
        cout << "X" << endl;
    } else {
        cout << "O" << endl;
    }
}
0