이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include <udacha>
#include <iostream>
#include <string>
#include <deque>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <fstream>
#include <stack>
#include <cmath>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <array>
#include <chrono>
#include <functional>
#include <numeric>
#include <complex>
using namespace std;
#define ll long long
#define ld long double
#define ull uint64_t
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pli pair<ll, int>
#define plli pair<pll, int>
#define pld pair<ld, ld>
#define fst first
#define snd second
#define pdi pair<ld, int>
#define pdd pair<double, double>
#define piii pair<int, pii>
#define forn(i, n) for (int i = 1; i <= n; i++)
#define dforn(i, a, b) for (int i = a; i <= b; i++)
#define rforn(i, n) for (int i = n; i >= 1; i--)
#define rdforn(i, a, b) for (int i = b; i >= a; i--)
#define sforn(i, a, b, s) for (ll i = a; i <= b; i += s)
#define aforn(v, a) for (auto& v : a)
#define sz(a) ((int)a.size())
const int mod = 1e9 + 7;
const ld pi = acos(-1);
const ll N = 2e5 + 1;
const ll inf = 3e18;
const int iinf = 1e9;
const ld dinf = 1e16;
const double eps = 1e-9;
void solve() {
int n, s, f;
cin >> n >> s >> f;
ll ans = 0;
dforn(t1, 0, 1) dforn(t2, 0, 1) {
vector<ll> dp(n + 3);
dp[t1 + t2] = 1;
int cnt = 0;
forn(i, n) {
if (i != s && i != f) cnt++;
vector<ll> ndp(n + 3);
dforn(j, 0, n + 2) {
if (i == s) {
if (t1 == 1 && j > 0) (ndp[j - 1] += dp[j]) %= mod;
else if (t1 == 0 && j < n + 2) (ndp[j + 1] += dp[j]) %= mod;
}
else if (i == f) {
if (t2 == 1 && j > 0) (ndp[j - 1] += dp[j]) %= mod;
else if (t2 == 0 && j < n + 2) (ndp[j + 1] += dp[j]) %= mod;
}
else {
if (j < n + 2) (ndp[j + 1] += dp[j] * max(0, j + 1 - t1 - t2) % mod) %= mod;
if (j) (ndp[j - 1] += dp[j] * max(0, j - 1 - t1 - t2 + (cnt == n - 2)) % mod) %= mod;
}
}
dp = ndp;
}
(ans += dp[1]) %= mod;
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while (t--) solve();
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... |