QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#188688#6887. Data GenerationmeomeoWA 48ms3444kbC++141.6kb2023-09-26 11:19:402023-09-26 11:19:40

Judging History

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

  • [2023-09-26 11:19:40]
  • 评测
  • 测评结果:WA
  • 用时:48ms
  • 内存:3444kb
  • [2023-09-26 11:19:40]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long

using namespace std;

#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int mod = 998244353; 

ll modpow(ll b, ll e) {
	ll ans = 1;
	for (; e; b = b * b % mod, e /= 2)
		if (e & 1) ans = ans * b % mod;
	return ans;
}

template<class T, int N> struct Matrix {
	typedef Matrix M;
	array<array<T, N>, N> d{};
	M operator*(const M& m) const {
		M a;
		rep(i,0,N) rep(j,0,N)
			rep(k,0,N) a.d[i][j] += d[i][k]*m.d[k][j];
		return a;
	}
	vector<T> operator*(const vector<T>& vec) const {
		vector<T> ret(N);
		rep(i,0,N) rep(j,0,N) ret[i] += d[i][j] * vec[j];
		return ret;
	}
	M operator^(ll p) const {
		assert(p >= 0);
		M a, b(*this);
		rep(i,0,N) a.d[i][i] = 1;
		while (p) {
			if (p&1) a = a*b;
			b = b*b;
			p >>= 1;
		}
		return a;
	}
};

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);

	int t;

	cin >> t;

	while (t--) {
		int n, m;

		cin >> n >> m;

		if (m == 0) {
			cout << 0 << "\n";
			continue;	
		}

		Matrix<int, 2> a;

		int d = modpow((n*n) % mod, mod-2);
		a.d[0][0] = ((((n * n)%mod - 2) * d) % mod + mod) % mod;
		a.d[0][1] = (2 * d) % mod;
		a.d[1][0] = ((2 * (n - 1) * d) % mod + mod) % mod;
		a.d[1][1] = (((((n-1) * (n-1)) % mod) * d) % mod + mod) % mod;

		a = a ^ m;
		int res = (a.d[1][0]) % mod;
		res = (res * n) % mod;

		cout << res << "\n";
	}

	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 48ms
memory: 3444kb

input:

100000
19491001 19491001
999999999449325353 939501148
400027352 999999998707619026
999999998353720210 999999999303057191
1879045722 1874448608
999999998385974740 1710466660
109045962 999999998020190078
999999998217418921 999999998898659805
999999999999986692 999999998389218199
351693073 2130408866
1...

output:

470518893
-475931934
0
0
109722559
382218442
606416051
0
-487265932
0
0
834385674
0
0
850871189
238517887
478650730
171503492
0
249561089
145830685
5290406
-109910051
0
-28022814
765144780
-840002119
8528140
-3423551
0
0
91941852
449336848
0
0
0
0
288952947
0
524409726
793077037
0
0
-840626338
0
0
5...

result:

wrong answer 1st lines differ - expected: '79256423', found: '470518893'