제출 #1019950

#제출 시각아이디문제언어결과실행 시간메모리
1019950alexddMisspelling (JOI22_misspelling)C++17
100 / 100
960 ms307024 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int MOD = 1e9+7; int n,m; int dp[500005][30]; int pref[500005][30]; vector<pair<int,int>> baga[500005],scoate[500005]; signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m; int a,b; for(int i=1;i<=m;i++) { cin>>a>>b; if(a==b) continue; if(a<b) { baga[a+1].push_back({b,0}); scoate[b].push_back({a+1,0}); } else { swap(a,b); baga[a+1].push_back({b,1}); scoate[b].push_back({a+1,1}); } } for(int c=0;c<26;c++) dp[1][c]=pref[1][c]=1; int rez=26; set<pair<int,int>> s[2]; for(int i=2;i<=n;i++) { for(auto [ri,tip]:baga[i]) s[tip].insert({i,ri}); int p0=1,p1=1; if(!s[0].empty()) p0 = (*prev(s[0].end())).first; if(!s[1].empty()) p1 = (*prev(s[1].end())).first; for(int c=0;c<26;c++) { for(int u=c+1;u<26;u++) dp[i][c] += pref[i-1][u]-pref[p1-1][u]+MOD; for(int u=0;u<c;u++) dp[i][c] += pref[i-1][u]-pref[p0-1][u]+MOD; dp[i][c]%=MOD; pref[i][c] = (pref[i-1][c] + dp[i][c])%MOD; rez = (rez + dp[i][c])%MOD; } for(auto [le,tip]:scoate[i]) s[tip].erase({le,i}); } cout<<rez; 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...