Submission #737505

#TimeUsernameProblemLanguageResultExecution timeMemory
737505minhcoolDigital Circuit (IOI22_circuit)C++17
18 / 100
51 ms33928 KiB
#include "circuit.h" #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<ii, ii> iiii; const int N = 5e3 + 5; const int oo = 1e18 + 7, mod = 1000002022; int n, m; vector<int> Adj[N]; int arr[N]; long long coor[N][N]; long long pref[N], suff[N]; void dfs(int u){ if(!Adj[u].size()) return; for(auto v : Adj[u]) dfs(v); pref[0] = coor[Adj[u][0]][m]; for(int i = 1; i < Adj[u].size(); i++) pref[i] = (pref[i - 1] * coor[Adj[u][i]][m]) % mod; suff[Adj[u].size()] = 1; for(int i = Adj[u].size() - 1; i >= 0; i--) suff[i] = (suff[i + 1] * coor[Adj[u][i]][m]) % mod; //for(int i = 0; i < Adj[u].size(); i++) cout << pref[i] << " " << suff[i] << "\n"; coor[u][m] = (pref[Adj[u].size() - 1] * Adj[u].size()) % mod; for(int i = 0; i < Adj[u].size(); i++){ for(int j = 0; j < m; j++){ long long temp1 = (!i ? 1 : pref[i - 1]); temp1 = (temp1 * suff[i + 1]) % mod; temp1 = (temp1 * coor[Adj[u][i]][j]) % mod; coor[u][j] = (coor[u][j] + temp1) % mod; } } for(int i = 0; i <= m; i++) coor[u][i] = ((coor[u][i] % mod) + mod) % mod; //for(int i = 0; i <= m; i++) cout << u << " " << i << " " << coor[u][i] << "\n"; } void init(int N, int M, vector<int> P, vector<int> A){ n = N, m = M; for(int i = 1; i < n + m; i++) Adj[P[i]].pb(i); for(int i = 0; i < m; i++) arr[i] = A[i]; for(int i = n; i < n + m; i++) coor[i][i - n] = coor[i][m] = 1; dfs(0); //for(int i = 0; i < m; i++) cout << coor[0][i] << " "; //cout << "\n"; } int count_ways(int L, int R){ L -= n, R -= n; for(int i = L; i <= R; i++) arr[i] ^= 1; long long ans = 0; for(int i = 0; i < m; i++) ans = (ans + (long long)arr[i] * coor[0][i]) % mod; ans = ((ans % mod) + mod) % mod; int ans2 = ans; return ans2; }

Compilation message (stderr)

circuit.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   16 | const int oo = 1e18 + 7, mod = 1000002022;
      |                ~~~~~^~~
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for(int i = 1; i < Adj[u].size(); i++) pref[i] = (pref[i - 1] * coor[Adj[u][i]][m]) % mod;
      |                 ~~^~~~~~~~~~~~~~~
circuit.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for(int i = 0; i < Adj[u].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...