結果

問題 No.1105 Many Triplets
ユーザー 夜
提出日時 2021-02-09 20:39:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,903 bytes
コンパイル時間 1,014 ms
コンパイル使用メモリ 101,548 KB
実行使用メモリ 4,564 KB
最終ジャッジ日時 2023-09-21 08:21:37
合計ジャッジ時間 2,560 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,564 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long mod = 1000000007;
	int m_size = 3;
	vector<vector<long long>> mat(3);
	long long y;
	cin >> y;
	y--;
	vector<vector<long long>> ans(3);
	for (int i = 0; i < m_size; i++) {
		for (int j = 0; j < m_size; j++) {
			if (i == j) {
				mat[i].emplace_back(1);
				ans[i].emplace_back(1);
			}
			else if (j == (i + 1) % 3) {
				mat[i].emplace_back(-1);
				ans[i].emplace_back(-1);
			}
			else {
				mat[i].emplace_back(0);
				ans[i].emplace_back(0);
			}
		}
	}
	y--;
	while (y > 0) {
		if ((y & 1) == 1) {
			vector<vector<long long>> ans_mem(220);
			for (int i = 0; i < m_size; i++) {
				for (int j = 0; j < m_size; j++) {
					ans_mem[i].emplace_back(0);
				}
			}
			for (int i = 0; i < m_size; i++) {
				for (int j = 0; j < m_size; j++) {
					for (int k = 0; k < m_size; k++) {
						ans_mem[i][j] += ans[i][k] * mat[k][j] % mod;
						ans_mem[i][j] %= mod;
					}
				}
			}
			ans = ans_mem;
		}
		vector<vector<long long>> mat_mem(220);
		for (int i = 0; i < m_size; i++) {
			for (int j = 0; j < m_size; j++) {
				mat_mem[i].emplace_back(0);
			}
		}
		for (int i = 0; i < m_size; i++) {
			for (int j = 0; j < m_size; j++) {
				for (int k = 0; k < m_size; k++) {
					mat_mem[i][j] += mat[i][k] * mat[k][j] % mod;
					mat_mem[i][j] %= mod;
				}
			}
		}
		mat = mat_mem;
		y >>= 1;
	}
	long long a, b, c;
	cin >> a >> b >> c;
	for (int i = 0; i < 3; i++) {
		long long ans1 = a * ans[i][0] % mod;
		ans1 += b * ans[i][1] % mod;
		ans1 += c * ans[i][2] % mod;
		ans1 %= mod;
		if (ans1 < 0)ans1 += mod;
		cout << ans1;
		if (i != 2) {
			cout << " ";
		}
	}
	cout << endl;
}
0