Submission #27695054
Source Code Expand
#include<bits/stdc++.h>
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define ll long long
using namespace std;
const int N = 307, mod = 998244353;
int n, m, dp[N][N], vis[N][N], arr[N], tp;
int f[N][N][N], pre[N][N][N];
int fi[N][N][N], st[N][N];
void init (int l, int r) {
L(a, 0, n + 1) pre[l][a][r] = f[l][a][r];
L(a, 1, n + 1) (pre[l][a][r] += pre[l][a - 1][r]) %= mod;
}
int main () {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m;
L(i, 1, m) {
int l, r;
cin >> l >> r;
vis[l][r] = true;
}
L(i, 0, n) {
dp[i + 1][i] = 1, f[i][i][i + 1] = mod - 1, init (i, i + 1);
}
L(i, 1, n) {
st[i + 1][i] = 1e9;
R(j, i, 1) st[j][i] = vis[j][i] ? j : st[j + 1][i];
}
L(i, 1, n) {
L(l, i, n) {
L(r, l, n) {
if(l < r) fi[i][l][r] = fi[i][l][r - 1];
else fi[i][l][r] = l;
fi[i][l][r] = min(fi[i][l][r], st[i][r]);
// L(u, i, l - 1) if(vis[u][r]) fi[i][l][r] = min(fi[i][l][r], u);
}
}
}
L(len, 1, n) {
L(l, 1, n - len + 1) {
int r = l + len - 1;
L(j, l, r) {
int cr = j - 1;
// L(k, l - 1, j - 1) {
// bool ok = true;
// L(a, l, k) L(b, j, r) if(vis[a][b]) ok = false;
// if(ok) (f[l - 1][j][r + 1] += mod - f[l - 1][k][j]) %= mod;
// }
cr = fi[l][j][r] - 1;
f[l - 1][j][r + 1] = mod - pre[l - 1][cr][j];
// L(k, l - 1, cr) (f[l - 1][j][r + 1] += mod - f[l - 1][k][j]) %= mod;
f[l - 1][j][r + 1] = (ll) f[l - 1][j][r + 1] * dp[j + 1][r] % mod;
(dp[l][r] += f[l - 1][j][r + 1]) %= mod;
f[l - 1][l - 1][r + 1] = mod - dp[l][r];
}
init (l - 1, r + 1);
// cout << l << ' ' << r << " : " << dp[l][r] << '\n';
// L(x, 1, (1 << (r - l + 1)) - 1) {
// int c = __builtin_popcount(x);
// tp = 0;
// arr[++tp] = l - 1;
// L(t, l, r) if(x >> (t - l) & 1) arr[++tp] = t;
// arr[++tp] = r + 1;
// c = (c & 1) ? 1 : mod - 1;
// L(j, 1, tp - 2)
// L(u, arr[j] + 1, arr[j + 1])
// L(v, arr[j + 2], r)
// if(vis[u][v])
// c = 0;
// L(j, 1, tp - 1)
// c = (ll) c * dp[arr[j] + 1][arr[j + 1] - 1] % mod;
// (dp[l][r] += c) %= mod;
// }
}
}
cout << dp[1][n] << '\n';
return 0;
}
Submission Info
| Submission Time |
|
| Task |
B - Range Argmax |
| User |
zhoukangyang |
| Language |
C++ (GCC 9.2.1) |
| Score |
900 |
| Code Size |
2295 Byte |
| Status |
AC |
| Exec Time |
432 ms |
| Memory |
225444 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
900 / 900 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt |
| All |
00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00-sample-001.txt |
AC |
8 ms |
3636 KiB |
| 00-sample-002.txt |
AC |
2 ms |
3868 KiB |
| 00-sample-003.txt |
AC |
2 ms |
3996 KiB |
| 01-001.txt |
AC |
2 ms |
3604 KiB |
| 01-002.txt |
AC |
9 ms |
8296 KiB |
| 01-003.txt |
AC |
309 ms |
184920 KiB |
| 01-004.txt |
AC |
99 ms |
74464 KiB |
| 01-005.txt |
AC |
188 ms |
120584 KiB |
| 01-006.txt |
AC |
73 ms |
53836 KiB |
| 01-007.txt |
AC |
52 ms |
38004 KiB |
| 01-008.txt |
AC |
183 ms |
119672 KiB |
| 01-009.txt |
AC |
352 ms |
205508 KiB |
| 01-010.txt |
AC |
237 ms |
151108 KiB |
| 01-011.txt |
AC |
5 ms |
5332 KiB |
| 01-012.txt |
AC |
287 ms |
173356 KiB |
| 01-013.txt |
AC |
14 ms |
13676 KiB |
| 01-014.txt |
AC |
396 ms |
225276 KiB |
| 01-015.txt |
AC |
395 ms |
225320 KiB |
| 01-016.txt |
AC |
399 ms |
225352 KiB |
| 01-017.txt |
AC |
417 ms |
224984 KiB |
| 01-018.txt |
AC |
424 ms |
225100 KiB |
| 01-019.txt |
AC |
415 ms |
225108 KiB |
| 01-020.txt |
AC |
400 ms |
225404 KiB |
| 01-021.txt |
AC |
397 ms |
225336 KiB |
| 01-022.txt |
AC |
399 ms |
225444 KiB |
| 01-023.txt |
AC |
395 ms |
225436 KiB |
| 01-024.txt |
AC |
395 ms |
225312 KiB |
| 01-025.txt |
AC |
432 ms |
224964 KiB |
| 01-026.txt |
AC |
395 ms |
225312 KiB |
| 01-027.txt |
AC |
392 ms |
225372 KiB |