이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
void setIO() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen("input.inp", "r")) {
freopen("input.inp", "r", stdin);
freopen("input.out", "w", stdout);
}
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7;
int n, s, t, dp[2][2002][3][3];
void add(int &a, int b) {
a += b;
if (a >= MOD) a -= MOD;
}
int mul(int a, int b) {
return 1LL * a * b % MOD;
}
int main() {
setIO();
cin >> n >> s >> t;
int cur = 0, nxt = 1;
memset(dp[cur], 0, sizeof(dp[cur]));
dp[cur][0][0][0] = 1;
foru(i, 0, n-1) {
memset(dp[nxt], 0, sizeof(dp[nxt]));
foru(j, 0, i) {
foru(x, 0, 2) {
foru(y, 0, 2) if (dp[cur][j][x][y] > 0) {
int val = dp[cur][j][x][y];
// cout << i << " " << j << " " << x << " " << y << " " << val << "\n";
if (i+1 == s) {
add(dp[nxt][j][1][y], val);
if (j > 0) add(dp[nxt][j-1][1][y], mul(val, j));
continue;
}
if (i+1 == t) {
add(dp[nxt][j][x][1], val);
if (j > 0) add(dp[nxt][j-1][x][1], mul(val, j));
continue;
}
// new comp type 0
add(dp[nxt][j+1][x][y], val);
// comb with type 0
add(dp[nxt][j][x][y], mul(val, j));
// comb with type 1
if (x) add(dp[nxt][j-1][1][y], mul(val, j));
// comb with type 2
if (y) add(dp[nxt][j-1][x][1], mul(val, j));
}
}
}
cur ^= 1; nxt ^= 1;
}
cout << dp[cur][0][1][1];
}
컴파일 시 표준 에러 (stderr) 메시지
kangaroo.cpp: In function 'void setIO()':
kangaroo.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | freopen("input.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | freopen("input.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |