이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
using db = long double;
template<class T> using pq = priority_queue<T, V<T>, less<T>>;
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 19;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M; cin >> N >> M;
V<vi> E1(N), E2(N); for(int i = 0; i < M; i++) {
int l, r; cin >> l >> r; --l, --r;
if (l < r) {
E1[l].pb(-1);
E1[r].pb(l);
} else {
E2[r].pb(-1);
E2[l].pb(r);
}
}
vi C1(N), C2(N);
for(int t = 0; t < 2; t++) {
multiset<int> L = {-1};
for(int x = 0; x < N; x++) {
C1[x] = *rbegin(L);
for(auto y : E1[x]) {
if (y == -1) L.insert(x);
else L.erase(L.find(y));
}
E1[x].swap(E2[x]);
}
C1.swap(C2);
}
// for(int i = 0; i < N; i++) {
// cout << C1[i] << " " << C2[i] << endl;
// }
V<vl> dp(N, vl(26, 0)), P(N, vl(26, 0));
auto qry = [&](int l, int r, int k) {
if (l > r) return 0LL;
return (P[r][k] - (l ? P[l-1][k] : 0) + MOD) % MOD;
};
for(int i = 0; i < 26; i++) dp[0][i] = P[0][i] = 1;
for(int i = 1; i < N; i++) {
for(int c = 0; c < 26; c++) {
for(int lc = 0; lc < 26; lc++) {
if (lc == c) continue;
if (lc < c) { // type 1
dp[i][c] = (dp[i][c] + qry(C1[i]+1, i-1, lc)) % MOD;
} else { // type 2
dp[i][c] = (dp[i][c] + qry(C2[i]+1, i-1, lc)) % MOD;
}
}
P[i][c] = (P[i-1][c] + dp[i][c]) % MOD;
}
}
ll ans = 0;
for(int i = 0; i < 26; i++) ans = (ans + P.back()[i]) % MOD;
cout << ans << nl;
exit(0-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... |