結果
| 問題 |
No.862 XORでX
|
| コンテスト | |
| ユーザー |
LayCurse
|
| 提出日時 | 2019-08-21 05:56:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 2,645 bytes |
| コンパイル時間 | 2,310 ms |
| コンパイル使用メモリ | 211,728 KB |
| 最終ジャッジ日時 | 2025-01-07 14:28:28 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 28 |
ソースコード
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
int k, m=0;
x=0;
for(;;){
k = getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
inline void wt_L(char a){
putchar_unlocked(a);
}
inline void wt_L(int x){
char f[10];
int m=0, s=0;
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
putchar_unlocked('-');
}
while(s--){
putchar_unlocked(f[s]+'0');
}
}
int N;
int X;
int res[100000];
int r;
void push(int a = 0, int b = 0, int c = 0, int d = 0){
if(a){
res[r++] = a;
}
if(b){
res[r++] = b;
}
if(c){
res[r++] = c;
}
if(d){
res[r++] = d;
}
}
int main(){
int i, k, m;
rd(N);
rd(X);
m = (N-1) / 4;
k = 4;
for(i=0;i<(m);i++){
if(X/4==k/4){
k += 4;
}
push(k, k+1, k+2, k+3);
k += 4;
}
if(N%4==0){
if(X==1){
push(k+1, k+3, 1, 2);
}
else if(X==2){
push(k, k+1, 1, 2);
}
else if(X==3){
push(k, k+1, 1, 3);
}
else{
push(X, 1, 2, 3);
}
}
if(N%4==1){
push(X);
}
if(N%4==2){
if(X!=1){
push(X^1, 1);
}
else{
push(2, 3);
}
}
if(N%4==3){
if(X==1){
push(3, k, k+2);
}
else if(X==2){
push(3, k, k+1);
}
else if(X==3){
push(2, k, k+1);
}
else{
push(X^1, 2, 3);
}
}
for(i=0;i<(N);i++){
wt_L(res[i]);
wt_L('\n');
}
return 0;
}
// cLay varsion 20190820-1
// --- original code ---
// int N, X;
// int res[1d5], r;
//
// void push(int a = 0, int b = 0, int c = 0, int d = 0){
// if(a) res[r++] = a;
// if(b) res[r++] = b;
// if(c) res[r++] = c;
// if(d) res[r++] = d;
// }
//
// {
// int i, k, m;
// rd(N,X);
//
// m = (N-1) / 4;
// k = 4;
// rep(i,m){
// if(X/4==k/4) k += 4;
// push(k, k+1, k+2, k+3);
// k += 4;
// }
//
// if(N%4==0){
// if(X==1) push(k+1, k+3, 1, 2);
// else if(X==2) push(k, k+1, 1, 2);
// else if(X==3) push(k, k+1, 1, 3);
// else push(X, 1, 2, 3);
// }
// if(N%4==1){
// push(X);
// }
// if(N%4==2){
// if(X!=1) push(X^1, 1);
// else push(2, 3);
// }
// if(N%4==3){
// if(X==1) push(3, k, k+2);
// else if(X==2) push(3, k, k+1);
// else if(X==3) push(2, k, k+1);
// else push(X^1, 2, 3);
// }
//
// rep(i,N) wt(res[i]);
// }
LayCurse