結果
| 問題 | 
                            No.862 XORでX
                             | 
                    
| コンテスト | |
| ユーザー | 
                             leaf_1415
                         | 
                    
| 提出日時 | 2019-08-09 23:10:49 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,832 bytes | 
| コンパイル時間 | 782 ms | 
| コンパイル使用メモリ | 68,396 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-19 15:38:26 | 
| 合計ジャッジ時間 | 5,448 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 19 WA * 9 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#define llint long long
using namespace std;
llint n, x;
vector<llint> ans;
int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> x;
	
	if(n == 1){
		cout << x << endl;
		return 0;
	}
	if(n == 2){
		if(x == 1){
			cout << 2 << endl;
			cout << 3 << endl;
		}
		else if(x == 2){
			cout << 1 << endl;
			cout << 3 << endl;
		}else{
			llint y = x ^ 1;
			cout << 1 << endl;
			cout << y << endl;
		}
		return 0;
	}
	
	llint rem = n;
	if(n % 4 == 0){
		if(x > 3){
			rem--;
			for(int i = 0; ; i++){
				if(x/4 == i) continue;
				for(int j = 0; j < 4; j++){
					if(i*4+j != 0 && rem) ans.push_back(i*4+j), rem--;
				}
				if(rem <= 0) break;
			}
			ans.push_back(x);
		}
		else{
			rem -= 4;
			for(int i = 0; ; i++){
				for(int j = 0; j < 4; j++){
					if(i*4+j != 0 && rem) ans.push_back(i*4+j), rem--;
				}
				if(rem <= 0) break;
			}
			int t = 3;
			if(ans.size()) t = ans.back();
			if(x != 1){
				ans.push_back(t+1);
				ans.push_back(t+2);
				if(x == 0) ans.push_back(2), ans.push_back(3);
				if(x == 2) ans.push_back(1), ans.push_back(2);
				if(x == 3) ans.push_back(1), ans.push_back(3);
			}
			else{
				ans.push_back(t+1);
				ans.push_back(t+3);
				ans.push_back(1), ans.push_back(2);
			}
		}
	}
	if(n % 4 == 1){
		rem--;
		for(int i = 1; ; i++){
			if(x/4 == i) continue;
			for(int j = 0; j < 4; j++){
				if(i*4+j != 0 && rem) ans.push_back(i*4+j), rem--;
			}
			if(rem <= 0) break;
		}
		ans.push_back(x);
	}
	if(n % 4 == 2){
		rem++;
		int i = x/4;
		for(int j = 0; j < 4; j++){
			if(i*4+j != 0 && rem) ans.push_back(i*4+j), rem--;
		}
		for(int i = 0; ; i++){
			for(int j = 0; j < 4; j++){
				if(rem) ans.push_back(i*4+j), rem--;
			}
			if(rem <= 0) break;
		}
		for(int j = 0; j < ans.size(); j++){
			if(ans[j] == x) ans.erase(ans.begin() + j);
		}
	}
	if(n % 4 == 3){
		if(x > 3){
			rem++;
			int i = x/4;
			for(int j = 0; j < 4; j++){
				if(i*4+j != 0 && rem) ans.push_back(i*4+j), rem--;
			}
			for(int i = 1; ; i++){
				for(int j = 0; j < 4; j++){
					if(i*4+j != 0 && rem) ans.push_back(i*4+j), rem--;
				}
				if(rem <= 0) break;
			}
			for(int j = 0; j < ans.size(); j++){
				if(ans[j] == x) ans.erase(ans.begin() + j);
			}
		}
		else{
			rem -= 3;
			for(int i = 0; ; i++){
				for(int j = 0; j < 4; j++){
					if(rem) ans.push_back(i*4+j), rem--;
				}
				if(rem <= 0) break;
			}
			int t = 3;
			if(ans.size()) t = ans.back();
			if(x != 1){
				ans.push_back(t+1);
				ans.push_back(t+2);
				if(x == 0) ans.push_back(1);
				if(x == 2) ans.push_back(3);
				if(x == 3) ans.push_back(2);
			}
			else{
				ans.push_back(t+1);
				ans.push_back(t+3);
				ans.push_back(3);
			}
		}
	}
	
	sort(ans.begin(), ans.end());
	for(int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
	
	return 0;
}
            
            
            
        
            
leaf_1415