이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define tiii tuple<int, int, int>
#define tiiii tuple<int, int, int, int>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
#define DEBUG
const int INF = (int)1e9 + 7;
using namespace std;
vector<int> A[505050];
vector<int> B[505050];
priority_queue<pii> C, D;
long long dp[505050][26];
long long L[505050][26];
long long R[505050][26];
long long S[505050];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m; cin >> n >> m;
for(int i = 0; i < m; ++i)
{
int x, y; cin >> x >> y;
if(x > y) A[y].push_back(x);
else B[x].push_back(y);
}
for(int i = 0; i < 26; ++i) dp[1][i] = 1, L[1][i] = i, R[1][i] = 25 - i, S[1] = 26;
for(int i = 1; i < n; ++i)
{
for(auto j : A[i]) C.push({i, j});
for(auto j : B[i]) D.push({i, j});
while(C.size() && C.top().ss <= i) C.pop();
while(D.size() && D.top().ss <= i) D.pop();
int x = (C.size() ? C.top().ff : 0);
int y = (D.size() ? D.top().ff : 0);
int z = max(x, y);
for(int j = 0; j < 26; ++j) dp[i + 1][j] = (2 * INF + dp[i][j] + (S[i] - S[z]) - (dp[i][j] - dp[z][j])) % INF;
if(x > y) for(int j = 0; j < 26; ++j) dp[i + 1][j] = (INF + dp[i + 1][j] + (L[x][j] - L[y][j])) % INF;
if(x < y) for(int j = 0; j < 26; ++j) dp[i + 1][j] = (INF + dp[i + 1][j] + (R[y][j] - R[x][j])) % INF;
for(int j = 1; j < 26; ++j) L[i + 1][j] = (L[i + 1][j - 1] + dp[i + 1][j - 1]) % INF;
for(int j = 24; j >= 0; --j) R[i + 1][j] = (R[i + 1][j + 1] + dp[i + 1][j + 1]) % INF;
for(int j = 0; j < 26; ++j) S[i + 1] = (S[i + 1] + dp[i + 1][j]) % INF;
}
cout << S[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... |