結果

問題 No.1056 2D Lamps
ユーザー LayCurseLayCurse
提出日時 2020-05-15 22:54:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 173 ms / 3,000 ms
コード長 5,199 bytes
コンパイル時間 2,944 ms
コンパイル使用メモリ 216,792 KB
実行使用メモリ 12,952 KB
最終ジャッジ日時 2023-10-19 16:07:50
合計ジャッジ時間 5,951 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,784 KB
testcase_01 AC 3 ms
7,784 KB
testcase_02 AC 3 ms
7,784 KB
testcase_03 AC 166 ms
12,952 KB
testcase_04 AC 167 ms
12,952 KB
testcase_05 AC 167 ms
12,952 KB
testcase_06 AC 166 ms
12,952 KB
testcase_07 AC 173 ms
12,952 KB
testcase_08 AC 171 ms
12,952 KB
testcase_09 AC 85 ms
12,952 KB
testcase_10 AC 169 ms
12,952 KB
testcase_11 AC 166 ms
12,952 KB
testcase_12 AC 166 ms
12,952 KB
testcase_13 AC 3 ms
7,828 KB
testcase_14 AC 18 ms
7,832 KB
testcase_15 AC 15 ms
7,832 KB
testcase_16 AC 12 ms
7,832 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;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
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(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
struct dimcomp2{
  int B;
  dimcomp2(){
  }
  dimcomp2(int b){
    B = b;
  }
  dimcomp2(int a, int b){
    B = b;
  }
  inline void set(int b){
    B = b;
  }
  inline void set(int a, int b){
    B = b;
  }
  inline int mask(int a, int b){
    return a * B + b;
  }
  inline int operator()(int a, int b){
    return a * B + b;
  }
  inline void para(int mask, int &a, int &b){
    a = mask / B;
    b = mask % B;
  }
  inline void operator()(int mask, int &a, int &b){
    a = mask / B;
    b = mask % B;
  }
}
;
int N;
int M;
bitset<40000> A[200];
bitset<40000> tar;
bitset<40000> mt[1198];
bitset<40000> mt2[1198];
int mtf[1198];
char buf[202];
int main(){
  int i;
  int j;
  int k;
  int t1;
  int t2;
  int x = 0;
  int y;
  rd(N);
  rd(M);
  dimcomp2 dm(N,N);
  y = N*N;
  for(k=(0);k<(M);k++){
    for(i=(0);i<(N);i++){
      rd(buf);
      for(j=(0);j<(N);j++){
        if(buf[j]=='#'){
          A[k].set(dm(i,j));
        }
      }
    }
  }
  for(i=(0);i<(N);i++){
    for(j=(0);j<(N);j++){
      mt[x+i].set(dm(i,j));
    }
  }
  x += N;
  for(i=(0);i<(N);i++){
    for(j=(0);j<(N);j++){
      mt[x+j].set(dm(i,j));
    }
  }
  x += N;
  for(i=(0);i<(N);i++){
    for(j=(0);j<(N);j++){
      mt[x+i+j].set(dm(i,j));
    }
  }
  x += 2*N - 1;
  for(i=(0);i<(N);i++){
    for(j=(0);j<(N);j++){
      mt[x+i+(N-1-j)].set(dm(i,j));
    }
  }
  x += 2*N - 1;
  j = 0;
  for(i=(0);i<(y);i++){
    for(k=(j);k<(x);k++){
      if(mt[k][i]){
        break;
      }
    }
    if(k==x){
      continue;
    }
    if(k != j){
      swap(mt[j], mt[k]);
    }
    for(k=(0);k<(x);k++){
      if(k!=j && mt[k][i]){
        mt[k] ^= mt[j];
      }
    }
    j++;
  }
  k = 0;
  for(i=(0);i<(x);i++){
    if(mt[i].any()){
      mt[k++] = mt[i];
    }
  }
  x = k;
  k = 0;
  for(i=(0);i<(x);i++){
    while(!mt[i][k]){
      k++;
    }
    mtf[i] = k;
  }
  for(t1=(0);t1<(M);t1++){
    for(i=(0);i<(x);i++){
      if(A[t1][mtf[i]]){
        A[t1] ^= mt[i];
      }
    }
  }
  for(t1=(0);t1<(M-1);t1++){
    for(t2=(t1+1);t2<(M);t2++){
      tar = A[t1] ^ A[t2];
      if(tar.none()){
        wt_L('1');
      }
      else{
        wt_L('0');
      }
    }
    wt_L("");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N, M;
// bitset<40000> A[200], tar;
// bitset<40000> mt[1198], mt2[1198];
// int mtf[1198];
// char buf[202];
// 
// {
//   int i, j, k, t1, t2;
//   int x = 0, y;
//   rd(N,M);
//   dimcomp2 dm(N,N);
//   y = N*N;
// 
//   rep(k,M){
//     rep(i,N){
//       rd(buf);
//       rep(j,N) if(buf[j]=='#') A[k].set(dm(i,j));
//     }
//   }
// 
//   rep(i,N) rep(j,N) mt[x+i].set(dm(i,j));
//   x += N;
//   rep(i,N) rep(j,N) mt[x+j].set(dm(i,j));
//   x += N;
//   rep(i,N) rep(j,N) mt[x+i+j].set(dm(i,j));
//   x += 2N - 1;
//   rep(i,N) rep(j,N) mt[x+i+(N-1-j)].set(dm(i,j));
//   x += 2N - 1;
// 
//   j = 0;
//   rep(i,y){
//     rep(k,j,x) if(mt[k][i]) break;
//     if(k==x) continue;
//     if(k != j) swap(mt[j], mt[k]);
//     rep(k,x) if(k!=j && mt[k][i]) mt[k] ^= mt[j];
//     j++;
//   }
// 
//   k = 0;
//   rep(i,x) if(mt[i].any()) mt[k++] = mt[i];
//   x = k;
// 
//   k = 0;
//   rep(i,x){
//     while(!mt[i][k]) k++;
//     mtf[i] = k;
//   }
// 
//   rep(t1,M) rep(i,x) if(A[t1][mtf[i]]) A[t1] ^= mt[i];
// 
//   rep(t1,M-1){
//     rep(t2,t1+1,M){
//       tar = A[t1] ^ A[t2];
//       wtN(if[tar.none(), '1', '0']);
//     }
//     wt("");
//   }
// }
0