結果

問題 No.1957 Xor Min
ユーザー ramia777ramia777
提出日時 2022-06-07 16:51:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,155 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 95,564 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 03:50:19
合計ジャッジ時間 2,008 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicodr
// No.1957



//二次元可変配列
//vector <vector <int>> mass;
//vector <vector <int>> memo;
//vector <int> memo;


//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <list>//list
#include <queue> //queue
#include <set> //連想コンテナ(要素が自動でソートされる)、要素1つ(Key)、keyの重複ない、O(logN)
#include <map> //連想コンテナ(要素が自動でソートされる)、要素2つ(Key,data)、keyの重複ない、dataは重複あり、O(logN)
#include <unordered_set> //hash、O(1)
#include <unordered_map> //hash、O(1)
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <climits>
//#include <bits/stdc++.h>

using namespace std;

#define FOR(x,to) for(x=0;x<to;x++)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define FMAX(a,b)  ((a)>(b)?(a):(b))
#define FMIN(a,b)  ((a)<(b)?(a):(b))
#define FCEIL(a,b)  ((a)+(b)-1)/(b)

typedef unsigned long long ULL;
typedef signed long long SLL;


queue<int> _queue;



SLL A, B,Cmax = 0;
SLL ABmax = 0;
SLL ABmin = 0;

int main()
{
	cin >> A;
	cin >> B;

	if (A > B)
	{
		ABmax = A;
		ABmin = B;
	}
	else
	{
		ABmax = B;
		ABmin = A;
	}

	//大きい数の最上位ビットだけ立っている数を取得 (例 16→ 0b10000)
	SLL ABmax_KETA = 1;
	while (ABmax >= ABmax_KETA *2)
	{
		ABmax_KETA <<= 1;
	}

	//小さい数の最上位ビットだけ立っている数を取得 (例 16→ 0b10000)
	SLL ABmin_KETA = 1;
	while (ABmin >= ABmin_KETA * 2)
	{
		ABmin_KETA <<= 1;
	}

	//もし大きい数の最上位ビットが大きい場合
	if(ABmin_KETA < ABmax_KETA)
	{ 
		// 3つの数がともに大きいときは x=ABmax_KETA, y=ABmin
		// ABmin < ABmax_KETA < (ABmax_KETA xor ABmin) の順番になるので一番小さい ABmin が答え

		cout << ABmin;
		return 0;
	}

	//もし最上位ビットが同じ場合
	if (ABmin_KETA == ABmax_KETA)
	{
		// 3つの数がともに大きいときの xorの値は ABmin_KETA-1( or ABmax_KETA-1)
		// 3つのなかでは(A xor B) の値が一番小さくなる

		cout << ABmin_KETA -1;
		return 0;
	}


	return 0;

}

0