QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#793139 | #9798. Safety First | LGyxj | TL | 0ms | 0kb | C++14 | 1.6kb | 2024-11-29 17:09:09 | 2024-11-29 17:09:10 |
answer
//////////////////////////
// Author: lnyxj
// Time: 2024-11-27 10:48:38
///////////////////////////
// #pragma target("avx,avx2")
#include <bits/stdc++.h>
#define xx first
#define yy second
// #define int long long
// #define double long double
using namespace std;
const int N = 2000 + 3, M = 1e5 + 5, mod = 998244353, inv2 = mod + 1 >> 1, inf = 0x3f3f3f3f;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef long long ll;
int T;
int ans[M];
vector<pii> qst[N];
void init() {
// T = 1;
// qst[2000].push_back({2000, 1});
cin >> T;
for (int i = 1; i <= T; ++ i) {
int n, m;
cin >> n >> m;
if (n == 1) ans[i] = 1;
else qst[n].push_back({m, i});
}
}
inline void Add(int& x, int y) { ((x += y) >= mod) && (x -= mod); }
// #define Add(x, y) (((x += y) >= mod) && (x -= mod))
void solve() {
static int f[N][N];
for (int j = 1; j < N; ++ j)
for (int i = j; i < N; ++ i)
f[j][i] = 1;
for (int i = 2; i < N; ++ i) {
// if (i % 512 == 0) cout << i << '\n' << flush;
// const int cur = i & 1, las = cur ^ 1;
// memset(f[cur], 0, sizeof f[cur]);
for (int k = N - 1; k; -- k) {
for (int j = N - 1 - k; j >= k; -- j) {
// Add(f[cur][j][k], f[las][j][k]);
Add(f[k][j + k], f[k][j]);
}
}
for (int k = N - 1; k > 1; -- k)
for (int j = N - 1; j >= k; -- j) {
Add(f[k - 1][j], f[k][j]);
}
for (auto [m, id] : qst[i])
ans[id] = f[1][m];
}
for (int i = 1; i <= T; ++ i) cout << ans[i] << '\n';
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
init(); solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3 1 3 2 3 3 3