제출 #1043711

#제출 시각아이디문제언어결과실행 시간메모리
1043711MarwenElarbiMisspelling (JOI22_misspelling)C++17
60 / 100
66 ms25428 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define ll long long #define pb push_back #define fi first #define se second #define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; const int nax=1e5+5; const int MOD=1e9+7; int n,k; long long dp[nax][26]; vector<int> up[nax]; vector<int> down[nax]; long long sum_up[26]; long long sum_down[26]; int main(){ optimise; cin>>n>>k; for (int i = 0; i < k; ++i) { int x,y; cin>>x>>y; if(x==y) continue; if(x>y){ up[y].pb(x); }else{ down[x].pb(y); } } for (int i = 0; i < 26; ++i) { dp[n][i]=1; } set<int> s,t; for (int i = n-1; i >= 1; --i) { s.insert(i+1); t.insert(i+1); for (int j = 0; j < 26; ++j) { sum_up[j]+=dp[i+1][j]; sum_down[j]+=dp[i+1][j]; } for(auto u:up[i]){ auto it=s.lower_bound(i+1); while(it!=s.end() && (*it)<=u){ for (int j = 0; j < 26; ++j) sum_up[j]-=dp[(*it)][j]; it=s.erase(it); } } for(auto u:down[i]){ auto it=t.lower_bound(i+1); while(it!=t.end() && (*it)<=u){ for (int j = 0; j < 26; ++j) sum_down[j]-=dp[(*it)][j]; it=t.erase(it); } } long long sum=0; for (int j = 0; j < 26; ++j) { dp[i][j]+=sum; sum+=sum_down[j]; } sum=0; for (int j = 25; j >= 0; --j) { dp[i][j]+=sum; sum+=sum_up[j]; } for (int j = 0; j < 26; ++j) { dp[i][j]++; dp[i][j]%=MOD; } } long long ans=0; for (int i = 0; i < 26; ++i) { ans+=dp[1][i]; ans%=MOD; } cout <<ans<<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...