結果

問題 No.567 コンプリート
ユーザー tnakao0123tnakao0123
提出日時 2017-09-14 19:44:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,473 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 83,328 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 06:38:36
合計ジャッジ時間 1,582 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 567.cc: No.567 コンプリート - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int D = 6;
const int DBITS = 1 << D;

/* typedef */

typedef double mat[DBITS][DBITS];

/* global variables */

void matmul(int n, const mat a, const mat b, mat c) { // a*b -> c
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      c[i][j] = 0.0;
      for (int k = 0; k < n; k++) c[i][j] += a[i][k] * b[k][j];
    }
}

void matpow(int n, const mat a, int b, mat c) { // a^b -> c
  mat q, t;
  for (int i = 0; i < n; i++) {
    fill(c[i], c[i] + n, 0.0);
    c[i][i] = 1.0;
  }
  memcpy(q, a, sizeof(mat));

  while (b) {
    if (b & 1) {
      matmul(n, c, q, t);
      memcpy(c, t, sizeof(mat));
    }

    matmul(n, q, q, t);
    memcpy(q, t, sizeof(mat));
    b >>= 1;
  }
}

/* subroutines */

/* main */

int main() {
  int n;
  cin >> n;

  mat a, c;
  for (int i = 0; i < DBITS; i++) fill(a[i], a[i] + DBITS, 0.0);

  for (int bits = 0; bits < DBITS; bits++)
    for (int d = 0, bd = 1; d < D; d++, bd <<= 1)
      a[bits | bd][bits] += 1.0 / D;

  matpow(DBITS, a, n, c);
  printf("%.8lf\n", c[DBITS - 1][0]);
}
0