Submission #674066

#TimeUsernameProblemLanguageResultExecution timeMemory
674066someoneMisspelling (JOI22_misspelling)C++14
100 / 100
285 ms234000 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 5e5 + 42, L = 26, INF = 1e18 + 42, MOD = 1e9 + 7; int n, m, maxFin[N][2], first[N][2], a[N], b[N], dp[N][L][2]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--, b[i]--; if(a[i] < b[i]) maxFin[a[i]][0] = max(maxFin[a[i]][0], b[i]); else maxFin[b[i]][1] = max(maxFin[b[i]][1], a[i]); } dp[n][0][0] = 1; for(int i = n-1; i > -1; i--) { for(int j = 0; j < 2; j++) { first[i][j] = i; if(maxFin[i][j]) { first[i][j] = first[maxFin[i][j]][j]; for(int k = i+1; k <= maxFin[i][j] && first[k][j] != first[i][j]; k++) first[k][j] = first[i][j]; } } if(maxFin[i][0]) { int fi = first[i][0]; for(int j = 0; j < L; j++) dp[i][j][1] = dp[fi][j][1]; } else { int sum = 0; for(int j = L-1; j > -1; j--) { sum += dp[i+1][j][1]; dp[i][j][1] += sum; sum += dp[i+1][j][0]; } } if(maxFin[i][1]) { int fi = first[i][1]; for(int j = 0; j < L; j++) dp[i][j][0] = dp[fi][j][0]; } else { int sum = 0; for(int j = 0; j < L; j++) { sum += dp[i+1][j][0]; dp[i][j][0] += sum; sum += dp[i+1][j][1]; } } for(int j = 0; j < L; j++) dp[i][j][0] %= MOD, dp[i][j][1] %= MOD; } int sum = 0; for(int j = 0; j < L; j++) sum = (sum + dp[0][j][0] + dp[0][j][1]) % MOD; cout << sum; }
#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...