Submission #895195

#TimeUsernameProblemLanguageResultExecution timeMemory
895195alexander707070Misspelling (JOI22_misspelling)C++14
0 / 100
1 ms6492 KiB
#include<bits/stdc++.h> #define MAXN 500007 using namespace std; const int mod=1e9+7; int n,m,a,b,ans; int dp[MAXN][2][2][30]; bool li[MAXN][2][2][30]; int cnt[MAXN],pref[MAXN],cnt2[MAXN],pref2[MAXN]; int ff(int pos,int small,int big,int last){ if(small==0 and cnt[pos]>0)small=1; if(small==1 and pref[pos]==0)small=0; if(big==0 and cnt2[pos]>0)big=1; if(big==1 and pref2[pos]==0)big=0; if(pos==n+1)return 1; if(li[pos][small][big][last])return dp[pos][small][big][last]; li[pos][small][big][last]=true; for(int i=0;i<26;i++){ if(i<last and small>0)continue; if(i>last and big>0)continue; if(i==last){ dp[pos][small][big][last]+=ff(pos+1,small,big,i); }else{ dp[pos][small][big][last]+=ff(pos+1,0,0,i); } dp[pos][small][big][last]%=mod; } return dp[pos][small][big][last]; } 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){ cnt[a+1]++; pref[a+1]++; pref[b+1]--; }else{ cnt2[b+1]++; pref2[b+1]++; pref2[a+1]--; } } for(int i=1;i<=n;i++){ pref[i]+=pref[i-1]; pref2[i]+=pref2[i-1]; } for(int i=0;i<26;i++){ ans+=ff(2,0,0,i); ans%=mod; } cout<<ans<<"\n"; return 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...