結果

問題 No.1228 I hate XOR Matching
ユーザー LayCurseLayCurse
提出日時 2020-09-25 18:20:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 4,076 bytes
コンパイル時間 2,826 ms
コンパイル使用メモリ 213,432 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 14:39:02
合計ジャッジ時間 7,911 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int A[50];
int K;
int X;
int arr[41];
int usa[21];
int sz;
int mylog2(long long k){
  int i;
  for(i=(0);i<(60);i++){
    if( (1LL<<i) == k ){
      return i;
    }
  }
  return -1;
}
int main(){
  int i;
  int j;
  int k;
  int mx;
  arr[1] = 1;
  for(i=(2);i<(41);i++){
    if(mylog2(i)==-1){
      arr[i] = arr[i-1] +2;
    }
    else{
      arr[i] = arr[i-1] +1;
    }
  }
  rd(K);
  rd(X);
  if(X==0){
    wt_L("Yes");
    wt_L('\n');
    K = (K+1) % (1<<20);
    wt_L(1);
    wt_L('\n');
    wt_L(K);
    wt_L('\n');
    return 0;
  }
  if(K==0){
    X++;
  }
  X = mylog2(X);
  if(X==-1){
    wt_L("No");
    wt_L('\n');
    return 0;
  }
  wt_L("Yes");
  wt_L('\n');
  if(K){
    A[N++] = K;
  }
  for(i=(0);i<(20);i++){
    if(((K) &(1<<(i)))){
      K = 0;
      continue;
    }
    usa[sz++] = i;
  }
  while(X){
    for(i=(1);i<(40);i++){
      if(X < arr[i+1]){
        break;
      }
    }
    mx = 0;
    for(j=(1);j<(i+1);j++){
      int hCmBdyQB, l;
      chmax(mx, log2(j));
      k = 0;
      for(l=(0);l<(mx+1);l++){
        if(((j) &(1<<(l)))){
          k ^= 1<<usa[sz-1-l];
        }
      }
      for(hCmBdyQB=(0);hCmBdyQB<(2);hCmBdyQB++){
        A[N++] = k;
      }
    }
    sz -= mx+1;
    X -= arr[i];
  }
  wt_L(N);
  wt_L('\n');
  {
    int YREPHmFM;
    if(N==0){
      wt_L('\n');
    }
    else{
      for(YREPHmFM=(0);YREPHmFM<(N-1);YREPHmFM++){
        wt_L(A[YREPHmFM]);
        wt_L(' ');
      }
      wt_L(A[YREPHmFM]);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20200920-1

// --- original code ---
// int N, A[50], K, X;
// int arr[41], usa[21], sz;
// 
// int mylog2(ll k){
//   rep(i,60) if( (1LL<<i) == k ) return i;
//   return -1;
// }
// 
// {
//   int i, j, k, mx;
//   arr[1] = 1;
//   rep(i,2,41) arr[i] = arr[i-1] + if[mylog2(i)==-1, 2, 1];
// 
//   rd(K,X);
//   if(X==0){
//     wt("Yes");
//     K = (K+1) % (1<<20);
//     wtLn(1, K);
//     return 0;
//   }
//   if(K==0) X++;
//   X = mylog2(X);
//   if(X==-1) wt("No"), return 0;
//   wt("Yes");
// 
//   if(K) A[N++] = K;
//   rep(i,20){
//     if(BIT_ith(K,i)) K = 0, continue;
//     usa[sz++] = i;
//   }
// 
//   while(X){
//     rep(i,1,40) if(X < arr[i+1]) break;
//     mx = 0;
//     rep(j,1,i+1){
//       mx >?= log2(j);
//       k = 0;
//       rep(l,mx+1) if(BIT_ith(j,l)) k ^= 1<<usa[sz-1-l];
//       rep(2) A[N++] = k;
//     }
//     sz -= mx+1;
//     X -= arr[i];
//   }
// 
//   wt(N);
//   wt(A(N));
// }
0