답안 #636871

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
636871 2022-08-30T10:48:01 Z ogibogi2004 Restore Array (RMI19_restore) C++14
0 / 100
158 ms 780 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=5e3+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;
        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(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 i=0;i<onezero.size();i++)
        {
            if(done[i]==0&&onezero[i].first.second<minr)
            {
                minr=onezero[i].first.second;
                what=onezero[i].second;
            }
        }
        if(what==-1)
        {
            arr[i]=0;
        }
        else arr[i]=what;
        for(int i=0;i<onezero.size();i++)
        {
            if(onezero[i].first.first<=i&&onezero[i].first.second>=i&&onezero[i].second==arr[i])
            {
                done[i]=1;
            }
        }
    }
    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:66: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]
   66 |         for(int i=0;i<onezero.size();i++)
      |                     ~^~~~~~~~~~~~~~~
restore.cpp:79: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]
   79 |         for(int i=0;i<onezero.size();i++)
      |                     ~^~~~~~~~~~~~~~~
restore.cpp:87: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]
   87 |     for(int i=0;i<onezero.size();i++)
      |                 ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 158 ms 780 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 158 ms 780 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -