Submission #631490

#TimeUsernameProblemLanguageResultExecution timeMemory
631490abc864197532Misspelling (JOI22_misspelling)C++17
28 / 100
4043 ms4376 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair <int, int> #define X first #define Y second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T a, U ...b) { cout << a << ' ', abc(b...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) { return o >> a.X >> a.Y; } template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) { return o << '(' << a.X << ", " << a.Y << ')'; } template <typename T> ostream& operator << (ostream& o, vector<T> a) { bool is = false; if (a.empty()) return o << "{}"; for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;} return o << '}'; } template <typename T> struct vv : vector <vector <T>> { vv (int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {} vv (int n, int m) : vector <vector <T>> (n, vector <T>(m)) {} vv () {} }; template <typename T> struct vvv : vector <vv <T>> { vvv (int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {} vvv (int n, int m, int k) : vector <vv <T>> (n, vv <T>(m, k)) {} vvv () {} }; #ifdef Doludu #define test(args...) abc("[" + string(#args) + "]", args) #define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #else #define test(args...) void(0) #define owo ios::sync_with_stdio(false); cin.tie(0) #endif const int mod = 1e9 + 7, N = 200002; void add(int &i, int j) { i += j; if (i >= mod) i -= mod; } int dp[N][29]; void solve() { int n, m; cin >> n >> m; vector <int> mx1(n), mx2(n); auto add_edge = [&](int u, int v) { if (u < v) mx1[u] = max(mx1[u], v); else mx2[v] = max(mx2[v], u); }; for (int i = 0, u, v; i < m; ++i) { cin >> u >> v, --u, --v; add_edge(u, v); } // s[i - 1] < s[i] dp[0][0] = 1; for (int i = 0; i < n; ++i) { for (int c = 0; c < 26; ++c) { add(dp[i][c + 1], dp[i][c]); } // dp[i] -> dp[j]; // s[i - 1] != s[i] -> only care range start from i // s[j - 1] < s[j] // no i -> j, i < j for (int c = 0; c < 26; ++c) { int mx = mx1[i]; for (int j = i + 1; j < n; ++j) { if (mx < j) { add(dp[j][c + 1], dp[i][c]); } mx = max(mx, mx1[j]); } } // s[j - 1] > s[j] // no i -> j, i > j for (int c = 0; c < 26; ++c) { int mx = mx2[i]; for (int j = i + 1; j < n; ++j) { if (mx < j) { add(dp[j][0], dp[i][c]); add(dp[j][c], mod - dp[i][c]); } mx = max(mx, mx2[j]); } } } int ans = 0; for (int i = 0; i < n; ++i) for (int c = 0; c < 26; ++c) { add(ans, dp[i][c]); } cout << ans << '\n'; } int main () { owo; int t = 1; // cin >> t; while (t--) solve(); }
#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...