Submission #55441611


Source Code Expand

// LUOGU_RID: 165173523
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define cp complex<ld>

const int N=8.4e6+5;
const ld PI=acos(-1);
int n,m,U[N],num;
ll a[N],b[N],d[N],cnt;
cp F[N];
ld ans=0;

void FFT(cp *p,int len,int op){
  for(int i=0;i<len;i++) if(i<U[i]) swap(p[i],p[U[i]]);
  cp nw=cp(1,0),u,tmp;
  for(int k=2,lst=1;k<=len;lst=k,k<<=1){
	u=cp(cos(2*PI/k),op*sin(2*PI/k));
	for(int i=0;i<len;i+=k){
	  nw=cp(1,0);
	  for(int l=i;l<i+lst;l++,nw=nw*u)
	    tmp=nw*p[l+lst],p[l+lst]=p[l]-tmp,p[l]+=tmp;
	}
  }
}

void Mul(ll *a,ll *b,int n,int m){
  int P=1;
  for(P=1;P<n+m;P<<=1);
  for(int i=n;i<P;i++) a[i]=0;
  for(int i=m;i<P;i++) b[i]=0;
  for(int i=0;i<P;i++) U[i]=(U[i>>1]>>1)|((i&1)?P>>1:0),F[i]={(ld)a[i],(ld)b[i]};
  FFT(F,P,1);
  for(int i=0;i<P;i++) F[i]=F[i]*F[i];
  FFT(F,P,-1);

  for(int i=0;i<P;i++) a[i]=(ll)(F[i].imag()/P/2+0.4999);
}

int id(int x,int y){return x*2*n+y;}

int main(){
  /*2024.7.11 H_W_Y AT_icpc2013spring_f Point Distance FFT*/
  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  cin>>n;m=2*n*n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
	  cin>>a[id(i,j)],cnt+=a[id(i,j)];
  for(int i=0;i<=m;i++) b[m-i]=a[i];

  Mul(a,b,m+1,m+1);

  for(int i=0;i<=m;i++){
	int x=(m-i)/(2*n),y=(m-i)%(2*n);
	if(y>n) y=2*n-y,++x;
	// cerr<<x<<" "<<y<<endl;
	d[x*x+y*y]+=a[i];
  }
  d[0]-=cnt,d[0]/=2;
  cnt=0;
  for(int i=0;i<=m;i++) cnt+=d[i];
  for(int i=0;i<=m;i++) ans+=(ld)sqrt((ld)i)*d[i]/cnt;
  //ans/=(ld)cnt;

  cout<<fixed<<setprecision(10)<<ans<<'\n';
  num=0;
  for(int i=0;i<=m;i++){
	if(d[i]) cout<<i<<' '<<d[i]<<'\n',++num;
	if(num==10000) break;
  }
  return 0;
}

Submission Info

Submission Time
Task F - Point Distance
User H_W_Y
Language C++ 20 (gcc 12.2)
Score 100
Code Size 1737 Byte
Status AC
Exec Time 3222 ms
Memory 446060 KiB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 64
Set Name Test Cases
All 00_sample_00, 00_sample_01, 00_sample_02, 10_random_small_00, 10_random_small_01, 10_random_small_02, 10_random_small_03, 10_random_small_04, 10_random_small_05, 10_random_small_06, 10_random_small_07, 10_random_small_08, 10_random_small_09, 10_random_small_10, 10_random_small_11, 10_random_small_12, 10_random_small_13, 10_random_small_14, 10_random_small_15, 10_random_small_16, 10_random_small_17, 10_random_small_18, 10_random_small_19, 10_random_small_20, 10_random_small_21, 10_random_small_22, 10_random_small_23, 10_random_small_24, 10_random_small_25, 10_random_small_26, 10_random_small_27, 10_random_small_28, 10_random_small_29, 20_random_large_00, 20_random_large_01, 20_random_large_02, 20_random_large_03, 20_random_large_04, 30_maximum, 40_same_number_01, 40_same_number_02, 40_same_number_03, 40_same_number_04, 40_same_number_05, 40_same_number_06, 40_same_number_07, 40_same_number_08, 40_same_number_09, 50_sparse_00, 50_sparse_01, 50_sparse_02, 50_sparse_03, 50_sparse_04, 50_sparse_05, 50_sparse_06, 50_sparse_07, 50_sparse_08, 50_sparse_09, 90_teuchi_00, 90_teuchi_01, 90_teuchi_02, 90_teuchi_03, 90_teuchi_04, 90_teuchi_05
Case Name Status Exec Time Memory
00_sample_00 AC 1 ms 4056 KiB
00_sample_01 AC 1 ms 4052 KiB
00_sample_02 AC 1 ms 4012 KiB
10_random_small_00 AC 1 ms 4040 KiB
10_random_small_01 AC 1 ms 4084 KiB
10_random_small_02 AC 3 ms 4108 KiB
10_random_small_03 AC 1 ms 4068 KiB
10_random_small_04 AC 1 ms 4132 KiB
10_random_small_05 AC 3 ms 4524 KiB
10_random_small_06 AC 1 ms 4148 KiB
10_random_small_07 AC 2 ms 4288 KiB
10_random_small_08 AC 1 ms 4028 KiB
10_random_small_09 AC 2 ms 4168 KiB
10_random_small_10 AC 1 ms 4040 KiB
10_random_small_11 AC 2 ms 4020 KiB
10_random_small_12 AC 3 ms 4484 KiB
10_random_small_13 AC 3 ms 4468 KiB
10_random_small_14 AC 1 ms 4132 KiB
10_random_small_15 AC 5 ms 4996 KiB
10_random_small_16 AC 3 ms 4468 KiB
10_random_small_17 AC 2 ms 3980 KiB
10_random_small_18 AC 1 ms 4232 KiB
10_random_small_19 AC 2 ms 4256 KiB
10_random_small_20 AC 2 ms 4312 KiB
10_random_small_21 AC 2 ms 4004 KiB
10_random_small_22 AC 1 ms 3944 KiB
10_random_small_23 AC 1 ms 4092 KiB
10_random_small_24 AC 2 ms 4108 KiB
10_random_small_25 AC 1 ms 4028 KiB
10_random_small_26 AC 1 ms 4004 KiB
10_random_small_27 AC 1 ms 4068 KiB
10_random_small_28 AC 3 ms 4424 KiB
10_random_small_29 AC 2 ms 4264 KiB
20_random_large_00 AC 1553 ms 228044 KiB
20_random_large_01 AC 1581 ms 232824 KiB
20_random_large_02 AC 1559 ms 230324 KiB
20_random_large_03 AC 1561 ms 231928 KiB
20_random_large_04 AC 1559 ms 232276 KiB
30_maximum AC 3197 ms 446060 KiB
40_same_number_01 AC 3 ms 4568 KiB
40_same_number_02 AC 2 ms 4000 KiB
40_same_number_03 AC 3 ms 4540 KiB
40_same_number_04 AC 1 ms 3916 KiB
40_same_number_05 AC 3 ms 4500 KiB
40_same_number_06 AC 1 ms 4128 KiB
40_same_number_07 AC 5 ms 4888 KiB
40_same_number_08 AC 2 ms 4272 KiB
40_same_number_09 AC 3 ms 4344 KiB
50_sparse_00 AC 2 ms 4116 KiB
50_sparse_01 AC 1 ms 4096 KiB
50_sparse_02 AC 5 ms 4984 KiB
50_sparse_03 AC 1 ms 4024 KiB
50_sparse_04 AC 5 ms 4964 KiB
50_sparse_05 AC 1 ms 4112 KiB
50_sparse_06 AC 1 ms 4048 KiB
50_sparse_07 AC 1 ms 3988 KiB
50_sparse_08 AC 2 ms 4312 KiB
50_sparse_09 AC 1 ms 3900 KiB
90_teuchi_00 AC 3195 ms 446028 KiB
90_teuchi_01 AC 3222 ms 446036 KiB
90_teuchi_02 AC 3192 ms 446040 KiB
90_teuchi_03 AC 1 ms 3892 KiB
90_teuchi_04 AC 1 ms 3884 KiB
90_teuchi_05 AC 3192 ms 445820 KiB