Submission #636875

# Submission time Handle Problem Language Result Execution time Memory
636875 2022-08-30T10:59:42 Z ogibogi2004 Restore Array (RMI19_restore) C++14
38 / 100
301 ms 908 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e4+6;
int A[MAXN],n,m;
vector<pair<int,int> >no_zero;
vector<pair<int,int> >no_one;
vector<pair<int,int> >one;
vector<pair<int,int> >zero;
vector<pair<pair<int,int>,int> >onezero;
int arr[MAXN];
bool done[2*MAXN];
int main()
{
    memset(arr,-1,sizeof(arr));
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int l,r,k,val;
        cin>>l>>r>>k>>val;
        l++;r++;
        if(k==1&&val==1)no_zero.push_back({l,r});
        if(k==r-l+1&&val==1)one.push_back({l,r});
        if(k==1&&val==0)zero.push_back({l,r});
        if(k==r-l+1&&val==0)no_one.push_back({l,r});
    }
    for(auto xd:no_zero)
    {
        for(int i=xd.first;i<=xd.second;i++)
        {
            arr[i]=1;
        }
    }
    for(auto xd:no_one)
    {
        for(int i=xd.first;i<=xd.second;i++)
        {
            if(arr[i]==1)
            {
                cout<<"-1\n";
                return 0;
            }
            arr[i]=0;
        }
    }
    //for(int i=1;i<=n;i++)cout<<arr[i]<<" ";
    //cout<<endl;
    for(auto xd:one)
    {
        bool found=0;
        for(int i=xd.first;i<=xd.second;i++)
        {
            if(arr[i]==1)found=1;
        }
        if(!found)onezero.push_back({xd,1});
    }
    for(auto xd:zero)
    {
        bool found=0;
        for(int i=xd.first;i<=xd.second;i++)
        {
            if(arr[i]==0)found=1;
        }
        if(!found)onezero.push_back({xd,0});
    }
    for(int i=1;i<=n;i++)
    {
        if(arr[i]>=0)continue;
        int minr=n+1,what=-1;
        for(int j=0;j<onezero.size();j++)
        {
            if(done[j]==0&&onezero[j].first.second<minr)
            {
                minr=onezero[j].first.second;
                what=onezero[j].second;
            }
        }
        if(what==-1)
        {
            arr[i]=0;
        }
        else arr[i]=what;
        for(int j=0;j<onezero.size();j++)
        {
            if(onezero[j].first.first<=i&&onezero[j].first.second>=i&&onezero[j].second==arr[i])
            {
                done[j]=1;
            }
        }
    }
    //for(int i=1;i<=n;i++)cout<<arr[i]<<" ";
    //cout<<endl;
    for(int i=0;i<onezero.size();i++)
    {
        if(done[i]==0)
        {
            cout<<"-1\n";
            return 0;
        }
    }
    for(int i=1;i<=n;i++)cout<<arr[i]<<" ";
    cout<<endl;
return 0;
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:69:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for(int j=0;j<onezero.size();j++)
      |                     ~^~~~~~~~~~~~~~~
restore.cpp:82:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for(int j=0;j<onezero.size();j++)
      |                     ~^~~~~~~~~~~~~~~
restore.cpp:92:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for(int i=0;i<onezero.size();i++)
      |                 ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 261 ms 708 KB Output is correct
2 Correct 146 ms 704 KB Output is correct
3 Correct 283 ms 788 KB Output is correct
4 Correct 276 ms 820 KB Output is correct
5 Correct 9 ms 468 KB Output is correct
6 Correct 9 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 261 ms 708 KB Output is correct
2 Correct 146 ms 704 KB Output is correct
3 Correct 283 ms 788 KB Output is correct
4 Correct 276 ms 820 KB Output is correct
5 Correct 9 ms 468 KB Output is correct
6 Correct 9 ms 596 KB Output is correct
7 Correct 301 ms 908 KB Output is correct
8 Correct 158 ms 788 KB Output is correct
9 Correct 161 ms 780 KB Output is correct
10 Correct 135 ms 732 KB Output is correct
11 Correct 10 ms 612 KB Output is correct
12 Correct 9 ms 596 KB Output is correct
13 Correct 144 ms 744 KB Output is correct
14 Correct 13 ms 596 KB Output is correct
15 Correct 13 ms 708 KB Output is correct
16 Correct 14 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -