結果

問題 No.1957 Xor Min
ユーザー SSRSSSRS
提出日時 2022-05-27 21:39:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,878 bytes
コンパイル時間 1,753 ms
コンパイル使用メモリ 174,524 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 20:00:25
合計ジャッジ時間 2,731 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  vector<int> a(30), b(30);
  for (int i = 0; i < 30; i++){
    a[i] = A >> i & 1;
    b[i] = B >> i & 1;
  }
  int tv = 0, fv = 1000000001;
  while (fv - tv > 1){
    int mid = (tv + fv) / 2;
    vector<int> k(30);
    for (int i = 0; i < 30; i++){
      k[i] = mid >> i & 1;
    }
    vector<vector<bool>> dp(31, vector<bool>(32, 0));
    dp[30][0] = true;
    for (int i = 29; i >= 0; i--){
      for (int j = 0; j < 32; j++){
        if (dp[i + 1][j]){
          for (int x = 0; x < 2; x++){
            for (int y = 0; y < 2; y++){
              bool ok  = true;
              int j2 = j;
              if ((j & 1) == 0 && k[i] == 1 && x == 0){
                ok = false;
              } else if (k[i] == 0 && x == 1){
                j2 |= 1;
              }
              if ((j & 2) == 0 && k[i] == 1 && y == 0){
                ok = false;
              } else if (k[i] == 0 && y == 1){
                j2 |= 2;
              }
              if ((j & 4) == 0 && k[i] == 1 && (x ^ y) == 0){
                ok = false;
              } else if (k[i] == 0 && (x ^ y) == 1){
                j2 |= 4;
              }
              if ((j & 8) == 0 && x == 1 && a[i] == 0){
                ok = false;
              } else if (x == 0 && a[i] == 1){
                j2 |= 8;
              }
              if ((j & 16) == 0 && y == 1 && b[i] == 0){
                ok = false;
              } else if (y == 0 && b[i] == 1){
                j2 |= 16;
              }
              if (ok){
                dp[i][j2] = true;
              }
            }
          }
        }
      }
    }
    bool ok = false;
    for (int i = 0; i < 32; i++){
      if (dp[0][i]){
        ok = true;
      }
    }
    if (ok){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
}
0