# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1062577 | sleepntsheep | Amusement Park (CEOI19_amusementpark) | C++17 | 1 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const ll M = 998244353;
vector<int> g[22];
int n, m, a[999], b[999], p[22], q[22];
ii dp[1<<22];
ll bpow(ll a, ll b) {
if (!b) return 1;
ll r = bpow(a, b / 2);
if (b & 1) return r * r % M * a % M;
return r * r % M;
}
ii add(ii a, ii b) {
return {(a.first * 1ll * a.second % M + b.first * 1ll * b.second % M) % M * 1ll * bpow((a.second + b.second) % M, M - 2) % M
, a.second + b.second};
}
ii prod(ii a, ii b) {
return {(a.first * 1ll * a.second % M + b.first * 1ll * a.second % M) % M * 1ll * bpow(a.second * 1ll * b.second % M, M - 2) % M,
a.second * 1ll * b.second % M};
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i)
scanf("%d%d", a+i, b+i), --a[i], --b[i], g[a[i]].push_back(b[i]);
dp[0] = {0, 1};
for (int j = 0; j < (1 << n); ++j) {
for (int i = 0; i < n; ++i) if (j & (1 << i)) {
int k = j & ~(1 << i), c {};
for (int v : g[i]) c += (k >> v) & 1;
dp[j] = add(dp[j], prod(dp[k], {c, 1}));
}
}
printf("%lld", dp[(1 << n) - 1].first * 1ll * dp[(1 << n) - 1].second % M);
}
컴파일 시 표준 에러 (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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |