Submission #908804

#TimeUsernameProblemLanguageResultExecution timeMemory
908804MinaRagy06Misspelling (JOI22_misspelling)C++17
89 / 100
4064 ms147540 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int mod = 1e9 + 7; struct mint { int v; mint(long long x) { if (x >= mod) x %= mod; v = x; } mint() {v = 0;} mint& operator+=(mint b) { if ((v += b.v) >= mod) { v -= mod; } return *this; } mint& operator-=(mint b) { if ((v -= b.v) < 0) { v += mod; } return *this; } mint& operator*=(mint b) { v = 1ll * v * b.v % mod; return *this; } mint power(mint a, int b) { mint ans = 1; while (b) { if (b & 1) { ans *= a; } a *= a, b >>= 1; } return ans; } mint& operator/=(mint b) { v = 1ll * v * power(b, mod - 2).v % mod; return *this; } friend mint operator+(mint a, mint b) { return a += b; } friend mint operator-(mint a, mint b) { return a -= b; } friend mint operator*(mint a, mint b) { return a *= b; } friend mint operator/(mint a, mint b) { return a /= b; } friend istream& operator>>(istream &is, mint a) { return is >> a.v; } friend ostream& operator<<(ostream &os, mint a) { return os << a.v; } }; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m; cin >> n >> m; vector<int> st[n][2]; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--, b--; if (a < b) { //s[i - 1] > s[i] st[a + 1][0].push_back(b + 1); } else { //s[i - 1] < s[i] st[b + 1][1].push_back(a + 1); } } mint dp[n + 1][26]; for (int j = 0; j < 26; j++) dp[n][j] = 1; set<int> active[26][2]; mint sum[26][2]; for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < 26; j++) { active[j][0].insert(i); for (int l = 0; l < j; l++) { sum[j][0] += dp[i + 1][l]; } active[j][1].insert(i); for (int l = j + 1; l < 26; l++) { sum[j][1] += dp[i + 1][l]; } for (auto en : st[i][0]) { auto it = active[j][1].lower_bound(i); while (it != active[j][1].end() && *it < en) { for (int l = j + 1; l < 26; l++) { sum[j][1] -= dp[*it + 1][l]; } active[j][1].erase(it); it = active[j][1].lower_bound(i); } } for (auto en : st[i][1]) { auto it = active[j][0].lower_bound(i); while (it != active[j][0].end() && *it < en) { for (int l = 0; l < j; l++) { sum[j][0] -= dp[*it + 1][l]; } active[j][0].erase(it); it = active[j][0].lower_bound(i); } } dp[i][j] = sum[j][0] + sum[j][1] + 1; } } mint ans = 0; for (int j = 0; j < 26; j++) { ans += dp[1][j]; } cout << ans << '\n'; return 0; }
#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...