結果
| 問題 | No.3718 XOR Escape |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-18 23:32:17 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1 ms / 2,000 ms |
| + 370µs | |
| コード長 | 2,731 bytes |
| 記録 | |
| コンパイル時間 | 2,177 ms |
| コンパイル使用メモリ | 336,104 KB |
| 実行使用メモリ | 6,528 KB |
| 最終ジャッジ日時 | 2026-09-18 23:32:21 |
| 合計ジャッジ時間 | 3,920 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 |
ソースコード
#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;
cout << dp[n] << endl;
}
int solve(ll n, ll a, ll b, ll c) {
// ll n, a, b, c;
// cin >> n >> a >> b >> c;
// naive(n, a, b, c);
vector<int> flg(3);
if (__builtin_popcountll(a+1) == 1) flg[0] = 1;
if (__builtin_popcountll(b+1) == 1) flg[1] = 1;
if (__builtin_popcountll(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;
}
mt19937 mt(time(0));
int main() {
// uniform_int_distribution<int> rand(1, 1000), r2(1, 10);
// int n = rand(mt), a = (1<<r2(mt))-1, b = (1<<r2(mt))-1;
// if (a == b) b = (1<<r2(mt))-1;
// int c = a^b;
// cout << n << " " << a << " " << b << " " << c << endl;
ll n, a, b, c;
cin >> n >> a >> b >> c;
solve(n, a, b, c);
// naive(n, a, b, c);
}