This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;
template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;
#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;
#define int ll
const int N = 210, C = 26, MOD = 1e9 + 7;
ll dp[N][N][C];
vector<tuple<int, int, bool>> a;
int pref[2][N][N];
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
a.resize(m);
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
a.push_back({min(u, v), max(u, v), u > v});
}
for (auto [x, y, inv] : a) {
++pref[inv][x + 1][y + 1];
}
for (int i = 0; i < 2; ++i) {
for (int x = 1; x <= n; ++x) {
for (int y = 1; y <= n; ++y) {
pref[i][x][y] += pref[i][x - 1][y] + pref[i][x][y - 1] - pref[i][x - 1][y - 1];
}
}
}
for (int i = 0; i < C; ++i) {
dp[1][1][i] = 1;
}
for (int i = 1; i < n; ++i) {
for (int j = 1; j <= i; ++j) {
for (int c0 = 0; c0 < C; ++c0) {
(dp[i + 1][j + 1][c0] += dp[i][j][c0]) %= MOD;
int cnt0 = pref[0][i][n] - pref[0][i - j][n] - pref[0][i][i] + pref[0][i - j][i];
int cnt1 = pref[1][i][n] - pref[1][i - j][n] - pref[1][i][i] + pref[1][i - j][i];
bool flag0 = !cnt0, flag1 = !cnt1;
for (int c1 = 0; c1 < c0 && flag0; ++c1) {
(dp[i + 1][1][c1] += dp[i][j][c0]) %= MOD;
}
for (int c1 = c0 + 1; c1 < C && flag1; ++c1) {
(dp[i + 1][1][c1] += dp[i][j][c0]) %= MOD;
}
}
}
}
cout << accumulate(dp[n][0], dp[n + 1][0], 0ll) % MOD;
}
# | 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... |