Submission #787471

# Submission time Handle Problem Language Result Execution time Memory
787471 2023-07-19T08:19:03 Z thimote75 Digital Circuit (IOI22_circuit) C++17
0 / 100
3000 ms 1828 KB
#include "circuit.h"

#include <bits/stdc++.h>
#define num long long

using namespace std;
const int MOD = 1000002022;

using idata = vector<signed>;
using ndata = vector<num>;

ndata C;
ndata Gamma;

idata status;
idata target;

int N, M;

void init(int _N, int _M, idata P, idata A) {
  N = _N; M = _M;
  C    .resize(N);
  Gamma.resize(N + 1, 1);

  status = A;
  target.resize(M);
  for (int i = 0; i < M; i ++)
    target[i] = P[i + N];

  for (int i = 1; i < N + M; i ++) C[P[i]] ++;

  for (int i = N - 1; i >= 0; i --) Gamma[i] = (C[i] * Gamma[i + 1]) % MOD;
}

int count_ways(int L, int R) {
  L -= N; R -= N;
  for (int i = L; i <= R; i ++)
    status [i] = 1 - status[i];
  
  ndata localC(N);
  
  int size_last = 0;

  for (int i = 0; i < M; i ++) {
    if (status[i] == 0) continue ;

    localC[target[i]] ++;
  }

  num res = 0;
  bool lc = true;
  for (int i = 0; i < N; i ++) {
    res += localC[i] * Gamma[i + 1];
    res %= MOD;
  
    lc &= (localC[i] + 1) == C[i];
  }

  if (lc) return Gamma[0];

  return res;
}

Compilation message

circuit.cpp: In function 'int count_ways(int, int)':
circuit.cpp:42:7: warning: unused variable 'size_last' [-Wunused-variable]
   42 |   int size_last = 0;
      |       ^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3091 ms 1828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3091 ms 1828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -