QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#188684 | #6887. Data Generation | meomeo | WA | 48ms | 3612kb | C++14 | 1.6kb | 2023-09-26 11:17:30 | 2023-09-26 11:17:30 |
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 - 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;
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: 3612kb
input:
100000 19491001 19491001 999999999449325353 939501148 400027352 999999998707619026 999999998353720210 999999999303057191 1879045722 1874448608 999999998385974740 1710466660 109045962 999999998020190078 999999998217418921 999999998898659805 999999999999986692 999999998389218199 351693073 2130408866 1...
output:
581518317 83548440 0 747695888 61112474 534734970 67252327 0 -819376682 0 0 276061471 603125537 701799827 747680470 308482191 -436338719 353281450 320136395 249561089 914724786 0 -4132290 0 311146465 866124356 -709934375 813337404 456085889 0 0 334927310 402303937 0 841764331 24663998 0 484181069 80...
result:
wrong answer 1st lines differ - expected: '79256423', found: '581518317'