답안 #481548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
481548 2021-10-21T06:39:06 Z SlavicG Restore Array (RMI19_restore) C++17
20 / 100
133 ms 588 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;
            }
        }
    }

    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();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 33 ms 204 KB Output is correct
4 Correct 32 ms 204 KB Output is correct
5 Correct 133 ms 204 KB Output is correct
6 Correct 67 ms 304 KB Output is correct
7 Correct 26 ms 316 KB Output is correct
8 Correct 24 ms 312 KB Output is correct
9 Correct 125 ms 288 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 5 ms 588 KB Output is correct
6 Correct 4 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 5 ms 588 KB Output is correct
6 Correct 4 ms 588 KB Output is correct
7 Incorrect 6 ms 588 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 33 ms 204 KB Output is correct
4 Correct 32 ms 204 KB Output is correct
5 Correct 133 ms 204 KB Output is correct
6 Correct 67 ms 304 KB Output is correct
7 Correct 26 ms 316 KB Output is correct
8 Correct 24 ms 312 KB Output is correct
9 Correct 125 ms 288 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 3 ms 588 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 3 ms 588 KB Output is correct
15 Correct 5 ms 588 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Incorrect 6 ms 588 KB Output isn't correct
18 Halted 0 ms 0 KB -