# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
569062 | dantoh000 | Misspelling (JOI22_misspelling) | C++14 | 1200 ms | 116480 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n,m;
int up[500005];
int down[500005];
int dp[500005][30];
set<int> gup, gdown;
int tot[500005];
int mod = 1000000007;
int main(){
scanf("%d%d",&n,&m);
for (int i = 1; i <= n; i++){
up[i] = down[i] = i;
}
for (int i = 0,a,b; i < m; i++){
scanf("%d%d",&a,&b);
if (a < b) up[a] = max(up[a], b);
else down[b] = max(down[b], a);
}
for (int i = 1; i <= n+1; i++){
gup.insert(i);
gdown.insert(i);
}
for (int i = 0; i < 26; i++) tot[i] = 1;
for (int i = n; i >= 1; i--){
while (*gup.lower_bound(i+1) <= up[i]){
int tmp = *gup.lower_bound(i+1);
gup.erase(tmp);
///printf("%d cannot transition to %d up\n");
int pfx = 0;
for (int j = 25; j >= 0; j--){
tot[j] = (tot[j] - pfx + mod)%mod;
pfx = (pfx + dp[tmp][j])%mod;
}
}
while (*gdown.lower_bound(i+1) <= down[i]){
int tmp = *gdown.lower_bound(i+1);
gdown.erase(tmp);
///printf("%d cannot transition to %d down\n");
int pfx = 0;
for (int j = 0; j < 26; j++){
tot[j] = (tot[j] - pfx + mod)%mod;
pfx = (pfx + dp[tmp][j])%mod;
}
}
int sum = 0;
for (int j = 0; j < 26; j++){
dp[i][j] = tot[j];
//printf("%d ",dp[i][j]);
sum = (sum+dp[i][j])%mod;
}
//printf("\n");
for (int j = 0; j < 26; j++){
tot[j] = ((tot[j] + sum)%mod - dp[i][j] + mod)%mod;
}
}
int ans = 0;
for (int i = 0; i < 26; i++){
ans = (ans + dp[1][i])%mod;
}
printf("%d\n",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |