CSES - Leirikisa 3 - Results
Submission details
Task:Mixture
Sender:vgtcross
Submission time:2023-04-19 17:01:58 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:144:34: error: no matching function for call to 'min(std::array<long long int, 3>&, int&)'
  144 |                         ans = min(ans, sz);
      |                               ~~~^~~~~~~~~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from input/code.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:...

Code

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

const array<ll, 3> def = {0, 0, 0};
array<ll, 3> basis[3];
array<ll, 3> cont[3];
int sz;

void init() {
    sz = 0;
    for (int i = 0; i < 3; ++i) {
        basis[i] = def;
    }
}

array<ll, 3> add(array<ll, 3> &a, array<ll, 3> &b) {
    return {a[0]+b[0], a[1]+b[1], a[2]+b[2]};
}

array<ll, 3> mul(array<ll, 3> &a, ll k) {
    return {a[0]*k, a[1]*k, a[2]*k};
}

void insert(array<ll, 3> a) {
    array<ll, 3> c = def;
    c[sz] = 1;
    for (int i = 0; i < 3; ++i) {
        if (a[i] == 0)
            continue;
        if (basis[i] == def) {
            basis[i] = a;
            cont[i] = c;
            ++sz;
            return;
        }
        
        array<ll, 3> b = basis[i];
        array<ll, 3> cb = cont[i];
        if (a[i] < 0) {
            a = mul(a, -1);
            c = mul(c, -1);
        }
        if (b[i] < 0) {
            b = mul(b, -1);
            cb = mul(cb, -1);
        }
        
        ll g = gcd(a[i], b[i]);
        ll ma = b[i]/g;
        ll mb = a[i]/g;
        
        a = mul(a, ma);
        c = mul(c, ma);
        b = mul(b, -mb);
        cb = mul(cb, -mb);
        
        a = add(a, b);
        c = add(c, cb);
    }
}

array<ll, 3> build(array<ll, 3> a) {
    array<ll, 3> c = def;
    for (int i = 0; i < 3; ++i) {
        if (a[i] == 0)
            continue;
        if (basis[i] == def)
            return def;
        
        array<ll, 3> b = basis[i];
        array<ll, 3> cb = cont[i];
        if (a[i] < 0) {
            a = mul(a, -1);
            c = mul(c, -1);
        }
        if (b[i] < 0) {
            b = mul(b, -1);
            cb = mul(cb, -1);
        }
        
        ll g = gcd(a[i], b[i]);
        ll ma = b[i]/g;
        ll mb = a[i]/g;
        
        a = mul(a, ma);
        c = mul(c, ma);
        b = mul(b, -mb);
        cb = mul(cb, -mb);
        
        a = add(a, b);
        c = add(c, cb);
    }
    
    return c;
}

void solve() {
    array<ll, 3> goal;
    cin >> goal[0] >> goal[1] >> goal[2];
    
    int n;
    cin >> n;
    
    vector<array<ll, 3>> v(n, def);
    int idx = 0;
    for (int i = 0; i < n; ++i) {
        char op;
        cin >> op;
        if (op == 'A') {
            cin >> v[idx][0] >> v[idx][1] >> v[idx][2];
            idx++;
        } else {
            int id;
            cin >> id;
            v[id-1] = def;
        }
        int ans = 4;
        for (int a = 0; a < idx; ++a) if (v[a] != def) {
            for (int b = a+1; b < idx; ++b) if (v[b] != def) {
                for (int c = b+1; c < idx; ++c) if (v[c] != def) {
                    init();
                    insert(v[a]);
                    insert(v[b]);
                    insert(v[c]);
                    array<ll, 3> ans = build(goal);
                    if (ans == def)
                        continue;
                    bool pos = 0, neg = 0;
                    for (int i = 0; i < 3; ++i) {
                        if (ans[i] > 0)
                            pos = 1;
                        else if (ans[i] < 0)
                            neg = 1;
                    }

                    if (pos ^ neg)
                        ans = min(ans, sz);
                }
            }
        }
        cout << ans%4;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
    
    return 0;
}