結果

問題 No.1121 Social Distancing in Cinema
ユーザー LayCurseLayCurse
提出日時 2020-07-22 21:56:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 7,485 bytes
コンパイル時間 3,439 ms
コンパイル使用メモリ 215,792 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2023-09-04 18:27:46
合計ジャッジ時間 23,896 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
12,480 KB
testcase_01 AC 4 ms
12,420 KB
testcase_02 AC 4 ms
12,560 KB
testcase_03 AC 4 ms
12,428 KB
testcase_04 AC 4 ms
12,508 KB
testcase_05 AC 4 ms
12,412 KB
testcase_06 AC 4 ms
12,484 KB
testcase_07 AC 4 ms
12,496 KB
testcase_08 AC 4 ms
12,432 KB
testcase_09 AC 4 ms
12,428 KB
testcase_10 AC 4 ms
12,484 KB
testcase_11 AC 5 ms
12,424 KB
testcase_12 AC 5 ms
12,428 KB
testcase_13 AC 6 ms
12,492 KB
testcase_14 AC 8 ms
12,500 KB
testcase_15 AC 22 ms
12,516 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 32 ms
12,620 KB
testcase_21 AC 24 ms
12,488 KB
testcase_22 AC 24 ms
12,488 KB
testcase_23 AC 8 ms
12,564 KB
testcase_24 AC 5 ms
12,436 KB
testcase_25 AC 159 ms
13,200 KB
testcase_26 AC 260 ms
13,660 KB
testcase_27 AC 5 ms
12,520 KB
testcase_28 AC 818 ms
15,220 KB
testcase_29 AC 232 ms
13,368 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 229 ms
13,356 KB
testcase_34 AC 223 ms
13,572 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 149 ms
13,112 KB
testcase_38 AC 249 ms
13,520 KB
testcase_39 AC 629 ms
15,260 KB
testcase_40 AC 72 ms
13,052 KB
testcase_41 AC 20 ms
12,604 KB
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 AC 4 ms
12,456 KB
testcase_48 AC 4 ms
12,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){
  sort(a, a+N);
}
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');
  }
}
template<class S> inline void arrInsert(const int k, int &sz, S a[], const S aval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  a[k] = aval;
}
template<class S, class T> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  a[k] = aval;
  b[k] = bval;
}
template<class S, class T, class U> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  for(i=sz-1;i>k;i--){
    c[i] = c[i-1];
  }
  a[k] = aval;
  b[k] = bval;
  c[k] = cval;
}
template<class S, class T, class U, class V> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval, V d[], const V dval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  for(i=sz-1;i>k;i--){
    c[i] = c[i-1];
  }
  for(i=sz-1;i>k;i--){
    d[i] = d[i-1];
  }
  a[k] = aval;
  b[k] = bval;
  c[k] = cval;
  d[k] = dval;
}
template <class T> struct LHeap{
  int *hp;
  int *place;
  int size;
  T *val;
  void malloc(int N){
    hp = (int*)std::malloc(N*sizeof(int));
    place=(int*)std::malloc(N*sizeof(int));
    val=(T*)std::malloc(N*sizeof(T));
  }
  void walloc(int N, void **mem=&wmem){
    walloc1d(&hp, N, mem);
    walloc1d(&place, N, mem);
    walloc1d(&val, N, mem);
  }
  void free(){
    std::free(hp);
    std::free(place);
    std::free(val);
  }
  void init(int N){
    int i;
    size=0;
    for(i=(0);i<(N);i++){
      place[i]=-1;
    }
  }
  void up(int n){
    int m;
    while(n){
      m=(n-1)/2;
      if(val[hp[m]]<=val[hp[n]]){
        break;
      }
      swap(hp[m],hp[n]);
      swap(place[hp[m]],place[hp[n]]);
      n=m;
    }
  }
  void down(int n){
    int m;
    for(;;){
      m=2*n+1;
      if(m>=size){
        break;
      }
      if(m+1<size&&val[hp[m]]>val[hp[m+1]]){
        m++;
      }
      if(val[hp[m]]>=val[hp[n]]){
        break;
      }
      swap(hp[m],hp[n]);
      swap(place[hp[m]],place[hp[n]]);
      n=m;
    }
  }
  void change(int n, T v){
    T f = val[n];
    val[n] = v;
    if(place[n]==-1){
      place[n] = size;
      hp[size++] = n;
      up(place[n]);
    }
    else{
      if(f < v){
        down(place[n]);
      }
      else if(f > v){
        up(place[n]);
      }
    }
  }
  int pop(void){
    int res = hp[0];
    place[res] = -1;
    size--;
    if(size){
      hp[0]=hp[size];
      place[hp[0]]=0;
      down(0);
    }
    return res;
  }
}
;
int N;
int X[300000];
int Y[300000];
int cnt[300000];
int use[300000];
int mp[500][500];
int ress;
int res[300000];
int sz;
int dx[400];
int dy[400];
int main(){
  wmem = memarr;
  LHeap<int> hp;
  int i;
  int j;
  int k;
  int si;
  int sj;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(X[Lj4PdHRW]);X[Lj4PdHRW] += (-1);
      rd(Y[Lj4PdHRW]);Y[Lj4PdHRW] += (-1);
    }
  }
  for(i=(-10);i<(11);i++){
    for(j=(-10);j<(11);j++){
      if(0 < i*i+j*j  &&  i*i+j*j < 100){
        arrInsert(sz, sz, dx, i, dy, j);
      }
    }
  }
  for(i=(0);i<(500);i++){
    for(j=(0);j<(500);j++){
      mp[i][j] = -1;
    }
  }
  for(i=(0);i<(N);i++){
    mp[X[i]][Y[i]] = i;
  }
  for(i=(0);i<(N);i++){
    for(j=(0);j<(sz);j++){
      si = X[i] + dx[j];
      sj = Y[i] + dy[j];
      if(0 <= si  &&  si < 500 && 0 <= sj  &&  sj < 500 && mp[si][sj] >= 0){
        cnt[i]++;
      }
    }
  }
  hp.malloc(N);
  hp.init(N);
  for(i=(0);i<(N);i++){
    hp.change(i, cnt[i]);
  }
  while(90 * ress < N){
    i = hp.pop();
    if(use[i]==0){
      res[ress++] = i;
      use[i] = 1;
    }
    for(j=(0);j<(sz);j++){
      si = X[i] + dx[j];
      sj = Y[i] + dy[j];
      if(0 <= si  &&  si < 500 && 0 <= sj  &&  sj < 500){
        k = mp[si][sj];
        if(k >= 0 && use[k]==0){
          cnt[k]--;
          if(use[i]==1){
            use[k] = 2;
            cnt[k] = 0;
          }
          hp.change(k, cnt[k]);
        }
      }
    }
  }
  sortA_L(ress,res);
  wt_L(ress);
  wt_L('\n');
  {
    int XJIcIBrW;
    if(ress==0){
      wt_L('\n');
    }
    else{
      for(XJIcIBrW=(0);XJIcIBrW<(ress-1);XJIcIBrW++){
        wt_L(res[XJIcIBrW]+1);
        wt_L(' ');
      }
      wt_L(res[XJIcIBrW]+1);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N, X[3d5], Y[3d5], cnt[3d5], use[3d5];
// int mp[500][500];
// int ress, res[3d5];
// 
// int sz, dx[400], dy[400];
// 
// {
//   LHeap<int> hp;
//   int i, j, k, si, sj;
//   rd(N,(X--,Y--)(N));
// 
//   rep(i,-10,11) rep(j,-10,11) if(0 < i*i+j*j < 100) arrInsert(sz, sz, dx, i, dy, j);
// 
//   rep(i,500) rep(j,500) mp[i][j] = -1;
//   rep(i,N) mp[X[i]][Y[i]] = i;
// 
//   rep(i,N) rep(j,sz){
//     si = X[i] + dx[j];
//     sj = Y[i] + dy[j];
//     if(0 <= si < 500 && 0 <= sj < 500 && mp[si][sj] >= 0) cnt[i]++;
//   }
// 
//   hp.malloc(N);
//   hp.init(N);
//   rep(i,N) hp.change(i, cnt[i]);
//   while(90 * ress < N){
//     i = hp.pop();
//     if(use[i]==0){
//       res[ress++] = i;
//       use[i] = 1;
//     }
//     rep(j,sz){
//       si = X[i] + dx[j];
//       sj = Y[i] + dy[j];
//       if(0 <= si < 500 && 0 <= sj < 500){
//         k = mp[si][sj];
//         if(k >= 0 && use[k]==0){
//           cnt[k]--;
//           if(use[i]==1) use[k] = 2, cnt[k] = 0;
//           hp.change(k, cnt[k]);
//         }
//       }
//     }
//   }
// 
//   sortA(ress,res);
//   wt(ress);
//   wt(res(ress)+1);
// }
0