QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768964#8049. Equal SumsAllHailLelouchWA 0ms3588kbC++14994b2024-11-21 15:28:292024-11-21 15:28:29

Judging History

你现在查看的是最新测评结果

  • [2024-11-21 15:28:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3588kb
  • [2024-11-21 15:28:29]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

constexpr int P = 998244353;

typedef std::array<std::array<i64, 3>, 3> Matrix;

Matrix operator *(const Matrix &a, Matrix &b) {
	Matrix c{0, 0, 0, 0, 0, 0, 0, 0, 0};
	for (auto k : {0, 1, 2}) {
		for (auto i : {0, 1, 2}) {
			for (auto j : {0, 1, 2}) {
				c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % P;
			}
		}
	}
	return c;
}

int main() {
	std::cin.tie(nullptr) -> sync_with_stdio(false);
	int n, m;
	std::cin >> n >> m;
	
	Matrix I{1, 0, 0, 0, 1, 0, 0, 0, 1};
	Matrix B{0, 1, 1, 1, 0, 0, 0, 1, 0};

	for (int k = n; k; k /= 2, B = B * B) if (k & 1) I = I * B;
	int Z = (I[0][0] + I[1][1] + I[2][2]);

	std::unordered_map<int, i64> dp;
	auto f = [&](auto self, int x) -> int {
		if (x <= 1) return x ? Z : 1;
		if (dp.count(x)) return dp[x];
		if (x & 1) return dp[x] = Z * self(self, x / 2) % P;
		return dp[x] = (self(self, x / 2), self(self, x / 2 - 1)) % P;
	};
	std::cout << f(f, m);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3588kb

input:

2 3
1 2
2 3
1 4
2 2
1 3

output:

4

result:

wrong answer 1st numbers differ - expected: '2', found: '4'