Submission #549284

#TimeUsernameProblemLanguageResultExecution timeMemory
549284Jarif_RahmanMisspelling (JOI22_misspelling)C++17
8 / 100
4054 ms205352 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll md = 1000000007; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> gr(n), lr(n); vector<vector<int>> grr(n), lrr(n); for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--, b--; if(a < b) lr[a+1].pb(i), lrr[b].pb(i); else gr[b+1].pb(i), grr[a].pb(i); } vector<vector<ll>> dp(n, vector<ll>(26, 0)); dp[n-1] = vector<ll>(26, 1); for(int I = n-2; I >= 0; I--) for(int J = 0; J < 26; J++){ set<int> s1, s2; for(int i = I+1; i < n; i++){ if(i != 0){ for(int x: grr[i-1]) s1.erase(x); for(int x: lrr[i-1]) s2.erase(x); } for(int x: gr[i]) s1.insert(x); for(int x: lr[i]) s2.insert(x); if(s1.empty() && s2.empty()){ for(int j = 0; j < 26; j++) dp[I][J]+=dp[i][j], dp[I][J]%=md; break; } if(!s1.empty() && !s2.empty()){ if(i == n-1) dp[I][J]++, dp[I][J]%=md; continue; } if(!s1.empty()) for(int j = J+1; j < 26; j++) dp[I][J]+=dp[i][j], dp[I][J]%=md; else for(int j = 0; j < J; j++) dp[I][J]+=dp[i][j], dp[I][J]%=md; if(i == n-1) dp[I][J]++, dp[I][J]%=md; } } ll ans = 0; for(ll x: dp[0]) ans+=x, ans%=md; cout << ans << "\n"; }
#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...