Submission #955845

#TimeUsernameProblemLanguageResultExecution timeMemory
955845aymanrsMisspelling (JOI22_misspelling)C++14
28 / 100
906 ms1048576 KiB
#include<bits/stdc++.h> using namespace std; const int MOD = 1e9+7; int fx(int x){ if(x > MOD) x -= MOD; return x; } void solve(){ int n, m;cin >> n >> m; vector<int> rnsp[n], rpsn[n]; int ansp[n] = {0}, apsn[n] = {0}; int psn[n], nsp[n]; while(m--){ int a, b; cin >> a >> b;a--;b--; if(a < b) { ansp[a+1]++; if(b+1 < n) rnsp[b+1].push_back(a); } else { swap(a,b); apsn[a+1]++; if(b+1 < n) rpsn[b+1].push_back(a); } } multiset<int> spsn, snsp; for(int i = 1;i < n;i++) { while(ansp[i]--) snsp.insert(i-1); while(apsn[i]--) spsn.insert(i-1); for(int k : rnsp[i]) snsp.erase(snsp.find(k)); for(int k : rpsn[i]) spsn.erase(spsn.find(k)); psn[i] = spsn.empty() ? i : *spsn.rbegin(); nsp[i] = snsp.empty() ? i : *snsp.rbegin(); } int dp[n+1][n+1][26]; for(int j = 0;j <= n;j++) for(int i = 0;i < 26;i++) dp[n][j][i] = 1; for(int i = n-1;i;i--){ for(int j = 0;j < i;j++){ for(int k = 0;k < 26;k++){ dp[i][j][k]=0; for(int l = psn[i] >= j && psn[i] <= i-1 ? k : 0;l < (nsp[i] >= j && nsp[i] <= i-1 ? k+1 : 26);l++){ dp[i][j][k] = fx(dp[i][j][k] + dp[i+1][l == k ? j : i][l]); } } } } int ans = 0; for(int i = 0;i < 26;i++) ans = fx(ans+dp[1][0][i]); cout <<ans << '\n'; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); 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...