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;
using ll = long long;
int const MOD = 1e9 + 7;
int const N = 500005;
int ogr[N], ols[N];
int isoogr[N], isools[N];
ll add(ll a, ll b) {
return (a + b) % MOD;
}
void solve() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
if (a < b) {
ols[a]++;
ols[b]--;
isools[a]++;
} else {
ogr[b]++;
isoogr[b]++;
ogr[a]--;
}
}
partial_sum(ols, ols + N, ols);
partial_sum(ogr, ogr + N, ogr);
array<array<ll, 4>, 26> dp;
for (int i = 0; i < 26; ++i) dp[i][0] = 1, dp[i][1] = dp[i][2] = dp[i][3] = 0;
for (int i = 1; i < n; ++i) {
array<array<ll, 4>, 26> pdp = dp;
for (int j = 0; j < 26; ++j) for (int k = 0; k < 4; ++k) dp[j][k] = 0;
for (int j = 0; j < 26; ++j) {
if (isoogr[i] > 0) {
pdp[j][1] = add(pdp[j][1], pdp[j][0]);
pdp[j][0] = 0;
pdp[j][3] = add(pdp[j][3], pdp[j][2]);
pdp[j][2] = 0;
}
if (ogr[i] == 0) {
pdp[j][0] = add(pdp[j][0], pdp[j][1]);
pdp[j][1] = 0;
pdp[j][2] = add(pdp[j][2], pdp[j][3]);
pdp[j][3] = 0;
}
if (isools[i] > 0) {
pdp[j][2] = add(pdp[j][2], pdp[j][0]);
pdp[j][0] = 0;
pdp[j][3] = add(pdp[j][3], pdp[j][1]);
pdp[j][1] = 0;
}
if (ols[i] == 0) {
pdp[j][0] = add(pdp[j][0], pdp[j][2]);
pdp[j][2] = 0;
pdp[j][1] = add(pdp[j][1], pdp[j][3]);
pdp[j][3] = 0;
}
}
for (int i = 0; i < 26; ++i) {
for (int k = 0; k < 4; ++k) cerr << pdp[i][k] << ' ';
cerr << endl;
}
for (int j = 0; j < 26; ++j) {
dp[j][1] = add(dp[j][1], pdp[j][1]);
dp[j][2] = add(dp[j][2], pdp[j][2]);
dp[j][3] = add(dp[j][3], pdp[j][3]);
for (int k = 0; k < 26; ++k) {
dp[k][0] = add(dp[k][0], pdp[j][0]);
if (k < j) {
dp[k][0] = add(dp[k][0], pdp[j][2]);
} else if (k > j) {
dp[k][0] = add(dp[k][0], pdp[j][1]);
}
}
}
}
for (int i = 0; i < 26; ++i) {
for (int k = 0; k < 4; ++k) cerr << dp[i][k] << ' ';
cerr << endl;
}
ll ans = 0;
for (int i = 0; i < 26; ++i) {
for (int k = 0; k < 4; ++k) {
ans = add(ans, dp[i][k]);
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
# | 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... |