Submission #493983

# Submission time Handle Problem Language Result Execution time Memory
493983 2021-12-13T14:43:19 Z leaked Restore Array (RMI19_restore) C++14
45 / 100
421 ms 716 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define m_p make_pair
#define vec vector
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fast_rmi ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

signed main(){
    fast_rmi;
    int n,m;
    cin>>n>>m;
    vec<array<int,4>>arr(m);
    vec<array<int,4>>arrt(m);

    for(auto &z : arr){
        cin>>z[0]>>z[1]>>z[2]>>z[3];
        if(z[3]==1)
            z[2]=z[2]-1;
//        cout<<"L R "<<z[0]<<' '<<z[1]<<' '<<z[2]<<' '<<"TYPE "<<z[3]<<endl;
    }
     auto brute=[&](){
        for(int mask=0;mask<(1<<n);mask++){
            vec<int>a(n);
            for(int i=0;i<n;i++){
                if(mask&(1<<i))
                    a[i]=1;
                else
                    a[i]=0;
            }
            auto check=[&](){
                int ok=1;
                for(auto &z : arr){
                    int cnt=0;
                    for(int i=z[0];i<=z[1];i++)
                        cnt+=(!a[i]);
                    if(z[3])
                        ok&=(cnt<=z[2]);
                    else{
                        ok&=(cnt>=z[2]);
                    }
                }
                return ok;
            };
            if(check()){
                return a;
            }
        }
        return vec<int>();
    };
    if(n<=18){
        vec<int> ans=brute();
        if(!sz(ans)){
            cout<<-1;
            return 0;
        }
        for(auto &z : ans)
            cout<<z<<' ';
        return 0;
    }
    arrt=arr;
    vec<int> a(n,-1);
    for(int i=0;i<m;i++){
        int l=arr[i][0];
        int r=arr[i][1];
        int k=arr[i][2];
        int t=arr[i][3];
        if(k==0 && t==1){
            for(int i=l;i<=r;i++){
                if(a[i]==0){
                    cout<<-1;
                    return 0;
                }
                a[i]=1;
            }
        }
        else if(k==r-l+1 && t==0){
            for(int i=l;i<=r;i++){
                if(a[i]==1){
                    cout<<-1;
                    return 0;
                }
                a[i]=0;
            }
        }
    }
    sort(all(arr));
    auto check=[&](){
        int ok=1;
        for(auto &z : arr){
            if(z[2]==z[1]-z[0] && z[3]==1){
                int kk=0;
                for(int i=z[0];i<=z[1];i++){
                    kk|=(a[i]==1);
                }
                if(!kk){
                    for(int i=z[0];i<=z[1];i++){
                        if(a[i]==-1 && !kk){
                            kk=1;
                            a[i]=1;
                        }
                    }
                }
                if(!kk)
                    return 0;
            }
            else if(z[3]==0 && z[2]==1){
                int kk=0;
                for(int i=z[0];i<=z[1];i++){
                    kk|=(a[i]==0);
                }
                if(!kk){
                    for(int i=z[0];i<=z[1];i++){
                        if(a[i]==-1 && !kk){
                            kk=1;
                            a[i]=0;
                        }
                    }
                }
                if(!kk)
                    return 0;
            }
        }
        return ok;
    };
    if(!check()){
        cout<<-1;
    }
    else
        for(auto &z : a){
            if(z==-1)
                z=0;
            cout<<z<<' ';
        }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 110 ms 204 KB Output is correct
4 Correct 75 ms 292 KB Output is correct
5 Correct 421 ms 296 KB Output is correct
6 Correct 159 ms 324 KB Output is correct
7 Correct 65 ms 292 KB Output is correct
8 Correct 60 ms 288 KB Output is correct
9 Correct 313 ms 308 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 588 KB Output is correct
2 Correct 20 ms 640 KB Output is correct
3 Correct 20 ms 628 KB Output is correct
4 Correct 22 ms 588 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 4 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 588 KB Output is correct
2 Correct 20 ms 640 KB Output is correct
3 Correct 20 ms 628 KB Output is correct
4 Correct 22 ms 588 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 4 ms 588 KB Output is correct
7 Correct 18 ms 588 KB Output is correct
8 Correct 18 ms 588 KB Output is correct
9 Correct 20 ms 648 KB Output is correct
10 Correct 17 ms 588 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 3 ms 588 KB Output is correct
13 Correct 18 ms 628 KB Output is correct
14 Correct 13 ms 716 KB Output is correct
15 Correct 12 ms 588 KB Output is correct
16 Correct 12 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 110 ms 204 KB Output is correct
4 Correct 75 ms 292 KB Output is correct
5 Correct 421 ms 296 KB Output is correct
6 Correct 159 ms 324 KB Output is correct
7 Correct 65 ms 292 KB Output is correct
8 Correct 60 ms 288 KB Output is correct
9 Correct 313 ms 308 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 17 ms 588 KB Output is correct
12 Correct 20 ms 640 KB Output is correct
13 Correct 20 ms 628 KB Output is correct
14 Correct 22 ms 588 KB Output is correct
15 Correct 3 ms 588 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Correct 18 ms 588 KB Output is correct
18 Correct 18 ms 588 KB Output is correct
19 Correct 20 ms 648 KB Output is correct
20 Correct 17 ms 588 KB Output is correct
21 Correct 2 ms 588 KB Output is correct
22 Correct 3 ms 588 KB Output is correct
23 Correct 18 ms 628 KB Output is correct
24 Correct 13 ms 716 KB Output is correct
25 Correct 12 ms 588 KB Output is correct
26 Correct 12 ms 588 KB Output is correct
27 Incorrect 4 ms 716 KB Output isn't correct
28 Halted 0 ms 0 KB -