結果

問題 No.1589 Bit Vector
ユーザー 👑 NachiaNachia
提出日時 2021-07-09 01:22:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 4,009 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 35,764 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 06:15:36
合計ジャッジ時間 2,478 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

inline int my_getchar(){
  static char buf[1024];
  static int s = 1024;
  static int e = 1024;
  if(s == e && e == 1024){
    e = fread(buf, 1, 1024, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline 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;
}
struct MY_WRITER{
  char buf[16384];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 16384;
  }
  ~MY_WRITER(){
    if(s){
      fwrite(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite(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(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('-');
  }
  while(s--){
    my_putchar(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar(c[i]);
  }
}
int N;
int K;
int anscnt = 0;
void push_upd(int i,int x){
  anscnt++;
  wt_L("UPD");
  wt_L(' ');
  wt_L(i);
  wt_L(' ');
  wt_L(x);
  wt_L('\n');
}
void push_and(int i,int x,int y){
  anscnt++;
  wt_L("AND");
  wt_L(' ');
  wt_L(i);
  wt_L(' ');
  wt_L(x);
  wt_L(' ');
  wt_L(y);
  wt_L('\n');
}
void push_xor(int i,int x,int y){
  anscnt++;
  wt_L("XOR");
  wt_L(' ');
  wt_L(i);
  wt_L(' ');
  wt_L(x);
  wt_L(' ');
  wt_L(y);
  wt_L('\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(){
  wt_L(549);
  wt_L('\n');
  rd(&N);
  rd(&K);
  solve(N,K);
  if(anscnt > 549) return 1;
  for(; anscnt<549; anscnt++){
    wt_L("UPD 0 0");
    wt_L('\n');
  }
  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