Submission #1057846

#TimeUsernameProblemLanguageResultExecution timeMemory
1057846ForestedDigital Circuit (IOI22_circuit)C++17
18 / 100
3014 ms3672 KiB
#include <bits/stdc++.h> using namespace std; using i32 = int; using i64 = long long; template <typename T> using V = vector<T>; template <typename T> using VV = V<V<T>>; template <typename T> using VVV = V<VV<T>>; template <typename T> bool chmin(T &x, const T &y) { if (x > y) { x = y; return true; } } template <typename T> bool chmax(T &x, const T &y) { if (x < y) { x = y; return true; } } #define OVERRIDE4(a, b, c, d, ...) d #define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i) #define REP3(i, l, r) for (i32 i = (i32)(l); i < (i32)(r); ++i) #define REP(...) OVERRIDE4(__VA_ARGS__, REP3, REP2)(__VA_ARGS__) #define PER2(i, n) for (i32 i = (i32)(n)-1; i >= 0; --i) #define PER3(i, l, r) for (i32 i = (i32)(r)-1; i >= (i32)(l); --i) #define PER(...) OVERRIDE4(__VA_ARGS__, PER3, PER2)(__VA_ARGS__) #define ALL(x) begin(x), end(x) #define LEN(x) (i32) size(x) void dbg(i32 x) { cerr << x; } void dbg(i64 x) { cerr << x; } template <typename T, typename U> void dbg(pair<T, U> p) { cerr << '('; dbg(p.first); cerr << ", "; dbg(p.second); cerr << ')'; } template <typename T> void dbg(V<T> arr) { cerr << '['; REP(i, LEN(arr)) { if (i) { cerr << ", "; } dbg(arr[i]); } cerr << ']'; } void debug() { cerr << '\n'; } template <typename Head, typename... Tail> void debug(Head head, Tail... tail) { dbg(head); cerr << ", "; debug(tail...); } #ifdef DEBUGF #define DBG(...) \ do { \ cerr << #__VA_ARGS__ << " : "; \ debug(__VA_ARGS__); \ } while (false) #else #define DBG(...) (void)0 #endif constexpr unsigned MOD = 1000002022; struct M { unsigned v; M() : v(0) {} M(unsigned v) : v(v) {} M &operator+=(M rhs) { if ((v += rhs.v) >= MOD) { v -= MOD; } return *this; } M &operator-=(M rhs) { if ((v -= rhs.v) >= MOD) { v += MOD; } return *this; } M &operator*=(M rhs) { v = (unsigned long long)v * rhs.v % MOD; return *this; } friend M operator+(M lhs, M rhs) { return lhs += rhs; } friend M operator-(M lhs, M rhs) { return lhs -= rhs; } friend M operator*(M lhs, M rhs) { return lhs *= rhs; } }; void dbg(M x) { cerr << x.v; } #include <vector> #include "circuit.h" struct Dp { M c0, c1; }; void dbg(Dp d) { cerr << '('; dbg(d.c0); cerr << ", "; dbg(d.c1); cerr << ')'; } Dp merge_naive(const V<Dp> &chl) { i32 c = LEN(chl); V<M> dp(1, M(1)); REP(i, c) { V<M> ndp(i + 2); REP(j, i + 1) { ndp[j] += dp[j] * chl[i].c0; ndp[j + 1] += dp[j] * chl[i].c1; } dp.swap(ndp); } V<M> sum(c + 2); REP(i, c + 1) { sum[i + 1] = sum[i] + dp[i]; } Dp ret; REP(i, 1, c + 1) { ret.c0 += sum[i]; ret.c1 += sum.back() - sum[i]; } return ret; } i32 n, m; V<i32> p, a; VV<i32> chl; V<Dp> dps; void init(i32 _n, i32 _m, V<i32> _p, V<i32> _a) { n = _n; m = _m; p = _p; a = _a; chl.resize(n); REP(i, 1, n + m) { chl[p[i]].push_back(i); } dps.resize(n + m); } int count_ways(i32 l, i32 r) { ++r; l -= n; r -= n; REP(i, l, r) { a[i] ^= 1; } REP(i, m) { dps[n + i].c0 = dps[n + i].c1 = M(); if (a[i] == 0) { dps[n + i].c0 = M(1); } else { dps[n + i].c1 = M(1); } } PER(i, n) { V<Dp> cd; for (i32 c : chl[i]) { cd.push_back(dps[c]); } dps[i] = merge_naive(cd); } DBG(a); REP(i, n + m) { DBG(dps[i].c0, dps[i].c1); } return dps[0].c1.v; }
#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...