제출 #858381

#제출 시각아이디문제언어결과실행 시간메모리
858381willychanMisspelling (JOI22_misspelling)C++14
0 / 100
1 ms4696 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; //#include<bits/extc++.h> //__gnu_pbds const int MOD = 1000000007; const int N = 5e5+5; ll dp[N][26][2][2]; bool start[N][2]; int inr[N][2]; int main(){ ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n,m;cin>>n>>m; for(int i=0;i<m;i++){ int a,b;cin>>a>>b; bool w=0; if(a>b) {w=1; swap(a,b);} start[a+1][w]=1; inr[a+1][w]++; inr[b+1][w]--; } for(int i=1;i<=n;i++){ inr[i][0]+=inr[i-1][0]; inr[i][1]+=inr[i-1][1]; } for(int i=0;i<26;i++) dp[1][i][0][0]=1; for(int i=2;i<=n;i++){ for(int c= 0;c<26;c++){ // cout<<(char)(c+'a')<<":"; for(int f=0;f<2;f++){ for(int s=0;s<2;s++){ int l[2][2]; int r[2][2]; for(int ff=0;ff<2;ff++){ for(int ss=0;ss<2;ss++){ l[ff][ss]=0; r[ff][ss]=25; } } // stupid trans if(start[i][0]){ if(f){ l[0][0]=c; r[0][0]=c; l[1][0]=c; r[1][0]=c; }else{ l[0][0] = 0; r[0][0] = c-1; l[1][0] = 0; r[1][0] = c-1; } }else if(inr[i][0]){ if(f){ l[0][0] = -1; r[0][0] = -1; l[1][0] = c; r[1][0] = c; }else{ l[0][0] = 0; r[0][0] = 25; l[1][0] = 0; r[1][0] = c-1; } }else{ if(f){ l[0][0] = -1; r[0][0] = -1; l[1][0] = -1; r[1][0] = -1; }else{ l[0][0] = 0; r[0][0] = 25; l[1][0] = 0; r[1][0] = 25; } } if(start[i][1]){ if(s){ l[0][1]=c; r[0][1]=c; l[1][1]=c; r[1][1]=c; }else{ l[0][1] = c+1; r[0][1] = 25; l[1][1] = c+1; r[1][1] = 25; } }else if(inr[i][1]){ if(s){ l[0][1] = -1; r[0][1] = -1; l[1][1] = c; r[1][1] = c; }else{ l[0][1] = 0; r[0][1] = 25; l[1][1] = c+1; r[1][1] = 25; } }else{ if(s){ l[0][1] = -1; r[0][1] = -1; l[1][1] = -1; r[1][1] = -1; }else{ l[0][1] = 0; r[0][1] = 25; l[1][1] = 0; r[1][1] = 25; } } // stupid trans for(int ff=0;ff<2;ff++){ for(int ss=0;ss<2;ss++){ int tl = max(l[ff][0],l[ss][1]); int tr = min(r[ff][0],r[ss][1]); if(tl>tr || tl<0 || tr<0) continue; for(int cc=tl;cc<=tr;cc++){ dp[i][c][f][s] = (dp[i][c][f][s]+dp[i-1][cc][ff][ss])%MOD; } } } // cout<<dp[i][c][f][s]<<","; } } //cout<<" "; } //cout<<"\n"; } ll ans = 0; for(int c=0;c<26;c++){ for(int f=0;f<2;f++){ for(int s=0;s<2;s++){ ans = (ans+dp[n][c][f][s])%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...