結果

問題 No.1589 Bit Vector
ユーザー 👑 NachiaNachia
提出日時 2021-07-09 01:45:10
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 3,568 bytes
コンパイル時間 1,136 ms
コンパイル使用メモリ 34,344 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 06:16:05
合計ジャッジ時間 2,763 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

char GCbuf[1024];
int GCs = 1024;
int GCe = 1024;
inline int my_getchar(){
  if(GCs == GCe && GCe == 1024){
    GCe = fread(GCbuf, 1, 1024, stdin);
    GCs = 0;
  }
  if(GCs == GCe){
    return EOF;
  }
  return GCbuf[GCs++];
}
void rd(int *px){
  int k;
  int m=0;
  int x=0;
  for(;;){
    k = my_getchar();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
  *px = x;
}

char WTbuf[8192];
int WTs=0;
int WTe=8192;

inline void my_putchar(int a){
  WTbuf[WTs++] = a;
}
inline void wt_C(char a){
  my_putchar(a);
}
inline void wt_L(int x){
  if(x >= 10){
    my_putchar(x/10+'0');
    x%=10;
  }
  my_putchar(x+'0');
}
void wt_S(const char *c){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar(c[i]);
  }
}
int N;
int K;
int anscnt = 0;
inline void push_upd(int i,int x){
  anscnt++;
  wt_S("UPD ");
  wt_L(i);
  wt_C(' ');
  wt_L(x);
  wt_C('\n');
}
inline void push_and(int i,int x,int y){
  anscnt++;
  wt_S("AND ");
  wt_L(i);
  wt_C(' ');
  wt_L(x);
  wt_C(' ');
  wt_L(y);
  wt_C('\n');
}
inline void push_xor(int i,int x,int y){
  anscnt++;
  wt_S("XOR ");
  wt_L(i);
  wt_C(' ');
  wt_L(x);
  wt_C(' ');
  wt_L(y);
  wt_C('\n');
}
void add1(int l1,int r1,int b){
  int n = N;
  for(int i=l1; i<r1; i++){
    push_and(n,i,b);
    push_xor(i,i,b);
    int x = n; n = b; b = x;
  }
  push_and(r1,b,b);
}
void comp(int l1,int r1,int k,int p){
  if(k & 1){
    push_and(p,l1,l1);
  }
  else{
    push_upd(p,1);
  }
  for(int i=l1+1; i<r1; i++){
    k >>= 1;
    if(k & 1){
      push_and(p,i,p);
    }
    else{
      push_upd(i-1,1);
      push_xor(p,i-1,p);
      push_xor(i,i-1,i);
      push_and(p,i,p);
      push_xor(p,i-1,p);
    }
  }
}
int xc[] = {
  0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
  5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
  6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  6,6,6
};
void solve(int n,int k){
  anscnt = 0;
  for(int i=1; i<n; i++){
    add1(0,xc[i],i);
  }
  comp(0,xc[n],k,n);
}
int main(){
  rd(&N);
  rd(&K);
  int ZC = 549;
  if(N<=30) ZC = 300;
  my_putchar(ZC/100+'0');
  wt_S("49\n");
  solve(N,K);
  for(; anscnt<549; anscnt++) wt_S("UPD 0 0\n");
  fwrite(WTbuf, 1, WTs, stdout);
  return 0;
}

// cLay varsion 20201003-1

// --- original code ---
// 
// int N,K;
// int anscnt = 0;
// 
// void push_upd(int i,int x){ anscnt++; wt("UPD",i,x); }
// void push_and(int i,int x,int y){ anscnt++; wt("AND",i,x,y); }
// void push_xor(int i,int x,int y){ anscnt++; wt("XOR",i,x,y); }
// 
// void add1(int l1,int r1,int b){
//   int n = N;
//   for(int i=l1; i<r1; i++){
//     push_and(n,i,b);
//     push_xor(i,i,b);
//     swap(n,b);
//   }
//   push_and(r1,b,b);
// }
// 
// void comp(int l1,int r1,int k,int p){
//   if(k & 1) push_and(p,l1,l1);
//   else push_upd(p,1);
//   for(int i=l1+1; i<r1; i++){
//     k >>= 1;
//     if(k & 1) push_and(p,i,p);
//     else{
//       push_upd(i-1,1);
//       push_xor(p,i-1,p);
//       push_xor(i,i-1,i);
//       push_and(p,i,p);
//       push_xor(p,i-1,p);
//     }
//   }
// }
// 
// int xc[] = {
//   0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
//   5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
//   6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
//   6,6,6
// };
// 
// void solve(int n,int k){
//   anscnt = 0;
//   for(int i=1; i<n; i++) add1(0,xc[i],i);
//   comp(0,xc[i],k,n);
// }
// 
// {
//   wt(633);
//   rd(N,K);
//   solve(N,K);
//   if(anscnt > 633) exit(1);
//   for(; anscnt<633; anscnt++) wt("UPD 0 0");
//   return 0;
// }
0