結果
| 問題 |
No.1265 Balloon Survival
|
| コンテスト | |
| ユーザー |
LayCurse
|
| 提出日時 | 2020-10-23 22:07:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 2,000 ms |
| コード長 | 5,450 bytes |
| コンパイル時間 | 2,917 ms |
| コンパイル使用メモリ | 220,544 KB |
| 最終ジャッジ日時 | 2025-01-15 13:06:08 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#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, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
int i;
pair<T1, T2>*arr;
walloc1d(&arr, N, &mem);
for(i=(0);i<(N);i++){
arr[i].first = a[i];
arr[i].second = b[i];
}
sort(arr, arr+N);
for(i=(0);i<(N);i++){
a[i] = arr[i].first;
b[i] = arr[i].second;
}
}
template<class T1, class T2, class T3> void sortA_L(int N, T1 a[], T2 b[], T3 c[], void *mem = wmem){
int i;
pair<T1, pair<T2, T3> >*arr;
walloc1d(&arr, N, &mem);
for(i=(0);i<(N);i++){
arr[i].first = a[i];
arr[i].second.first = b[i];
arr[i].second.second = c[i];
}
sort(arr, arr+N);
for(i=(0);i<(N);i++){
a[i] = arr[i].first;
b[i] = arr[i].second.first;
c[i] = arr[i].second.second;
}
}
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(long long &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 T> inline T pow2_L(T a){
return a*a;
}
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;
}
int N;
long long X[1000];
long long Y[1000];
int es;
int e1[1000000];
int e2[1000000];
long long et[1000000];
int dead[1000];
int main(){
int i;
wmem = memarr;
int x;
int y;
int res = 0;
rd(N);
{
int Lj4PdHRW;
for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
rd(X[Lj4PdHRW]);
rd(Y[Lj4PdHRW]);
}
}
for(i=(0);i<(N);i++){
int j;
for(j=(i+1);j<(N);j++){
arrInsert(es, es, e1, i, e2, j, et,(pow2_L((X[i]-X[j])))+(pow2_L((Y[i]-Y[j]))));
}
}
sortA_L(es, et, e1, e2);
for(i=(0);i<(es);i++){
{
auto t_ynMSdg = (e1[i]);
auto KrdatlYV = ( e2[i]);
x = t_ynMSdg;
y = KrdatlYV;
}
if(dead[x] || dead[y]){
continue;
}
if(x==0 || y==0){
res++;
dead[x+y] = 1;
continue;
}
dead[x] = dead[y] = 1;
}
wt_L(res);
wt_L('\n');
return 0;
}
// cLay varsion 20201018-2
// --- original code ---
// int N; ll X[1000], Y[1000];
// int es, e1[1d6], e2[1d6]; ll et[1d6];
// int dead[1000];
// {
// int x, y, res = 0;
// rd(N,(X,Y)(N));
// rep(i,N) rep(j,i+1,N) arrInsert(es, es, e1, i, e2, j, et, (X[i]-X[j])**2+(Y[i]-Y[j])**2);
// sortA(es, et, e1, e2);
// rep(i,es){
// (x, y) = (e1[i], e2[i]);
// if(dead[x] || dead[y]) continue;
// if(x==0 || y==0) res++, dead[x+y] = 1, continue;
// dead[x] = dead[y] = 1;
// }
// wt(res);
// }
LayCurse