結果

問題 No.2489 X and Xor 2
ユーザー SSRSSSRS
提出日時 2023-09-29 21:47:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,986 bytes
コンパイル時間 2,586 ms
コンパイル使用メモリ 207,460 KB
実行使用メモリ 8,764 KB
最終ジャッジ日時 2023-09-29 22:08:46
合計ジャッジ時間 5,605 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;  
const long long MOD = 998244353;
const int LOG = 60;
int main(){
  long long N, M;
  cin >> N >> M;
  vector<long long> POW(LOG);
  for (int i = 0; i < LOG; i++){
    POW[i] = (long long) 1 << i;
  }
  vector<vector<long long>> S(LOG, vector<long long>(2, 0));
  for (int i = 0; i < LOG; i++){
    long long b = POW[i];
    S[i][0] = M / (b * 2) * b + min(M % (b * 2), b);
    S[i][1] =  M / (b * 2) * b + max(M % (b * 2) - b, (long long) 0);
    S[i][0] %= MOD;
    S[i][1] %= MOD;
  }
  vector<vector<vector<long long>>> dp(N - 1, vector<vector<long long>>(LOG, vector<long long>(2, 0)));
  for (int i = 0; i < LOG; i++){
    for (int j = 0; j < 2; j++){
      dp[0][i][j] = S[i][j] * (POW[i] % MOD) % MOD;
    }
  }
  for (int i = 1; i < N - 1; i++){
    for (int j = 0; j < LOG; j++){
      for (int k = 0; k < 2; k++){
        for (int l = 0; l < LOG; l++){
          for (int m = 0; m < 2; m++){
            vector<vector<long long>> dp2(LOG + 1, vector<long long>(2, 0));
            dp2[LOG][0] = 1;
            for (int x = LOG - 1; x >= 0; x--){
              for (int y = 0; y < 2; y++){
                for (int d = 0; d < 2; d++){
                  if (!(x == j && d == k) && !(x == l && d != m)){
                    if (!((M >> x & 1) == 0 && y == 0 && d == 1)){
                      int y2 = y;
                      if ((M >> x & 1) == 1 && d == 0){
                        y2 = 1;
                      }
                      dp2[x][y2] += dp2[x + 1][y];
                    }
                  }
                }
              }
            }
            long long cnt = dp2[0][1] % MOD;
            dp[i][l][m] += dp[i - 1][j][k] * cnt % MOD * (POW[l] % MOD);
            dp[i][l][m] %= MOD;
          }
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < LOG; i++){
    for (int j = 0; j < 2; j++){
      ans += dp[N - 2][i][j] * S[i][j ^ 1];
      ans %= MOD;
    }
  }
  cout << ans << endl;
}
0