Submission #652758

#TimeUsernameProblemLanguageResultExecution timeMemory
652758BlagojDigital Circuit (IOI22_circuit)C++17
2 / 100
10 ms2384 KiB
#include "circuit.h" #include <bits/stdc++.h> using namespace std; vector<int> states; vector<int> kids[1009]; int n, m; long long mod = 1000002022; void init(int N, int M, std::vector<int> P, std::vector<int> A) { states = A; n = N; m = M; for (int i = 1; i < P.size(); i++) { kids[P[i]].push_back(i); } } long long dp[3000][2]; bool solved[3000]; void solve(int x) { if (solved[x]) { return; } solved[x] = true; int k1 = kids[x][0], k2 = kids[x][1]; if (dp[k1][0] == -1 || dp[k1][1] == -1) { solve(k1); } if (dp[k2][0] == -1 || dp[k2][1] == -1) { solve(k2); } dp[x][0] = (dp[k1][0] * dp[k2][1] + dp[k1][1] * dp[k2][0] + 2 * dp[k1][0] * dp[k2][0]) % mod; dp[x][1] = (dp[k1][0] * dp[k2][1] + dp[k1][1] * dp[k2][0] + 2 * dp[k1][1] * dp[k2][1]) % mod; } int count_ways(int L, int R) { for (int i = L - n; i <= R - n; i++) { if (states[i] == 0) { states[i] = 1; } else { states[i] = 0; } } if (n == 1) { int ans = 0; for (int i = 0; i < m; i++) { ans += states[i]; } return ans; } for (int i = 0; i < n; i++) { dp[i][0] = dp[i][1] = -1; } for (int i = n; i < n + m; i++) { if (states[i] == 1) { dp[i][1] = 1; dp[i][0] = 0; } else { dp[i][1] = 0; dp[i][0] = 1; } } memset(solved, 0, sizeof(solved)); for (int i = 0; i < n; i++) { if (!solved[i]) { solve(i); } } return dp[0][1]; }

Compilation message (stderr)

circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:15:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |   for (int i = 1; i < P.size(); i++)
      |                   ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...