結果
問題 | No.130 XOR Minimax |
ユーザー |
![]() |
提出日時 | 2015-01-19 21:31:19 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 42 ms / 5,000 ms |
コード長 | 763 bytes |
コンパイル時間 | 679 ms |
コンパイル使用メモリ | 45,792 KB |
実行使用メモリ | 9,008 KB |
最終ジャッジ日時 | 2024-09-12 22:33:37 |
合計ジャッジ時間 | 2,105 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:32:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | scanf( "%d", &N ); | ~~~~~^~~~~~~~~~~~ main.cpp:36:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | scanf( "%d", &x ); | ~~~~~^~~~~~~~~~~~
ソースコード
// yukicoder 130 (http://yukicoder.me/problems/282)#include<cstdio>#include<algorithm>#include<vector>#define rep(i,a) for(int i=0;i<(a);++i)#define all(a) (a).begin(), (a).end()const int MAX_N = 100000;int N;std::vector<int> a;int f( int d, std::vector<int> &S ){if( S.size() <= 1 )return 0;std::vector<int> T[2];rep( i, S.size() )T[S[i]>>d&1].push_back( S[i]^(S[i]&(1<<d)) );if( T[0].empty() )return f( d-1, T[1] );if( T[1].empty() )return f( d-1, T[0] );return (1<<d)+std::min( f(d-1,T[0]), f(d-1,T[1]) );}int main(){scanf( "%d", &N );rep( i, N ){int x;scanf( "%d", &x );a.push_back(x);}std::sort( all(a) );a.erase( std::unique(all(a)), a.end() );printf( "%d\n", f( 29, a ) );return 0;}