Submission #720305

# Submission time Handle Problem Language Result Execution time Memory
720305 2023-04-07T22:41:01 Z Huseyn123 Digital Circuit (IOI22_circuit) C++17
2 / 100
29 ms 26304 KB
#include "circuit.h"
#include <bits/stdc++.h>
#define MAX 300001
#define INF LLONG_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define gett(x,m) get<m>(x)
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define sorta(a,sz) sort(a,a+sz)
#define inputar(a,b){\
    for(int i=0;i<b;i++){\
        cin >> a[i];\
    }\
}
#define inputvec(a,b){\
    for(int i=0;i<b;i++){\
        ll num;\
        cin >> num;\
        a.pb(num);\
    }\
}
#define outputar(a,b){\
    for(int i=0;i<b;i++){\
        cout << a[i] << " ";\
    }\
    cout << "\n";\
}
#define outputvec(a){\
    for(auto x:a){\
        cout << x << " ";\
    }\
    cout << "\n";\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
  freopen((filename+".in").c_str(),"r",stdin);
  freopen((filename+".out").c_str(),"w",stdout);
}
ll n,q,t=1,m,n2,m2,k,cnt=0,x,y,z,x2,y2,z2,res1=0,cnt1,cnt2,cnt3;
ll c[501][501];
ll fact[MAX];
ll inv_fact[MAX];
//char c;
string str[MAX];
string s1,s2;
vector<tuple<ll,ll,ll>> v;
vector<pll> v1,v2,v3,v4;
const int mod = 998244353;
vector<int> a,b;
vector<vector<ll>> g;
ll dp[1001][1001];
ll dp3[1001][2];
void dfs(ll v){
    if(v>=n){
        if(b[v-n]==0){
            dp3[v][0]=1;
            dp3[v][1]=0;
        }
        else{
            dp3[v][0]=0;
            dp3[v][1]=1;
        }
        return;
    }
    for(int i=0;i<=g[v].size();i++){
        dp[v][i]=0;
    }
    dp3[v][0]=0;
    dp3[v][1]=0;
    dp[v][0]=1;
    if(g[v].size()){
        vector<ll> arr(g[v].size()+1,0);
        for(auto x:g[v]){
            dfs(x);
            for(int i=0;i<=g[v].size();i++){
                arr[i]+=dp[v][i]*dp3[x][0];
            }
            for(int i=1;i<=g[v].size();i++){
                arr[i]+=dp[v][i-1]*dp3[x][1];
            }
            for(int i=0;i<=g[v].size();i++){
                dp[v][i]=arr[i];
                arr[i]=0;
            }
        }
    }
    for(int i=0;i<=g[v].size();i++){
        dp3[v][1]+=i*dp[v][i];
        dp3[v][0]+=(g[v].size()-i)*dp[v][i];
    }
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n=N;
    m=M;
    a=P;
    b=A;
    g.resize(N+M);
    for(int i=1;i<N+M;i++){
        g[P[i]].pb(i);
    }
}
int count_ways(int L, int R) {
  for(int i=L-n;i<=R-n;i++){
      b[i]=(1-b[i]);
  }
  dfs(0);
  return dp3[0][1];
}

Compilation message

circuit.cpp: In function 'void dfs(ll)':
circuit.cpp:79:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for(int i=0;i<=g[v].size();i++){
      |                 ~^~~~~~~~~~~~~
circuit.cpp:89:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |             for(int i=0;i<=g[v].size();i++){
      |                         ~^~~~~~~~~~~~~
circuit.cpp:92:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |             for(int i=1;i<=g[v].size();i++){
      |                         ~^~~~~~~~~~~~~
circuit.cpp:95:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |             for(int i=0;i<=g[v].size();i++){
      |                         ~^~~~~~~~~~~~~
circuit.cpp:101:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for(int i=0;i<=g[v].size();i++){
      |                 ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 6 ms 9612 KB Output is correct
3 Correct 12 ms 9792 KB Output is correct
4 Correct 12 ms 9680 KB Output is correct
5 Correct 12 ms 9680 KB Output is correct
6 Correct 13 ms 9716 KB Output is correct
7 Correct 13 ms 9792 KB Output is correct
8 Correct 13 ms 9780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Incorrect 6 ms 10704 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 6 ms 9612 KB Output is correct
3 Correct 12 ms 9792 KB Output is correct
4 Correct 12 ms 9680 KB Output is correct
5 Correct 12 ms 9680 KB Output is correct
6 Correct 13 ms 9716 KB Output is correct
7 Correct 13 ms 9792 KB Output is correct
8 Correct 13 ms 9780 KB Output is correct
9 Correct 5 ms 9680 KB Output is correct
10 Incorrect 6 ms 10704 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 29 ms 26304 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 29 ms 26304 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Incorrect 6 ms 10704 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 6 ms 9612 KB Output is correct
3 Correct 12 ms 9792 KB Output is correct
4 Correct 12 ms 9680 KB Output is correct
5 Correct 12 ms 9680 KB Output is correct
6 Correct 13 ms 9716 KB Output is correct
7 Correct 13 ms 9792 KB Output is correct
8 Correct 13 ms 9780 KB Output is correct
9 Correct 5 ms 9680 KB Output is correct
10 Incorrect 6 ms 10704 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 6 ms 9612 KB Output is correct
3 Correct 12 ms 9792 KB Output is correct
4 Correct 12 ms 9680 KB Output is correct
5 Correct 12 ms 9680 KB Output is correct
6 Correct 13 ms 9716 KB Output is correct
7 Correct 13 ms 9792 KB Output is correct
8 Correct 13 ms 9780 KB Output is correct
9 Correct 5 ms 9680 KB Output is correct
10 Incorrect 6 ms 10704 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -