結果

問題 No.130 XOR Minimax
ユーザー ともき
提出日時 2015-10-12 04:43:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 3,192 bytes
コンパイル時間 1,135 ms
コンパイル使用メモリ 121,284 KB
実行使用メモリ 54,200 KB
最終ジャッジ日時 2024-09-12 22:36:30
合計ジャッジ時間 3,483 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <thread>
#include <chrono>
using namespace std;
#define int long long
#define let const auto
#define var auto
#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif
typedef complex<double> point;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for(auto it = v.begin(); it != v.end(); ++it){
if(it != v.begin()){
os << ",";
}
os << *it;
}
return os << "}";
}
template<typename T>
void isort(std::vector<T>& v, std::function<bool(T,T)> comp=less<T>()){
sort(v.begin(), v.end(), comp);
}
template<typename T>
std::vector<T> sort(std::vector<T> v, std::function<bool(T,T)> comp=less<T>()){
isort(v);
return v;
}
template<typename T1, typename T2>
std::vector<T2> rmap(const std::vector<T1>& v, std::function<T2(T1)> f){
std::vector<T2> t; t.reserve(v.size());
for(const auto& i: v) t.push_back(f(i));
return t;
}
std::vector<std::string> split(std::string str, char delim){
std::vector<std::string> res;
size_t current = 0, found;
while((found = str.find_first_of(delim, current)) != std::string::npos){
res.push_back(std::string(str, current, found - current));
current = found + 1;
}
res.push_back(std::string(str, current, str.size() - current));
return res;
}
string join(const std::vector<string>& v, string delim){
string ret = "";
for(auto it = v.begin(); it != v.end(); ++it){
if(it != v.begin()){
ret += delim;
}
ret += *it;
}
return ret;
}
int sub(vector<int> a, int w){
assert(a.size() != 0 && "A should not be 0");
if(w == 0){
bool there_one = false;
bool there_zero = false;
for(int i : a){
there_one |= (i & 1);
there_zero |= ((i & 1) == 0);
}
return (there_one && there_zero) ? 1 : 0;
}
vector<int> l,r;
for(int i : a){
if(i & (1 << w)){
l.push_back(i);
}else{
r.push_back(i);
}
}
if(l.size() == 0){
return sub(r, w-1);
}
if(r.size() == 0){
return sub(l, w-1);
}
int ls = sub(l, w-1);
int rs = sub(r, w-1);
int mini = min(ls,rs);
return (1 << w) | mini;
}
int solve(vector<int> a){
return sub(a,31);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<int> a(n);
for(int& i: a) cin >> i;
cout << solve(a) << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0