Submission #995321

#TimeUsernameProblemLanguageResultExecution timeMemory
995321CSQ31Misspelling (JOI22_misspelling)C++17
57 / 100
4088 ms61824 KiB
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define sz(a) (int)(a.size()) #define all(a) a.begin(),a.end() #define lb lower_bound #define ub upper_bound #define owo ios_base::sync_with_stdio(0);cin.tie(0); #define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr) #define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\ debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC)) typedef long long int ll; typedef long double ld; typedef pair<ll,ll> PII; typedef pair<int,int> pii; typedef vector<vector<int>> vii; typedef vector<vector<ll>> VII; ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);} const int MAXN = 5e5+5,MOD = 1e9+7; int dp[26][MAXN],add[2][MAXN]; int main() { int n,m; cin>>n>>m; for(int i=0;i<m;i++){ int l,r; cin>>l>>r; if(r > l){ //red,> add[0][l] = max(add[0][l],r); }else{ //blue,< add[1][r] = max(add[1][r],l); } } for(int i=0;i<26;i++)dp[i][1] = 1; for(int i=2;i<=n;i++){ int r = 0,b = 0; for(int j=i-1;j>=0;j--){ if(add[0][j] >= i)r++; if(add[1][j] >= i)b++; if(r && b)break; if(!r){ int sum = 0; for(int k=0;k<26;k++){ dp[k][i] += sum; if(dp[k][i]>=MOD)dp[k][i]-=MOD; sum += dp[k][j]; if(sum>=MOD)sum-=MOD; } } if(!b){ int sum = 0; for(int k=25;k>=0;k--){ dp[k][i] += sum; if(dp[k][i]>=MOD)dp[k][i]-=MOD; sum += dp[k][j]; if(sum>=MOD)sum-=MOD; } } } } int ans = 0; for(int i=1;i<=n;i++){ for(int j=0;j<26;j++){ ans+=dp[j][i]; if(ans>=MOD)ans-=MOD; } } cout<<ans<<'\n'; }
#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...