結果

問題 No.130 XOR Minimax
ユーザー yyyuuuummmmaaa1yyyuuuummmmaaa1
提出日時 2019-11-11 07:26:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 316 ms / 5,000 ms
コード長 2,259 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 150,764 KB
実行使用メモリ 98,504 KB
最終ジャッジ日時 2023-10-10 00:24:59
合計ジャッジ時間 5,124 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
44,376 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 30 ms
4,352 KB
testcase_05 AC 34 ms
4,348 KB
testcase_06 AC 63 ms
15,956 KB
testcase_07 AC 64 ms
16,032 KB
testcase_08 AC 243 ms
98,504 KB
testcase_09 AC 18 ms
6,932 KB
testcase_10 AC 27 ms
8,192 KB
testcase_11 AC 84 ms
12,532 KB
testcase_12 AC 10 ms
5,544 KB
testcase_13 AC 67 ms
11,744 KB
testcase_14 AC 316 ms
80,020 KB
testcase_15 AC 4 ms
4,392 KB
testcase_16 AC 216 ms
58,396 KB
testcase_17 AC 229 ms
60,592 KB
testcase_18 AC 243 ms
64,604 KB
testcase_19 AC 294 ms
75,288 KB
testcase_20 AC 141 ms
40,204 KB
testcase_21 AC 308 ms
79,352 KB
testcase_22 AC 61 ms
21,248 KB
testcase_23 AC 17 ms
8,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<stack>
#include<complex>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

#define WHATS(var)cout<<__LINE__<<' '<<#var<<"="<<var<<endl;

template<class S, class T> ostream& operator <<(ostream &os, const pair<S, T> v){
os << "( " << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<T> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<vector<T>> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<set<T>> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const set<T> &v){
int i=0;
for(auto it:v){
	if(i > 0){os << ' ';}
	os << it;
	i++;
} 
return os;
}


using ll=long long ;


struct node{
	int l;
	int r;
	shared_ptr<node>chl,chr;
	node(int l,int r):l(l),r(r){
		chl=nullptr;
		chr=nullptr;
	}
};
void add(shared_ptr<node>no,int x){
	int l=no->l;
	int r=no->r;
	if(l+1==r){

	}else{
		int m((l+r)/2);
		if(x<m){
			if(no->chl==nullptr){
				no->chl=make_shared<node>(l,m);
			}
			add(no->chl,x);

		}else{
			if(no->chr==nullptr){
				no->chr=make_shared<node>(m,r);

			}
			add(no->chr,x);
		}	
	}
}
int solve(shared_ptr<node>no){
	int l=no->l;
	int r=no->r;
	//WHATS(l)
	//WHATS(r)
	if(l+1==r){
		return 0;
	}else{
		int m((l+r)/2);
		if(no->chl==nullptr){
			return solve(no->chr);
		}else if(no->chr==nullptr){
			return solve(no->chl);
		}else{
			int am=solve(no->chl);
			int bm=solve(no->chr);
			return (r-l)/2+min(am,bm);
		}
	}
}
int main() {
	ios::sync_with_stdio(false);
	int N;cin>>N;
	shared_ptr<node>root=make_shared<node>(0,(1<<30));
	for(int i=0;i<N;++i){
		int a;cin>>a;
		add(root,a);
	}	
	int ans=solve(root);
	cout<<ans<<endl;
	
	return 0;
}
0