結果

問題 No.1704 Many Bus Stops (easy)
ユーザー atjh16atjh16
提出日時 2021-10-16 20:37:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 2,318 ms
コンパイル使用メモリ 211,320 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 22:17:25
合計ジャッジ時間 5,011 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 29 ms
4,348 KB
testcase_02 AC 16 ms
4,348 KB
testcase_03 AC 16 ms
4,348 KB
testcase_04 AC 16 ms
4,348 KB
testcase_05 AC 16 ms
4,348 KB
testcase_06 AC 16 ms
4,348 KB
testcase_07 AC 16 ms
4,348 KB
testcase_08 AC 16 ms
4,348 KB
testcase_09 AC 16 ms
4,348 KB
testcase_10 AC 16 ms
4,348 KB
testcase_11 AC 16 ms
4,348 KB
testcase_12 AC 16 ms
4,348 KB
testcase_13 AC 17 ms
4,348 KB
testcase_14 AC 16 ms
4,348 KB
testcase_15 AC 16 ms
4,348 KB
testcase_16 AC 16 ms
4,348 KB
testcase_17 AC 16 ms
4,348 KB
testcase_18 AC 16 ms
4,348 KB
testcase_19 AC 16 ms
4,348 KB
testcase_20 AC 16 ms
4,348 KB
testcase_21 AC 16 ms
4,348 KB
testcase_22 AC 28 ms
4,348 KB
testcase_23 AC 29 ms
4,348 KB
testcase_24 AC 29 ms
4,348 KB
testcase_25 AC 29 ms
4,348 KB
testcase_26 AC 29 ms
4,348 KB
testcase_27 AC 29 ms
4,348 KB
testcase_28 AC 29 ms
4,348 KB
testcase_29 AC 29 ms
4,348 KB
testcase_30 AC 29 ms
4,348 KB
testcase_31 AC 29 ms
4,348 KB
testcase_32 AC 29 ms
4,348 KB
testcase_33 AC 29 ms
4,348 KB
testcase_34 AC 29 ms
4,348 KB
testcase_35 AC 29 ms
4,348 KB
testcase_36 AC 28 ms
4,348 KB
testcase_37 AC 29 ms
4,348 KB
testcase_38 AC 29 ms
4,348 KB
testcase_39 AC 29 ms
4,348 KB
testcase_40 AC 29 ms
4,348 KB
testcase_41 AC 29 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long t, n, m, w;
const long long M = 1e9 + 7;
typedef vector<vector<long long>> mat;

long long powm(long long a, long long b) {
	long long u = 1, v = a;

	while (b > 0) {
		if (b & 1)
			u = u * v % M;

		v = v * v % M;
		b >>= 1;
	}

	return u;
}

mat mprod(mat& a, mat& b) {
	mat c(a.size(), vector<long long>(b[0].size()));

	for (int i = 0; i < a.size(); i++) {
		for (int k = 0; k < b.size(); k++) {
			for (int j = 0; j < b[0].size(); j++) {
				c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % M;
			}
		}
	}

	return c;
}

mat powmat(mat a, long long t) {
	mat b(a.size(), vector<long long>(a.size()));

	for (int i = 0; i < a.size(); i++)
		b[i][i] = 1;

	while (t > 0) {
		if (t & 1)
			b = mprod(b, a);

		a = mprod(a, a);
		t >>= 1;
	}

	return b;
}

int main()
{
	cin >> t;
	w = powm(3, M - 2);

	for (int i = 0; i < t; i++) {
		cin >> n;

		mat a = { {w, M - w}, {1, 0} };
		mat d = powmat(a, n);

		m = (d[1][0] * 2 * powm(9, M - 2) % M + d[1][1] * 2 * powm(3, M - 2) % M) % M;
		m = (m + powm(5, M - 2)) % M;

		long long x = 2 * powm(15, M - 2) % M * powm(2, n) % M * powm(w, n) % M;

		if (n % 2 == 0)
			m = (m + x) % M;
		else
			m = (m + M - x) % M;

		cout << m << endl;
	}
}
0