結果

問題 No.3718 XOR Escape
コンテスト
ユーザー HoyHoyCharhang
提出日時 2026-09-18 23:17:10
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,296 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,047 ms
コンパイル使用メモリ 335,724 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-18 23:17:21
合計ジャッジ時間 3,493 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,g,n) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define eb emplace_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<typename T> using pq = priority_queue<T,vector<T>,greater<T>>;
using P = pair<int,int>;
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}

void naive(ll n, ll a, ll b, ll c) {
  vector<ll> dp(n+1, 0);
  dp[0] = 0;
  rep(x,1,n+1) rep(y,0,x) {
    if ((x^y) != a && (x^y) != b && (x^y) != c) {
      dp[x] = max(dp[x], dp[y]+1);
    }
  }
  rep(i,0,n+1) {
    cout << dp[i] << " ";
  }
  cout << endl;
}

int main() {
  ll n, a, b, c;
  cin >> n >> a >> b >> c;
  // naive(n, a, b, c);
  vector<int> flg(3);
  if (__builtin_popcount(a+1) == 1) flg[0] = 1;
  if (__builtin_popcount(b+1) == 1) flg[1] = 1;
  if (__builtin_popcount(c+1) == 1) flg[2] = 1;
  if (flg[0]+flg[1]+flg[2] == 0) {
    cout << n << endl;
    return 0;
  } else if (flg[0]+flg[1]+flg[2] == 1) {
    int x = 0;
    if (flg[0]) x = 64-__builtin_clzll(a);
    if (flg[1]) x = 64-__builtin_clzll(b);
    if (flg[2]) x = 64-__builtin_clzll(c);
    if (n < (1LL<<(x-1))) {
      cout << n << endl;
    } else {
      cout << n-((n-(1LL<<(x-1)))/(1LL<<x)+1) << endl;
    }
    return 0;
  }
  int x = 0, y = 0;
  if (flg[0]) {
    if (x == 0) x = 64-__builtin_clzll(a);
    else y = 64-__builtin_clzll(a);
  }
  if (flg[1]) {
    if (x == 0) x = 64-__builtin_clzll(b);
    else y = 64-__builtin_clzll(b);
  }
  if (flg[2]) {
    if (x == 0) x = 64-__builtin_clzll(c);
    else y = 64-__builtin_clzll(c);
  }
  // cout << x << " " << y << endl;
  if (x > y) swap(x, y);
  if (x >= 2) {
    ll k1 = 0, k2 = 0;
    if (n >= (1LL<<(x-1))) {
      k1 = (n-(1LL<<(x-1)))/(1LL<<x)+1;
    }
    if (n >= (1LL<<(y-1))) {
      k2 = (n-(1LL<<(y-1)))/(1LL<<y)+1;
    }
    cout << n-k1-k2 << endl;
    return 0;
  }
  ll z = (n+(1LL<<(y-1)))/(1LL<<y);
  cout << n/2-z << endl;
  return 0;
}
0