結果
| 問題 | 
                            No.939 and or
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-12-02 00:15:09 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 1,673 bytes | 
| コンパイル時間 | 1,270 ms | 
| コンパイル使用メモリ | 77,860 KB | 
| 最終ジャッジ日時 | 2025-01-08 06:39:37 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:60:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |   i64 A, B; scanf("%ld%ld", &A, &B);
      |             ~~~~~^~~~~~~~~~~~~~~~~~
            
            ソースコード
#include <bitset>
#include <cstdint>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
using i64 = int64_t;
string to_bin(const i64 a) {
  string s = bitset<32>(a).to_string();
  return s;
}
int cmp(int x, int y) {
  if(x <  y) { return 0; }
  if(x == y) { return 1; }
  return 2;
}
int next_state(int x, int y, int cur) {
  int res = cur;
  if(res == 1) { res = cmp(x, y); }
  return res;
}
i64 f(i64 a, i64 b) {
  string sa = to_bin(a),
         sb = to_bin(b);
  const int n = 32;
  // dp[xがyより未満/丁度/超過][x&yがaより未満/丁度/超過][x|yがbより未満/丁度/超過] := パターン数
  vector<vector<vector<i64>>> dp(3, vector<vector<i64>>(3, vector<i64>(3, 0)));
  dp[1][1][1] = 1;
  for(int i=0; i<n; ++i) {
    vector<vector<vector<i64>>> ndp(3, vector<vector<i64>>(3, vector<i64>(3, 0)));
    for(int state1=0; state1<3; ++state1) {
      for(int state2=0; state2<3; ++state2) {
        for(int state3=0; state3<3; ++state3) {
          if(!dp[state1][state2][state3]) { continue; }
          for(int xi=0; xi<2; ++xi) {
            for(int yi=0; yi<2; ++yi) {
              int nstate1 = next_state(xi,    yi,        state1),
                  nstate2 = next_state(xi&yi, sa[i]-'0', state2),
                  nstate3 = next_state(xi|yi, sb[i]-'0', state3);
              ndp[nstate1][nstate2][nstate3] += dp[state1][state2][state3];
            }
          }
        }
      }
    }
    dp = ndp;
  }
  i64 res = 0;
  for(int state1 : {0, 1}) {
    res += dp[state1][1][1];
  }
  return res;
}
int main(void) {
  i64 A, B; scanf("%ld%ld", &A, &B);
  i64 res = f(A, B);
  printf("%ld\n", res);
  return 0;
}