이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 20'010;
const int alpha = 26;
const int mod = 1e9+7;
ll dp[N][alpha];
ll ps[N][32];
int mxa[N], mxb[N];
int n, m;
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> m;
Loop (_,0,m) {
int i, j;
cin >> i >> j;
//i=_+1,j=n;
--i; --j;
if (i < j)
mxa[i] = max(mxa[i], j);
else
mxb[j] = max(mxb[j], i);
}
dp[n][0] = 1;
Loop (x,0,alpha)
ps[n][x+1] = 1;
LoopR (i,0,n) {
ll ans[32] = {};
int a = mxa[i], b = mxb[i];
Loop (j,i+1,n+1) {
if (j > a && j > b) {
Loop (x,0,alpha)
ans[x] += ps[j][alpha];
goto end;
} else if (j > b) {
Loop (x,0,alpha)
ans[x] += ps[j][alpha] - ps[j][x+1];
} else if (j > a) {
Loop (x,0,alpha)
ans[x] += ps[j][x];
}
a = max(a, mxa[j]);
b = max(b, mxb[j]);
}
end:
Loop (x,0,alpha)
dp[i][x] = ans[x] % mod;
Loop (x,0,alpha)
ps[i][x+1] = ps[i][x] + dp[i][x];
}
ll ans = 0;
Loop (x,0,alpha)
ans += dp[0][x];
ans %= 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... |