# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
868308 | ND0322 | Amusement Park (CEOI19_amusementpark) | C++17 | 1727 ms | 4180 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
const int MAXN = 18;
const int MOD = 998244353;
//if you find a dag that works reversing all edges creates a new dag
//ans would be edges * (#dag/2)
//the dags differ by their nodes
int n, m, popcount[1<<MAXN];
long long dp[1<<MAXN];
bool indep[1<<MAXN];
//dp = num dags using nodes in the mask
//indep is if a mask is an independant subset (no two nodes are connected)
//all submasks of independant submasks are independant as well
//for all independant subsets of mask:
//if(number of nodes in subset is odd) dp[mask] += dp[the rest of the mask]
//and because we overcount some
//if(number of nodes in subset is even) dp[mask] -= dp[the rest of the mask]
//every subset of an independant set is independant
//if it isnt then the whole thing isnt independant
int main(){
scanf("%d %d", &n, &m);
fill(indep, indep + (1<<n), 1);
for(int i = 0; i < m; i++){
int x,y; scanf("%d %d", &x, &y);
indep[1<<(x-1) | 1<<(y-1)] = 0;
}
//same thing as the function
for(int i = 0; i < n; i++){
for(int j = (1<<n)-1; j >= 0; j--) if(j & (1<<i)) indep[j] &= indep[j ^ (1<<i)];
}
for(int i = 0; i < (1<<n); i++){
popcount[i] = popcount[i>>1] + (i&1);
}
dp[0] = 1;
for(int i = 0; i < (1<<n); i++){
for(int j = i; j >= 1; j = (j-1) & i ){
if(indep[j]){
if(popcount[j] & 1) dp[i] = (dp[i] + dp[i^j]) % MOD;
else dp[i] = (dp[i] - dp[i^j]) % MOD;
}
}
}
//https://math.stackexchange.com/questions/3361647/finding-inverse-of-2-mod-m
int minv = ((1+MOD)/2);
dp[(1 << n) - 1] = (dp[(1 << n) - 1] + MOD) % MOD;
printf("%lld\n", dp[(1<<n)-1] * m % MOD * minv % MOD);
}
컴파일 시 표준 에러 (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... |