Submission #785798

#TimeUsernameProblemLanguageResultExecution timeMemory
785798AndreyDigital Circuit (IOI22_circuit)C++17
18 / 100
3095 ms23728 KiB
#include "circuit.h" #include<bits/stdc++.h> using namespace std; vector<int> haha[300001]; vector<long long> wut[300001]; vector<long long> bruh(300001); vector<long long> dp(300001); vector<long long> prod(300001); const long long MOD = 1e9+2022; long long n,m; void dfs(long long a, long long t) { long long br = 0,pr = 1,sb = 0,yeah = 0; for(long long i = 0; i < wut[a].size(); i++) { if(bruh[wut[a][i]]) { br++; } yeah++; } for(long long v: haha[a]) { if(v != t) { dfs(v,a); sb = (sb*prod[v]+dp[v]*pr)%MOD; pr*=prod[v]; pr%=MOD; yeah++; } } prod[a] = (pr*yeah)%MOD; dp[a] = (sb+br*pr)%MOD; } void init(int N, int M, vector<int> p, vector<int> a) { n = N; m = M; for(long long i = n; i < n+m; i++) { bruh[i] = a[i-n]; } for(long long i = 1; i < n; i++) { haha[i].push_back(p[i]); haha[p[i]].push_back(i); } for(long long i = n; i < n+m; i++) { wut[p[i]].push_back(i); } } int count_ways(int l, int r) { for(long long i = l; i <= r; i++) { if(bruh[i]) { bruh[i] = 0; } else { bruh[i] = 1; } } dfs(0,-1); return dp[0]; }

Compilation message (stderr)

circuit.cpp: In function 'void dfs(long long int, long long int)':
circuit.cpp:15:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(long long i = 0; i < wut[a].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...