結果

問題 No.66 輝け☆全国たこやき杯
ユーザー akakimidoriakakimidori
提出日時 2018-04-18 19:34:48
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 933 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 27,380 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 11:25:33
合計ジャッジ時間 932 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int m;
  scanf("%d",&m);
  int len=1<<m;
  int *a=(int *)malloc(sizeof(int)*len);
  int i;
  for(i=0;i<len;i++) scanf("%d",a+i);
  double *now=(double *)malloc(sizeof(double)*len);
  double *next=(double *)malloc(sizeof(double)*len);
  for(i=0;i<len;i++) now[i]=1;
  for(i=1;i<=m;i++){
    int j;
    for(j=0;j<len;j++) next[j]=0;
    for(j=0;j<len;j+=(1<<i)){
      int x,y;
      for(x=j;x<j+(1<<(i-1));x++){
	for(y=j+(1<<(i-1));y<j+(1<<i);y++){
	  int sx=a[x];
	  int sy=a[y];
	  double p=(double)sx*sx/(sx*sx+sy*sy);
	  next[x]+=now[x]*now[y]*p;
	  next[y]+=now[x]*now[y]*(1-p);
	}
      }
    }
    double *swap=now;
    now=next;
    next=swap;
  }
  printf("%.9lf\n",now[0]);
}

int main(void){
  run();
  return 0;
}
0