結果

問題 No.3219 Ruler to Maximize
コンテスト
ユーザー Rumain831
提出日時 2026-09-22 03:09:22
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 430µs
コード長 557 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,817 ms
コンパイル使用メモリ 176,204 KB
実行使用メモリ 9,896 KB
最終ジャッジ日時 2026-09-22 03:09:27
合計ジャッジ時間 4,141 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
using namespace std;

int main(void){
  int n; cin >> n;
  vector<int> a(n);
  for(auto&x:a) cin >> x;
  int m=12, mx=(1<<m), all=mx-1;
  int ans=-1;
  string s;
  for(int i=0; i<mx; i++){
    int w=0, b=0, rem=all^i;
    string t;
    for(int j=0; j<n; j++){
      if((i|a[j])==i) w|=a[j], t+='W';
      else if((rem|a[j])==rem) b|=a[j], t+='B';
      else{w=-1; break;}
    }
    if(w!=-1){
      int now=w*b;
      if(now>ans){
        ans=now, s=t;
      }
    }
  }
  cout << ans << '\n' << s << endl;
  return 0; 
}
0