結果

問題 No.567 コンプリート
ユーザー akakimidori
提出日時 2018-08-02 04:34:03
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 505 ms
コンパイル使用メモリ 23,552 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-19 17:02:03
合計ジャッジ時間 1,209 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:13:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |   scanf("%d",&n);
      |   ^~~~~~~~~~~~~~

ソースコード

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 n;
  scanf("%d",&n);
  const int f=6;
  const double p=(double)1/f;
  double *now=(double *)calloc(f+1,sizeof(double));
  now[1]=1;
  double *next=(double *)calloc(f+1,sizeof(double));
  int i;
  for(i=2;i<=n;i++){
    int j;
    for(j=1;j<=f;j++){
      next[j]=now[j]*(j*p)+now[j-1]*((f-(j-1))*p);
    }
    double *swap=now;
    now=next;
    next=swap;
  }
  printf("%.9lf\n",now[f]);
}

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