Submission #331416

# Submission time Handle Problem Language Result Execution time Memory
331416 2020-11-28T12:05:12 Z Sho10 Restore Array (RMI19_restore) C++14
45 / 100
19 ms 1280 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,m,a[5005],check=0;
map<ll,ll>viz;
struct kth{
int l,r,value,k;
};
kth b[100005];
bool cmp(kth x,kth y){
return x.r<y.r;
}
void solve(ll pos,ll val){
    if(check==1){
        return;
    }
    a[pos]=val;
if(pos==n){
    for(ll i=1;i<=m;i++)
    {
        ll cnt=0;
        for(ll j=b[i].l;j<=b[i].r;j++)
        {
            if(a[j]==0){
                cnt++;
            }
        }
        if(b[i].value==0){
            if(cnt<b[i].k){
                a[pos]=-1;
                return;
            }
        }
        if(b[i].value==1){
            if(cnt>=b[i].k){
                a[pos]=-1;
                return;
            }
        }
    }
    check=1;
    for(ll i=1;i<=n;i++)
    {
        cout<<a[i]<<' ';
    }
    a[pos]=-1;
    return;
}
solve(pos+1,0);
solve(pos+1,1);
a[pos]=-1;
return;
}
int32_t main(){
CODE_START;
cin>>n>>m;
if(n<=18&&m<=200){
for(ll i=1;i<=m;i++)
{
    cin>>b[i].l>>b[i].r>>b[i].k>>b[i].value;
    b[i].l++;
    b[i].r++;
}
solve(1,0);
solve(1,1);
if(check==1){
   return 0;
}
rc("-1");
}else {
for(ll i=1;i<=n;i++)
{
    a[i]=-1;
}
for(ll i=1;i<=m;i++)
{
    cin>>b[i].l>>b[i].r>>b[i].k>>b[i].value;
    b[i].l++;
    b[i].r++;
    if(b[i].value==1&&b[i].k==1){
    for(ll j=b[i].l;j<=b[i].r;j++)
    {
        if(a[j]==0){
            rc("-1");
        }
        a[j]=1;
    }
}else if(b[i].value==0&&b[i].k==b[i].r-b[i].l+1){
for(ll j=b[i].l;j<=b[i].r;j++)
{
if(a[j]==1){
    rc("-1");
}
a[j]=0;
}
}
}
sort(b+1,b+m+1,cmp);
for(ll i=1;i<=n;i++)
{
    if(a[i]==-1){
        a[i]=0;
        viz[i]=1;
    }
}
for(ll i=1;i<=m;i++){
    if(b[i].value==0&&b[i].k==b[i].r-b[i].l+1){
        continue;
    }
    if(b[i].value==1&&b[i].k==1){
        continue;
    }
    if(b[i].value==0&&b[i].k==1){
            ll s1=0;
    for(ll j=b[i].l;j<=b[i].r;j++)
    {
        if(a[j]==0){
            s1=1;
        }
    }
    if(s1==0){
            rc("-1");
    }
        continue;
    }
    ll cnt=0;
    for(ll j=b[i].l;j<=b[i].r;j++)
    {
        if(a[j]==1){
            cnt++;
        }
    }
    if(cnt!=0){
        continue;
    }
    ll check=0;
    for(ll j=b[i].l;j<=b[i].r;j++)
    {
if(viz[j]==1&&a[j]==0){
    a[j]=1;
    viz[j]=0;
    check=1;
    break;
}
    }
    if(check==0){
        rc("-1");
    }

}
for(ll i=1;i<=n;i++)
{
    cout<<a[i]<<' ';
}
}
}
/*
Subtask 1:
4 5
0 1 2 1
0 2 2 0
2 2 1 0
0 1 1 0
1 2 1 0
*/

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 12 ms 364 KB Output is correct
6 Correct 7 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 4 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1004 KB Output is correct
2 Correct 13 ms 1004 KB Output is correct
3 Correct 13 ms 1004 KB Output is correct
4 Correct 15 ms 1004 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 6 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1004 KB Output is correct
2 Correct 13 ms 1004 KB Output is correct
3 Correct 13 ms 1004 KB Output is correct
4 Correct 15 ms 1004 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 6 ms 620 KB Output is correct
7 Correct 16 ms 1004 KB Output is correct
8 Correct 16 ms 1004 KB Output is correct
9 Correct 16 ms 1132 KB Output is correct
10 Correct 15 ms 1004 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 15 ms 1004 KB Output is correct
14 Correct 13 ms 748 KB Output is correct
15 Correct 12 ms 748 KB Output is correct
16 Correct 14 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 12 ms 364 KB Output is correct
6 Correct 7 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 4 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 13 ms 1004 KB Output is correct
12 Correct 13 ms 1004 KB Output is correct
13 Correct 13 ms 1004 KB Output is correct
14 Correct 15 ms 1004 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 6 ms 620 KB Output is correct
17 Correct 16 ms 1004 KB Output is correct
18 Correct 16 ms 1004 KB Output is correct
19 Correct 16 ms 1132 KB Output is correct
20 Correct 15 ms 1004 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 15 ms 1004 KB Output is correct
24 Correct 13 ms 748 KB Output is correct
25 Correct 12 ms 748 KB Output is correct
26 Correct 14 ms 748 KB Output is correct
27 Incorrect 19 ms 1280 KB Output isn't correct
28 Halted 0 ms 0 KB -