제출 #556964

#제출 시각아이디문제언어결과실행 시간메모리
556964DanShadersMisspelling (JOI22_misspelling)C++17
0 / 100
2228 ms122668 KiB
#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 = 1 << 19, C = 26, MOD = 1e9 + 7; int dp[N][C + 1], t[2][2 * N]; signed main() { cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; fill(t[0], t[2], -1); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; --u, --v; int l = N + min(u, v) + 1, r = N + max(u, v); bool at = u > v; while (l <= r) { if (l & 1) t[at][l] = max(t[at][l], min(u, v)); if (!(r & 1)) t[at][r] = max(t[at][r], min(u, v)); l = (l + 1) / 2; r = (r - 1) / 2; } } for (int i = 0; i < 2; ++i) { for (int j = 0; j < N; ++j) { t[i][2 * j] = max(t[i][2 * j], t[i][j]); t[i][2 * j + 1] = max(t[i][2 * j + 1], t[i][j]); } } for (int i = 0; i < n; ++i) { for (int j = 0; j < C; ++j) { dp[i][j] = 0; } } for (int i = 0; i < C; ++i) { dp[n - 1][i] = 1; } for (int i = n - 1; i > 0; --i) { for (int j = 0; j < C; ++j) { (dp[i][j] += dp[i + 1][j]) %= MOD; } for (int c0 = 0; c0 < C; ++c0) { int j0 = t[0][N + i], j1 = t[1][N + i]; for (int c1 = 0; c1 < C; ++c1) { if (c0 != c1) { (dp[i - 1][c1] += dp[i][c0]) %= MOD; (dp[max(j0, j1)][c1] -= dp[i][c0]) %= MOD; // for (int j = max(j0, j1) + 1; j < i; ++j) { // (dp[j][c1] += dp[i][c0]) %= MOD; // } } } if (j0 < j1) { for (int c1 = 0; c1 < c0; ++c1) { (dp[max(j0, j1)][c1] += dp[i][c0]) %= MOD; (dp[min(j0, j1)][c1] -= dp[i][c0]) %= MOD; // for (int j = min(j0, j1) + 1; j <= max(j0, j1); ++j) { // (dp[j][c1] += dp[i][c0]) %= MOD; // } } } else { for (int c1 = c0 + 1; c1 < C; ++c1) { (dp[max(j0, j1)][c1] += dp[i][c0]) %= MOD; (dp[min(j0, j1)][c1] -= dp[i][c0]) %= MOD; // for (int j = min(j0, j1) + 1; j <= max(j0, j1); ++j) { // (dp[j][c1] += dp[i][c0]) %= MOD; // } } } } } for (int j = 0; j < C; ++j) { (dp[0][j] += dp[1][j]) %= MOD; } cout << accumulate(dp[0], dp[1], 0ll) % MOD; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...