# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1092127 | lovrot | Paths (BOI18_paths) | C++17 | 216 ms | 97216 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <vector>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
const int K = 5;
int n, m, k, c[N];
vector<int> g[N];
ll dp[N][1 << K];
int next_perm(int x, int k) {
int ret = x + (x & -x);
return ret + (1 << (k - __builtin_popcount(ret))) - 1;
}
char out[K];
char* bit(int x) {
for(int i = 0; i < k; ++i) {
out[i] = '0' + (bool) (x & (1 << i));
}
return out;
}
int main() {
scanf("%d%d%d", &n, &m, &k);
for(int i = 1; i <= n; ++i) {
scanf("%d", c + i);
-- c[i];
dp[i][1 << c[i]] = 1;
}
for(int i = 0; i < m; ++i) {
int u, v;
scanf("%d%d", &u, &v);
g[u].PB(v);
g[v].PB(u);
}
ll ans = 0;
for(int i = 2; i <= k; ++i) {
int mask = (1 << i) - 1;
for(; mask < (1 << k); mask = next_perm(mask, i)) {
// printf("%d %.*s\n", mask, k, bit(mask));
for(int u = 1; u <= n; ++u) {
if(mask & (1 << c[u])) {
for(int v : g[u]) {
dp[u][mask] += dp[v][mask ^ (1 << c[u])];
}
// if(i == 2) { printf("%d %lld\n", u, dp[u][mask]); }
ans += dp[u][mask];
}
}
}
}
printf("%lld\n", ans);
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |