제출 #895307

#제출 시각아이디문제언어결과실행 시간메모리
895307alexander707070Misspelling (JOI22_misspelling)C++14
28 / 100
4045 ms171856 KiB
#include<bits/stdc++.h> #define MAXN 2007 using namespace std; const int mod=1e9+7; int n,m,a,b,ans; int dp[MAXN][MAXN][30]; bool li[MAXN][MAXN][30]; int cnt[MAXN],pref[MAXN],cnt2[MAXN],pref2[MAXN]; int maxs[MAXN][MAXN],maxs2[MAXN][MAXN],es[MAXN],es2[MAXN]; bool open(int l,int r){ return maxs[l][r]>=r; } bool open2(int l,int r){ return maxs2[l][r]>=r; } int ff(int pos,int change,int last){ if(pos==n+1)return 1; if(li[pos][change][last])return dp[pos][change][last]; li[pos][change][last]=true; if(last!=26)dp[pos][change][last]=ff(pos+1,change,last); for(int i=0;i<26;i++){ if(i==last)continue; if(i<last and open(change+1,pos))continue; if(i>last and open2(change+1,pos))continue; dp[pos][change][last]+=ff(pos+1,pos,i); dp[pos][change][last]%=mod; } return dp[pos][change][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]++; es[a+1]=max(es[a+1],b); pref[a+1]++; pref[b+1]--; }else{ cnt2[b+1]++; es2[b+1]=max(es2[b+1],a); pref2[b+1]++; pref2[a+1]--; } } for(int i=1;i<=n;i++){ for(int f=i;f<=n;f++){ maxs[i][f]=max(maxs[i][f-1],es[f]); maxs2[i][f]=max(maxs2[i][f-1],es2[f]); } } cout<<ff(1,0,26)<<"\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...