QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188690 | #6887. Data Generation | meomeo | WA | 49ms | 3652kb | C++14 | 1.6kb | 2023-09-26 11:23:25 | 2023-09-26 11:23:26 |
Judging History
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 + mod) * d) % mod + mod) % mod;
a.d[0][1] = (2 * d) % mod;
a.d[1][0] = ((2 * (n - 1 + mod) * d) % mod + mod) % mod;
a.d[1][1] = (((((n-1+mod) * (n-1+mod)) % mod) * d) % mod + mod + 1) % mod;
a = a ^ m;
int res = (a.d[1][0]) % mod;
res = (res * n) % mod;
cout << res << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 49ms
memory: 3652kb
input:
100000 19491001 19491001 999999999449325353 939501148 400027352 999999998707619026 999999998353720210 999999999303057191 1879045722 1874448608 999999998385974740 1710466660 109045962 999999998020190078 999999998217418921 999999998898659805 999999999999986692 999999998389218199 351693073 2130408866 1...
output:
0 0 662799367 0 0 29235122 0 0 0 476795814 783034742 0 255905572 852528062 -942646772 0 -971954586 0 99943268 249561090 0 794711881 0 0 0 0 -317656902 26237176 0 0 0 -764892700 0 116266210 -22374520 677524675 537897195 0 262389705 0 459298950 969200622 27287473 985397562 -898158713 102316995 -261339...
result:
wrong answer 1st lines differ - expected: '79256423', found: '0'