| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 242669 | kingfran1907 | Zapina (COCI20_zapina) | C++14 | 382 ms | 5372 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long llint;
const int maxn = 400;
const llint mod = 1e9+7;
int n;
llint dp[maxn][maxn][3];
llint fac[maxn];
llint chos[maxn][maxn];
llint f(int x, int y, bool flag) {
if (x == n + 1) {
if (y == 0) return flag;
else return 0;
}
llint &ret = dp[x][y][flag];
if (ret != -1) return ret;
ret = 0;
for (int i = 0; i <= y; i++) {
ret += chos[y][i] * f(x + 1, y - i, flag || (i == x));
ret %= mod;
}
return ret;
}
llint pot(llint a, llint b) {
if (b == 0) return 1;
else if (b % 2 == 1) return (a * pot(a, b - 1)) % mod;
else {
llint out = pot(a, b / 2);
return (out * out) % mod;
}
}
llint inv(llint x) {
return pot(x, mod - 2);
}
llint choose(int a, int b) {
llint out = fac[a];
out *= inv(fac[b]), out %= mod;
out *= inv(fac[a - b]), out %= mod;
return out;
}
int main() {
memset(dp, -1, sizeof dp);
scanf("%d", &n);
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i, fac[i] %= mod;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= i; j++) {
chos[i][j] = choose(i, j);
}
}
printf("%lld\n", f(1, n, false));
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
