Submission #891354

#TimeUsernameProblemLanguageResultExecution timeMemory
891354amirhoseinfar1385Misspelling (JOI22_misspelling)C++17
29 / 100
337 ms168608 KiB
#include<bits/stdc++.h> using namespace std; const long long maxn=500000+10,K=27,mod=1000000007; long long ps[maxn][K],n,m; vector<pair<long long,long long>>allq[maxn]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for(long long i=0;i<m;i++){ long long u,v; cin>>u>>v; if(u>v){ swap(u,v); allq[u].push_back(make_pair(v,1)); } else{ allq[u].push_back(make_pair(v,0)); } } for(long long i=1;i<K;i++){ ps[1][i]=i; } set<pair<long long,long long>>stl,str; for(long long i=2;i<=n;i++){ for(auto x:allq[i-1]){ if(x.second==1){ str.insert(make_pair(i-1,x.first)); } else{ stl.insert(make_pair(i-1,x.first)); } } while((long long)str.size()>0&&(*str.rbegin()).second<i){ str.erase(*str.rbegin()); } while((long long)stl.size()>0&&(*stl.rbegin()).second<i){ stl.erase(*stl.rbegin()); } long long maxl=0,maxr=0; if((long long)str.size()>0){ maxr=(*str.rbegin()).first; } if((long long)stl.size()>0){ maxl=(*stl.rbegin()).first; } //cout<<maxl<<" "<<maxr<<" "<<i<<endl; if(maxl==maxr&&maxl!=0){ for(long long j=0;j<K;j++){ ps[i][j]=ps[i-1][j]; } continue; } if(maxl==maxr){ for(int j=0;j<K;j++){ ps[i][j]=ps[i-1][K-1]-ps[i-1][j]+ps[i-1][j-1]; ps[i][j]+=mod*4; ps[i][j]%=mod; } } if(maxl>maxr){ for(long long j=1;j<K;j++){ ps[i][j]=ps[i-1][K-1]-ps[maxl][K-1]-(ps[i-1][j]-ps[i-1][j-1]-(ps[maxl][j]-ps[maxl][j-1])); } for(long long j=1;j<K;j++){ ps[i][j]+=ps[maxl][K-1]-ps[maxl][j]-(ps[maxr][K-1]-ps[maxr][j]); } for(long long j=1;j<K;j++){ ps[i][j]+=ps[i][j-1]; ps[i][j]+=mod*4; ps[i][j]%=mod; } for(long long j=1;j<K;j++){ ps[i][j]+=ps[i-1][j]; ps[i][j]+=mod*4; ps[i][j]%=mod; } } else{ swap(maxl,maxr); for(long long j=1;j<K;j++){ ps[i][j]=ps[i-1][K-1]-ps[maxl][K-1]-(ps[i-1][j]-ps[i-1][j-1]-(ps[maxl][j]-ps[maxl][j-1])); } for(long long j=1;j<K;j++){ // cout<<j<<" "<<maxr<<" "<<ps[i-1][j-1]<<" "<<ps[maxr][j-1]<<endl; ps[i][j]+=ps[maxl][j-1]-(ps[maxr][j-1]); } for(long long j=1;j<K;j++){ ps[i][j]+=ps[i][j-1]; ps[i][j]+=mod*4; ps[i][j]%=mod; } for(long long j=1;j<K;j++){ ps[i][j]+=ps[i-1][j]; ps[i][j]+=mod*4; ps[i][j]%=mod; } } } // for(long long i=1;i<=n;i++){ // for(long long j=1;j<K;j++){ // cout<<ps[i][j]<<" "; // } // cout<<"\n"; // } cout<<ps[n][K-1]<<endl; }
#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...