# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
901669 | alexander707070 | Misspelling (JOI22_misspelling) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define MAXN 20007
using namespace std;
const int mod=1e9+7;
int n,m,a,b,ans;
int dp[MAXN][30];
int maxs[MAXN][MAXN],maxs2[MAXN][MAXN],es[MAXN],es2[MAXN];
bool bad[MAXN],bad2[MAXN];
int pt,pt2;
int sum[30],sum2[30];
void calc_dp(){
pt=pt2=n+1;
for(int pos=n;pos>=1;pos--){
for(int f=pos+1;f<=es[pos];f++){
for(int letter=0;letter<26;letter++){
if(!bad[f])sum[letter]-=dp[f][letter]; sum[letter]+=mod; sum[letter]%=mod;
}
bad[f]=true;
}
for(int f=pos+1;f<=es2[pos];f++){
for(int letter=0;letter<26;letter++){
if(!bad2[f])sum2[letter]-=dp[f][letter]; sum2[letter]+=mod; sum2[letter]%=mod;
}
bad2[f]=true;
}
if(es[pos]>=pos+1)pt=pos+1;
if(es2[pos]>=pos+1)pt2=pos+1;
for(int letter=0;letter<26;letter++){
dp[pos][letter]=1;
for(int nxtletter=0;nxtletter<26;nxtletter++){
if(nxtletter==letter)continue;
if(nxtletter<letter)dp[pos][letter]+=sum[nxtletter];
if(nxtletter>letter)dp[pos][letter]+=sum2[nxtletter];
dp[pos][letter]%=mod;
}
}
for(int letter=0;letter<26;letter++){
sum[letter]+=dp[pos][letter]; sum[letter]%=mod;
sum2[letter]+=dp[pos][letter]; sum2[letter]%=mod;
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>a>>b;
if(a<b){
es[a]=max(es[a],b);
}else{
es2[b]=max(es2[b],a);
}
}
calc_dp();
for(int i=0;i<26;i++){
ans+=dp[1][i];
ans%=mod;
}
cout<<ans<<"\n";
return 0;
}