結果

問題 No.1228 I hate XOR Matching
ユーザー leaf_1415leaf_1415
提出日時 2020-09-11 23:13:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,383 bytes
コンパイル時間 741 ms
コンパイル使用メモリ 79,040 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 16:46:45
合計ジャッジ時間 4,106 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:123:24: warning: ‘b’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   llint x = vec[i] % (1<<b);
                      ~~^~~~

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define PI 3.1415926535897932384626433832795028841971
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint k, x;
vector<llint> vec;

void get(llint r)
{
	if(r <= 26){
		for(int i = 0; i < r/11; i++){
			for(int j = 1; j <= 7; j++){
				llint x = j<<(3*i);
				vec.push_back(x);
				vec.push_back(x);
			}
		}
		for(int i = 0; i < r%11; i++){
			vec.push_back(1<<(r/11*3+i));
			vec.push_back(1<<(r/11*3+i));
		}
	}
	else{
		for(int i = 0; i < r/26; i++){
			for(int j = 1; j <= 15; j++){
				llint x = j<<(4*i);
				//cout << x << endl;
				vec.push_back(x);
				vec.push_back(x);
			}
		}
		for(int i = 0; i < r%26; i++){
			vec.push_back(1<<(r/26*4+i));
			vec.push_back(1<<(r/26*4+i));
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> k >> x;
	
	if(k == 0){
		if(x == 0){
			cout << "Yes" << endl;
			cout << 1 << endl;
			cout << 1 << endl;
			return 0;
		}
		if((x+1)&x){
			cout << "No" << endl;
			return 0;
		}
		llint r = 0;
		x++;
		for(;x;x/=2) r++;
		r--;
		
		cout << "Yes" << endl;
		get(r);
		cout << vec.size() << endl;
		for(int i = 0; i < vec.size(); i++) cout << vec[i] << " "; cout << endl;
		return 0;
	}
	
	
	if(x == 0){
		cout << "Yes" << endl;
		cout << 1 << endl;
		cout << 0 << endl;
		return 0;
	}
	if((x-1)&x){
		cout << "No" << endl;
		return 0;
	}
	
	llint r = 0;
	for(;x;x/=2) r++;
	r--;
	
	llint b;
	for(int i = 0; i < 20; i++){
		if(k & (1<<i)){
			b = i;
			break;
		}
	}
	
	cout << "Yes" << endl;
	get(r);
	//cout << b << endl;
	for(int i = 0; i < vec.size(); i++){
		//cout << vec[i] << " ";
		llint x = vec[i] % (1<<b);
		vec[i] = ((vec[i] >> b) << (b+1)) + x;
		//cout << vec[i] << endl;
	}
	vec.push_back(k);
	
	cout << vec.size() << endl;
	for(int i = 0; i < vec.size(); i++) cout << vec[i] << " "; cout << endl;
	
	cout << endl;
	
	return 0;
}
0