답안 #1006108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1006108 2024-06-23T12:08:13 Z pudelos Paths (BOI18_paths) C++17
100 / 100
388 ms 97280 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=a; i<=b; ++i)
#define eb emplace_back
#define ll long long
#define V vector
const int maxn=3e5+7, maxk=5;

ll dp[maxn][1<<maxk];
int n, m, k;
V<int> A;
V<V<int>> con;

int main() {
  cin.tie(0) -> ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  A.resize(n+1);
  con.resize(n+1);
  FOR(i, 1, n) {
    cin >> A[i];
    --A[i];
    dp[i][1<<A[i]]=1;
  }
  int a, b;
  FOR(i, 1, m) {
    cin >> a >> b;
    con[a].eb(b);
    con[b].eb(a);
  }

  ll odp=0;
  FOR(m, 1, (1<<k)-1) {
    FOR(v, 1, n) {
      int gr = A[v];
      if(m&(1<<gr)==0) continue;
      if(__builtin_popcount(m)>=2) odp+=dp[v][m];
      for(int u : con[v]) {
        int sgr = A[u];
        if(m&(1<<sgr)==1) continue;
        dp[u][m^(1<<sgr)]+=dp[v][m];
      }
    }
  }
  cout << odp << '\n';
}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:35:19: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   35 |       if(m&(1<<gr)==0) continue;
      |            ~~~~~~~^~~
paths.cpp:39:22: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   39 |         if(m&(1<<sgr)==1) continue;
      |              ~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 9296 KB Output is correct
2 Correct 41 ms 8532 KB Output is correct
3 Correct 220 ms 96704 KB Output is correct
4 Correct 62 ms 17236 KB Output is correct
5 Correct 51 ms 17236 KB Output is correct
6 Correct 157 ms 68464 KB Output is correct
7 Correct 229 ms 96424 KB Output is correct
8 Correct 241 ms 97108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 50 ms 9296 KB Output is correct
12 Correct 41 ms 8532 KB Output is correct
13 Correct 220 ms 96704 KB Output is correct
14 Correct 62 ms 17236 KB Output is correct
15 Correct 51 ms 17236 KB Output is correct
16 Correct 157 ms 68464 KB Output is correct
17 Correct 229 ms 96424 KB Output is correct
18 Correct 241 ms 97108 KB Output is correct
19 Correct 51 ms 9376 KB Output is correct
20 Correct 42 ms 8540 KB Output is correct
21 Correct 223 ms 96596 KB Output is correct
22 Correct 62 ms 17260 KB Output is correct
23 Correct 51 ms 17276 KB Output is correct
24 Correct 158 ms 68476 KB Output is correct
25 Correct 228 ms 96548 KB Output is correct
26 Correct 217 ms 97280 KB Output is correct
27 Correct 51 ms 8540 KB Output is correct
28 Correct 68 ms 10072 KB Output is correct
29 Correct 377 ms 96412 KB Output is correct
30 Correct 185 ms 53448 KB Output is correct
31 Correct 193 ms 53432 KB Output is correct
32 Correct 388 ms 96668 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 472 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 24 ms 2288 KB Output is correct
3 Correct 16 ms 2396 KB Output is correct
4 Correct 53 ms 34176 KB Output is correct
5 Correct 40 ms 34764 KB Output is correct
6 Correct 117 ms 34140 KB Output is correct
7 Correct 16 ms 2396 KB Output is correct
8 Correct 67 ms 34192 KB Output is correct
9 Correct 50 ms 34748 KB Output is correct
10 Correct 58 ms 35032 KB Output is correct
11 Correct 54 ms 19152 KB Output is correct
12 Correct 72 ms 27220 KB Output is correct
13 Correct 64 ms 19540 KB Output is correct
14 Correct 106 ms 34140 KB Output is correct
15 Correct 107 ms 34132 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct