Submission #481550

# Submission time Handle Problem Language Result Execution time Memory
481550 2021-10-21T06:42:52 Z SlavicG Restore Array (RMI19_restore) C++17
Compilation error
0 ms 0 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

bool check(vector<int>& a, vector<array<int,4>>& q)
{
    int n = sz(a), m = sz(q);
    vector<int> p(n);
    forn(i, n){
        p[i] = a[i];
        if(i)p[i] += p[i - 1];
    }

    bool ok = true;
            for(int i = 0;i < m;++i){
                int l = q[i][0], r = q[i][1], k = q[i][2], val = q[i][3];

                int zeroes = (r - l + 1) - p[r];
                if(l)zeroes += p[l - 1];

                int number  = 0;
                if(zeroes >= k)number = 0;
                else number = 1;

                if(number != val)ok = false;
            }
    return ok;
}
void solve()
{ 
    int n, m;
    cin >> n >> m;

    vector<array<int, 4>> q(m);

    for(int i = 0;i < m;++i){
        int l, r, k, val;
        cin >> l >> r >> k >> val;
        q[i] = {l, r, k, val};
    }

    if(n <= 18)
    {
        for(int mask = 0;mask < (1 << n);++mask){
            vector<int> a(n, 0);
            vector<int> p(n, 0);
            for(int i = 0;i < n;++i){
                if(mask & (1 << i))a[i] = 1;
                p[i] = a[i];
                if(i)p[i] += p[i - 1];
            }

            if(check(a, q)){
                forn(i, n)cout << a[i] << " ";
                cout << "\n";
                return;
            }
        }

        cout << "-1\n";
        return;
    }

    vector<int> a(n, 0);

    for(int i = 0;i < m;++i){
        int l = q[i][0], r = q[i][1], k = q[i][2], val = q[i][3];

        if(k == 1){
            if(val == 1){
                for(int j = l;j <= r;++j)
                    a[j] = 1;
            }
        }else if(k == r - l + 1){
            if(val -- 9){
                for(int j = l;j <= r;++j)
                    a[j] = 0;
            }
        }
    }

    if(check(a, q)){
        forn(i, n)cout << a[i] << " ";
        return;
    }

    cout << "-1\n";

}
 
int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
}

Compilation message

restore.cpp: In function 'void solve()':
restore.cpp:83:22: error: expected ')' before numeric constant
   83 |             if(val -- 9){
      |               ~      ^~
      |                      )