結果

問題 No.1952 xooooooooooor
ユーザー MtSakaMtSaka
提出日時 2022-04-12 19:58:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,043 bytes
コンパイル時間 2,047 ms
コンパイル使用メモリ 203,364 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 08:43:51
合計ジャッジ時間 3,429 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
long long modpow(long long a,long long b,long long mod){long long res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
int main(){
  constexpr long long mod=998244353;
  long long n,m;cin>>n>>m;
  long long n2=n;
  vector<int>bits;
  int sum=0;
  while(n){
    bits.push_back(n&1);
    sum^=(n&1);
    n>>=1;
  }
  n=n2;
  reverse(bits.begin(),bits.end());
  if(m<=(int)bits.size()){
    long long ans=0;
    for(int i=0;i<m;i++)ans^=n*(1LL<<i);
    cout<<ans%mod<<endl;
    return 0;
  }
  vector<int>r(bits.size()),l(bits.size());
  int tmp=0;
  for(int i=0;i<(int)bits.size();i++){
    tmp^=bits[i];
    r[i]=tmp;
  }
  tmp=0;
  for(int i=0;i<(int)bits.size();i++){
    tmp^=bits[bits.size()-1-i];
    l[i]=tmp;
  }
  long long ans=0;
  for(int i=0;i<(int)bits.size();i++){
    ans+=l[i]*modpow(2,i,mod)%mod;
    ans+=r[i]*modpow(2,m+bits.size()-i-2,mod)%mod;
    ans%=mod;
  }
  if(sum)ans+=modpow(2,m-1,mod)-modpow(2,bits.size(),mod);
  ans=(ans+mod)%mod;
  cout<<ans<<endl;
}
0