QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188689 | #6887. Data Generation | meomeo | WA | 50ms | 3676kb | C++14 | 1.6kb | 2023-09-26 11:21:01 | 2023-09-26 11:21:02 |
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) * d) % mod + mod + 1) % 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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 50ms
memory: 3676kb
input:
100000 19491001 19491001 999999999449325353 939501148 400027352 999999998707619026 999999998353720210 999999999303057191 1879045722 1874448608 999999998385974740 1710466660 109045962 999999998020190078 999999998217418921 999999998898659805 999999999999986692 999999998389218199 351693073 2130408866 1...
output:
643294907 182503986 285471672 754435780 152020110 -550365273 684966345 790396049 -197584821 605740766 568241591 744812109 843940361 231687137 229814132 559429372 428559962 461489872 107917639 249561090 649301419 0 -252942264 -5541809 -118823878 676570161 545493208 95202440 616146385 0 59502918 0 800...
result:
wrong answer 1st lines differ - expected: '79256423', found: '643294907'