이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 500005
#define maxc 26
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
ll dp[maxn][maxc],pref[maxn][maxc];
int lim[maxn][2];
vector<int> s1[maxn], s2[maxn];
void madd(ll &u, ll v) {
u = ((u + v) % mod + mod)%mod;
}
int main() {
io
int n, m;
cin >> n >> m;
multiset<int> v1, v2;
for (int i = 0;i < m;i++) {
int a, b;
cin >> a >> b;
if (a < b) {
s2[a].push_back(a);
s2[b].push_back(-a);
} else {
s1[b].push_back(b);
s1[a].push_back(-b);
}
}
for (int i = 1;i <= n;i++) {
for (auto j:s1[i]) {
if (j > 0) v1.insert(j);
else v1.erase(v1.find(-j));
}
for (auto j:s2[i]) {
if (j > 0) v2.insert(j);
else v2.erase(v2.find(-j));
}
if (v1.size()) lim[i][0] = *prev(v1.end());
if (v2.size()) lim[i][1] = *prev(v2.end());
}
for (int i = 0;i < maxc;i++) dp[0][i] = 1, pref[0][i] = i + 1;
for (int i = 1;i < n;i++) {
//debug(lim[i][0], lim[i][1]);
for (int j = 0;j < maxc;j++) {
if (j) {
madd(dp[i][j], (pref[i-1][j-1] - (lim[i][1] > 0 ? pref[lim[i][1]-1][j-1] : 0) + mod));
}
if (j < maxc - 1) {
madd(dp[i][j], pref[i-1][maxc-1] - pref[i-1][j] -
(lim[i][0] > 0 ? pref[lim[i][0]-1][maxc-1] - pref[lim[i][0]-1][j] : 0) + mod);
}
pref[i][j] = (dp[i][j] + (j ? pref[i][j-1] : 0))%mod;
}
//pary(dp[i], dp[i] + maxc);
for (int j = 0;j < maxc;j++) madd(pref[i][j], pref[i-1][j]);
}
ll ans = (pref[n-1][maxc-1]) %mod;
cout << ans << "\n";
}
# | 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... |