답안 #915215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915215 2024-01-23T13:56:10 Z Namkhing 디지털 회로 (IOI22_circuit) C++17
0 / 100
381 ms 3400 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int Max = 2e5 + 1;
const int Mod = 1e9 + 2022;
ll n, m, dp[Max][2];

void build(int node, int left, int right, vector<int>& A) {
    if (left == right) {
        dp[node][A[left]] = 1;
        return;
    }

    int mid = (left + right) / 2;

    int l = node * 2 + 1;
    int r = node * 2 + 2;

    build(l, left, mid, A);
    build(r, mid + 1, right, A);

    dp[node][0] = dp[l][1] * dp[r][0] % Mod + dp[l][0] * dp[r][1] % Mod + dp[l][0] * dp[r][0] % Mod;
    dp[node][1] = dp[l][1] * dp[r][0] % Mod + dp[l][0] * dp[r][1] % Mod + 2 * dp[l][1] * dp[r][1] % Mod;

    dp[node][0] %= Mod;
    dp[node][1] %= Mod;
}

void update(int node, int left, int right, int idx) {
    if (left > idx || right < idx) return;
    if (left == idx && right == idx) {
        swap(dp[node][0], dp[node][1]);
        return;
    }

    int mid = (left + right) / 2;

    int l = node * 2 + 1;
    int r = node * 2 + 2;

    update(l, left, mid, idx);
    update(r, mid + 1, right, idx);

    dp[node][0] = dp[l][1] * dp[r][0] % Mod + dp[l][0] * dp[r][1] % Mod + dp[l][0] * dp[r][0] % Mod;
    dp[node][1] = dp[l][1] * dp[r][0] % Mod + dp[l][0] * dp[r][1] % Mod + 2 * dp[l][1] * dp[r][1] % Mod;

    dp[node][0] %= Mod;
    dp[node][1] %= Mod;
}

void init(int N, int M, vector<int> P, vector<int> A) {
    n = N, m = M;
    build(0, 0, M - 1, A);
}

int count_ways(int L, int R) {
    update(0, 0, m - 1, L - n);
    return dp[0][1]; 
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 381 ms 3400 KB 1st lines differ - on the 1st token, expected: '431985922', found: '128974656'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 381 ms 3400 KB 1st lines differ - on the 1st token, expected: '431985922', found: '128974656'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -