結果
| 問題 |
No.1121 Social Distancing in Cinema
|
| コンテスト | |
| ユーザー |
LayCurse
|
| 提出日時 | 2020-07-22 21:58:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 7,495 bytes |
| コンパイル時間 | 4,105 ms |
| コンパイル使用メモリ | 218,756 KB |
| 最終ジャッジ日時 | 2025-01-12 02:41:31 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 33 WA * 14 |
ソースコード
#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(hp.size){
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(hp.size){//} && 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);
// }
LayCurse