| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1310133 | thuhienne | Misspelling (JOI22_misspelling) | C++20 | 60 ms | 4676 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define thuhien ""
#define re exit(0);
const int mod = 1e9 + 7;
const int maxn = 2009;
int n,m;
pair <int,int> cond[maxn];
int dp[maxn][27];
//dp i j: so cach build [i,n] thoa man dieu kien trong m cai tren
int maxarr[maxn][maxn][2];
int main() {
// ios_base::sync_with_stdio(0);
// cin.tie(nullptr);
if (fopen(thuhien".inp","r")) {
freopen(thuhien".inp","r",stdin);
freopen(thuhien".out","w",stdout);
}
cin >> n >> m;
for (int i = 1;i <= m;i++) {
int a,b;cin >> a >> b;
cond[i] = {a,b};
int l = min(a,b),r = max(a,b);
maxarr[l][l][a < b] = max(maxarr[l][l][a < b],r);
}
for (int i = n;i >= 1;i--) {
for (int j = i + 1;j <= n;j++) {
maxarr[i][j][0] = max(maxarr[i][j - 1][0],maxarr[j][j][0]);
maxarr[i][j][1] = max(maxarr[i][j - 1][1],maxarr[j][j][1]);
}
}
for (int i = n;i >= 1;i--) {
for (int j = 0;j <= 'z' - 'a';j++) {
dp[i][j] = 1;
for (int k = i;k <= n;k++) {
int less = maxarr[i][k][0];
int greater = maxarr[i][k][1];
if (less > k && greater > k) continue;
else if (less <= k && greater <= k) {
for (int h = 0;h <= 'z' - 'a';h++) if (j != h) {
dp[i][j] = (dp[i][j] + dp[k + 1][h]) % mod;
}
} else {
for (int h = 0;h <= 'z' - 'a';h++) if ((less > k && j < h) || (greater > k && j > h)) {
dp[i][j] = (dp[i][j] + dp[k + 1][h]) % mod;
}
}
}
}
}
int res = 0;
for (int h = 0;h <= 'z' - 'a';h++) res = (res + dp[1][h]) % mod;
cout << res;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
