結果

問題 No.2071 Shift and OR
ユーザー 👑 p-adicp-adic
提出日時 2022-09-17 11:12:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,371 bytes
コンパイル時間 1,970 ms
コンパイル使用メモリ 199,892 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 17:35:06
合計ジャッジ時間 3,569 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,384 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG 
#include<bits/stdc++.h>
using namespace std;

using uint = unsigned int;
using ll = long long;

#define CIN( LL , A ) LL A; cin >> A 
#define GETLINE( A ) string A; getline( cin , A ) 
#define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR ) 
#define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) 
#define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( ll VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) 
#define FOR_ITR( ARRAY , ITR , END ) for( auto ITR = ARRAY .begin() , END = ARRAY .end() ; ITR != END ; ITR ++ ) 
#define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES ) 
#define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; return 0 
#define DOUBLE( PRECISION , ANSWER ) cout << fixed << setprecision( PRECISION ) << ( ANSWER ) << "\n"; return 0 
#define MIN( A , B ) A < B ? A : B;
#define MAX( A , B ) A < B ? B : A;

template <typename T> inline T Absolute( const T& a ){ return a > 0 ? a : - a; }

int main()
{
  UNTIE;
  CIN( ll , N );
  constexpr const ll power = 65536;
  constexpr const ll digit = 16;
  if( N >= digit ){
    RETURN( power - 1 );
  }
  constexpr const ll shift = power / 2;
  ll Ai;
  bool c[power] = {};
  ll answer[2][power];
  answer[0][0] = 0;
  ll size[2] = { 1 , 0 };
  ll signature_last = 0;
  ll signature_new = 1;
  ll value;
  N--;
  REPEAT( N ){
    cin >> Ai;
    ll ( &answer_last )[power] = answer[signature_last];
    ll& size_last = size[signature_last];
    ll ( &answer_new )[power] = answer[signature_new];
    ll& size_new = size[signature_new];
    size_new = 0;
    REPEAT( digit ){
      FOR( j , 0 , size_last ){
	value = answer_last[j] | Ai;
	if( ! c[value] ){
	  c[value] = true;
	  answer_new[size_new] = value;
	  size_new++;
	}
      }
      Ai = shift * ( Ai % 2 ) + Ai / 2;
    }
    if( size_new == 0 ){
      RETURN( power - 1 );
    }
    swap( signature_last , signature_new );
  }
  ll max = -1;
  {
    cin >> Ai;
    ll ( &answer_last )[power] = answer[signature_last];
    ll& size_last = size[signature_last];
    REPEAT( digit ){
      FOR( j , 0 , size_last ){
	value = answer_last[j] | Ai;
	if( ! c[value] ){
	  c[value] = true;
	  if( max < value ){
	    max = value;
	  }
	}
      }
      Ai = shift * ( Ai % 2 ) + Ai / 2;
    }
    if( max == -1 ){
      RETURN( power - 1 );
    }
  }
  RETURN( max );
}

0