結果
問題 | No.130 XOR Minimax |
ユーザー |
|
提出日時 | 2017-01-02 16:36:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 123 ms / 5,000 ms |
コード長 | 1,520 bytes |
コンパイル時間 | 2,040 ms |
コンパイル使用メモリ | 168,852 KB |
実行使用メモリ | 51,200 KB |
最終ジャッジ日時 | 2024-09-12 22:42:41 |
合計ジャッジ時間 | 3,753 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector< int > vi; typedef vector< vi > vvi; typedef vector< ll > vl; typedef vector< vl > vvl; typedef pair< int, int > pii; typedef vector< pii > vp; typedef vector< double > vd; typedef vector< vd > vvd; typedef vector< string > vs; template< class T1, class T2 > int upmin( T1 &x, T2 v ){ if( x > v ){ x = v; return 1; } return 0; } template< class T1, class T2 > int upmax( T1 &x, T2 v ){ if( x < v ){ x = v; return 1; } return 0; } const int INF = 0x3f3f3f3f; int N; vi A; void init(){ cin >> N; A = vi( N ); for( int i = 0; i < N; ++i ){ cin >> A[ i ]; } } struct trie{ trie *ch[ 2 ]; trie(){ ch[ 0 ] = ch[ 1 ] = NULL; } } *root; void update( trie *&t, int lv, int v ){ if( lv < 0 ){ return; } if( t->ch[ v >> lv & 1 ] == NULL ){ t->ch[ v >> lv & 1 ] = new trie(); } update( t->ch[ v >> lv & 1 ], lv - 1, v ); } void preprocess(){ root = new trie(); for( int i = 0; i < N; ++i ){ update( root, 30, A[ i ] ); } } int dfs( const trie *t, int lv ){ if( lv < 0 ){ return 0; } if( t->ch[ 0 ] == NULL ){ return dfs( t->ch[ 1 ], lv - 1 ); } if( t->ch[ 1 ] == NULL ){ return dfs( t->ch[ 0 ], lv - 1 ); } return 1 << lv | min( dfs( t->ch[ 0 ], lv - 1 ), dfs( t->ch[ 1 ], lv - 1 ) ); } void solve(){ cout << dfs( root, 30 ) << endl; } signed main(){ ios::sync_with_stdio( 0 ); init(); preprocess(); solve(); return 0; }