Submission #679670

# Submission time Handle Problem Language Result Execution time Memory
679670 2023-01-08T20:43:59 Z peijar Paths (BOI18_paths) C++17
100 / 100
622 ms 74056 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

namespace std {
template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) {
  out << "[";
  for (int i = 0; i < (int)vec.size(); ++i) {
    out << vec[i];
    if (i + 1 < (int)vec.size())
      out << ", ";
  }
  return out << "]";
}
} // namespace std

void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
  cout << ' ' << H;
  dbg_out(T...);
}

#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int nbSommet, nbAretes, nbCouleurs;
  cin >> nbSommet >> nbAretes >> nbCouleurs;
  vector<vector<int>> dp(nbSommet, vector<int>(1 << nbCouleurs));
  vector<int> col(nbSommet);
  for (int &c : col) {
    cin >> c;
    --c;
  }
  vector<vector<int>> adj(nbSommet);
  for (int i = 0; i < nbAretes; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int dejaVu = (1 << nbCouleurs) - 1; dejaVu >= 0; --dejaVu) {
    for (int u = 0; u < nbSommet; ++u) {
      int &cur = dp[u][dejaVu];
      cur = 1;
      for (int v : adj[u])
        if (!((1 << col[v]) & dejaVu))
          cur += dp[v][dejaVu | (1 << col[v])];
    }
  }
  int sol = 0;
  for (int u = 0; u < nbSommet; ++u)
    sol += dp[u][1 << col[u]] - 1;
  cout << sol << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 316 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 10840 KB Output is correct
2 Correct 68 ms 9796 KB Output is correct
3 Correct 365 ms 55244 KB Output is correct
4 Correct 100 ms 14796 KB Output is correct
5 Correct 107 ms 14312 KB Output is correct
6 Correct 272 ms 39888 KB Output is correct
7 Correct 362 ms 55188 KB Output is correct
8 Correct 403 ms 55712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 316 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 85 ms 10840 KB Output is correct
12 Correct 68 ms 9796 KB Output is correct
13 Correct 365 ms 55244 KB Output is correct
14 Correct 100 ms 14796 KB Output is correct
15 Correct 107 ms 14312 KB Output is correct
16 Correct 272 ms 39888 KB Output is correct
17 Correct 362 ms 55188 KB Output is correct
18 Correct 403 ms 55712 KB Output is correct
19 Correct 75 ms 10956 KB Output is correct
20 Correct 72 ms 9784 KB Output is correct
21 Correct 400 ms 55200 KB Output is correct
22 Correct 100 ms 14860 KB Output is correct
23 Correct 85 ms 14284 KB Output is correct
24 Correct 249 ms 39888 KB Output is correct
25 Correct 395 ms 55292 KB Output is correct
26 Correct 358 ms 55736 KB Output is correct
27 Correct 87 ms 9888 KB Output is correct
28 Correct 130 ms 13340 KB Output is correct
29 Correct 560 ms 74000 KB Output is correct
30 Correct 382 ms 42372 KB Output is correct
31 Correct 371 ms 42508 KB Output is correct
32 Correct 622 ms 74056 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 316 KB Output is correct
37 Correct 1 ms 324 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 59 ms 3396 KB Output is correct
3 Correct 29 ms 3296 KB Output is correct
4 Correct 89 ms 18484 KB Output is correct
5 Correct 62 ms 18920 KB Output is correct
6 Correct 237 ms 37228 KB Output is correct
7 Correct 31 ms 3300 KB Output is correct
8 Correct 148 ms 24652 KB Output is correct
9 Correct 97 ms 25144 KB Output is correct
10 Correct 130 ms 25328 KB Output is correct
11 Correct 118 ms 20036 KB Output is correct
12 Correct 171 ms 28836 KB Output is correct
13 Correct 139 ms 20420 KB Output is correct
14 Correct 253 ms 37288 KB Output is correct
15 Correct 241 ms 37356 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 324 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct