제출 #840836

#제출 시각아이디문제언어결과실행 시간메모리
840836NK_Misspelling (JOI22_misspelling)C++17
100 / 100
1783 ms303128 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> using namespace std; #define nl '\n' #define pb push_back #define pf push_front #define mp make_pair #define f first #define s second #define sz(x) int(x.size()) template<class T> using V = vector<T>; using pi = pair<int, int>; using vi = V<int>; using vpi = V<pi>; using ll = long long; using pl = pair<ll, ll>; using vpl = V<pl>; using vl = V<ll>; using db = long double; template<class T> using pq = priority_queue<T, V<T>, less<T>>; const int MOD = 1e9 + 7; const ll INFL = ll(1e17); const int LG = 19; int main() { cin.tie(0)->sync_with_stdio(0); int N, M; cin >> N >> M; V<vi> E1(N), E2(N); for(int i = 0; i < M; i++) { int l, r; cin >> l >> r; --l, --r; if (l < r) { E1[l].pb(-1); E1[r].pb(l); } else { E2[r].pb(-1); E2[l].pb(r); } } vi C1(N), C2(N); for(int t = 0; t < 2; t++) { multiset<int> L = {-1}; for(int x = 0; x < N; x++) { C1[x] = *rbegin(L); for(auto y : E1[x]) { if (y == -1) L.insert(x); else L.erase(L.find(y)); } E1[x].swap(E2[x]); } C1.swap(C2); } // for(int i = 0; i < N; i++) { // cout << C1[i] << " " << C2[i] << endl; // } V<vl> dp(N, vl(26, 0)), P(N, vl(26, 0)); auto qry = [&](int l, int r, int k) { if (l > r) return 0LL; return (P[r][k] - (l ? P[l-1][k] : 0) + MOD) % MOD; }; for(int i = 0; i < 26; i++) dp[0][i] = P[0][i] = 1; for(int i = 1; i < N; i++) { for(int c = 0; c < 26; c++) { for(int lc = 0; lc < 26; lc++) { if (lc == c) continue; if (lc < c) { // type 1 dp[i][c] = (dp[i][c] + qry(C1[i]+1, i-1, lc)) % MOD; } else { // type 2 dp[i][c] = (dp[i][c] + qry(C2[i]+1, i-1, lc)) % MOD; } } P[i][c] = (P[i-1][c] + dp[i][c]) % MOD; } } ll ans = 0; for(int i = 0; i < 26; i++) ans = (ans + P.back()[i]) % MOD; cout << ans << nl; exit(0-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...