답안 #1071751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1071751 2024-08-23T10:49:04 Z Unforgettablepl 디지털 회로 (IOI22_circuit) C++17
2 / 100
3000 ms 5720 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

const long long modulo = 1e9+2022;

namespace {
    int N,M;
    vector<int> A;
    vector<long long> arr;
}

void init(int N,int M,vector<int> P,vector<int> A){
    ::N = N;
    ::M = M;
    ::A = A;
    arr = vector<long long>(M);
    vector<vector<int>> adj(N);
    vector<vector<pair<long long,long long>>> ways(N);
    for(int i=1;i<N+M;i++){adj[P[i]].emplace_back(i);ways[P[i]].emplace_back(1,1);}
    {
        function<long long(int)> dfs = [&](int x){
            if(x>=N)return 1ll;
            long long tot_ways = adj[x].size();
            for(int i=0;i<adj[x].size();i++) {
                ways[x][i].first=ways[x][i].second=dfs(adj[x][i]);
                tot_ways=(tot_ways*ways[x][i].first)%modulo;
                if(i)ways[x][i].first=(ways[x][i].first*ways[x][i-1].first)%modulo;
            }
            for(int i=adj[x].size()-2;i>=0;i--)ways[x][i].second=(ways[x][i].second*ways[x][i+1].second)%modulo;
            return tot_ways;
        };
        dfs(0);
    }
    {
        function<void(int,long long)> dfs = [&](int x,long long offset) {
            if(x>=N) {
                arr[x-N]=offset;
                return;
            }
            for(int i=0;i<adj[x].size();i++) {
                long long tot = 1;
                if(i)tot=(tot*ways[x][i-1].first)%modulo;
                if(i!=adj[x].size()-1)tot=(tot*ways[x][i+1].second)%modulo;
                dfs(adj[x][i],tot);
            }
        };
        dfs(0,1);
    }
}

int count_ways(int L,int R){
    L-=N;R-=N;
    for(int i=L;i<=R;i++)A[i]^=1;
    long long ans = 0;
    for(int i=0;i<M;i++) {
        if(A[i])ans+=arr[i];
        ans%=modulo;
    }
    return ans;
}

Compilation message

circuit.cpp: In lambda function:
circuit.cpp:25:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |             for(int i=0;i<adj[x].size();i++) {
      |                         ~^~~~~~~~~~~~~~
circuit.cpp: In lambda function:
circuit.cpp:41:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             for(int i=0;i<adj[x].size();i++) {
      |                         ~^~~~~~~~~~~~~~
circuit.cpp:44:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |                 if(i!=adj[x].size()-1)tot=(tot*ways[x][i+1].second)%modulo;
      |                    ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 376 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Incorrect 0 ms 376 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3048 ms 5720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3048 ms 5720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 376 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Incorrect 0 ms 376 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Incorrect 0 ms 376 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
11 Halted 0 ms 0 KB -