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;
#define ll long long
const int mod = 1e9 + 7;
struct mint {
int v;
mint(long long x) {
if (x >= mod) x %= mod;
v = x;
}
mint() {v = 0;}
mint& operator+=(mint b) {
if ((v += b.v) >= mod) {
v -= mod;
}
return *this;
}
mint& operator-=(mint b) {
if ((v -= b.v) < 0) {
v += mod;
}
return *this;
}
mint& operator*=(mint b) {
v = 1ll * v * b.v % mod;
return *this;
}
mint power(mint a, int b) {
mint ans = 1;
while (b) {
if (b & 1) {
ans *= a;
}
a *= a, b >>= 1;
}
return ans;
}
mint& operator/=(mint b) {
v = 1ll * v * power(b, mod - 2).v % mod;
return *this;
}
friend mint operator+(mint a, mint b) {
return a += b;
}
friend mint operator-(mint a, mint b) {
return a -= b;
}
friend mint operator*(mint a, mint b) {
return a *= b;
}
friend mint operator/(mint a, mint b) {
return a /= b;
}
friend istream& operator>>(istream &is, mint a) {
return is >> a.v;
}
friend ostream& operator<<(ostream &os, mint a) {
return os << a.v;
}
};
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> st[n][2];
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
if (a < b) {
//s[i - 1] > s[i]
st[a + 1][0].push_back(b + 1);
} else {
//s[i - 1] < s[i]
st[b + 1][1].push_back(a + 1);
}
}
mint dp[n + 1][26];
for (int j = 0; j < 26; j++) dp[n][j] = 1;
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j < 26; j++) {
dp[i][j] = 1;
int cnt[n + 1][2]{};
int cur[2]{};
for (int k = i + (i == 0); k < n; k++) {
for (int x = 0; x < 2; x++) {
cur[x] += cnt[k][x];
for (auto en : st[k][x]) {
cur[x]++;
cnt[en][x]--;
}
}
if (!cur[1]) {
for (int l = 0; l < j; l++) {
dp[i][j] += dp[k + 1][l];
}
}
if (!cur[0]) {
for (int l = j + 1; l < 26; l++) {
dp[i][j] += dp[k + 1][l];
}
}
}
}
}
mint ans = 0;
for (int j = 0; j < 26; j++) {
ans += dp[0][j];
}
cout << ans << '\n';
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... |