Submission #549289

#TimeUsernameProblemLanguageResultExecution timeMemory
549289Jarif_RahmanMisspelling (JOI22_misspelling)C++17
28 / 100
4054 ms203956 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); vector<pair<int, int>> cons; 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), cons.pb({a, b}); else gr[b+1].pb(i), grr[a].pb(i), cons.pb({b, a}); } 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++){ int s1 = 0, s2 = 0; for(int i = I+1; i < n; i++){ if(i != 0){ for(int x: grr[i-1]) if(cons[x].f >= I) s1--; for(int x: lrr[i-1]) if(cons[x].f >= I) s2--; } s1+=gr[i].size(); s2+=lr[i].size(); if(!s1 && !s2){ for(int j = 0; j < 26; j++) dp[I][J]+=dp[i][j], dp[I][J]%=md; break; } if(s1 && s2){ if(i == n-1) dp[I][J]++, dp[I][J]%=md; continue; } if(s1) 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...