Submission #258083

# Submission time Handle Problem Language Result Execution time Memory
258083 2020-08-05T10:32:51 Z tqbfjotld Restore Array (RMI19_restore) C++14
13 / 100
21 ms 896 KB
/*
value = 0 --> sum of range(l,r)<=r-l+1-k
value = 1 --> sum of range(l,r)>=r-l+1-k+1
*/
#include <bits/stdc++.h>
using namespace std;
typedef pair<pair<int,int>,pair<int,int> > query;

bool cmp(query a, query b){
    int v1 = a.second.first==1&&a.second.second==1;
    int v2 = b.second.first==1&&b.second.second==1;
    if (v1!=v2) return v1>v2;
    v1 = (a.second.first==a.first.second-a.first.first+1 && a.second.second==0);
    v2 = (b.second.first==b.first.second-b.first.first+1 && b.second.second==0);
    if (v1!=v2) return v1>v2;
    return a<b;
}

int arr[50005];
vector<query> queries;

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for (int x = 0; x<m; x++){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        queries.push_back({{a,b},{c,d}});
    }
    sort(queries.begin(),queries.end(),cmp);
    for (auto x : queries){
        //printf("%d %d %d %d\n",x);
        int l = x.first.first;
        int r = x.first.second;
        int k = x.second.first;
        int val = x.second.second;
        if (k==1&&val==1){
            for (int x = l; x<=r; x++){
                arr[x] = 1;
            }
            continue;
        }
        if (k==r-l+1 && val==0){
            for (int x = l; x<=r; x++){
                if (arr[x]==1){
                    printf("-1");
                    return 0;
                }
            }
            continue;
        }
        //if (val==0){
            bool found = false;
            for (int x = l; x<=r; x++){
                if (val==arr[x]) found = true;
            }
            if (!found){
                printf("-1");
                return 0;
            }
        //}
    }
    for (int x = 0; x<n; x++){
        printf("%d ",arr[x]);
    }
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
restore.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d",&a,&b,&c,&d);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 768 KB Output is correct
2 Correct 14 ms 768 KB Output is correct
3 Correct 15 ms 640 KB Output is correct
4 Correct 14 ms 768 KB Output is correct
5 Correct 10 ms 896 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 768 KB Output is correct
2 Correct 14 ms 768 KB Output is correct
3 Correct 15 ms 640 KB Output is correct
4 Correct 14 ms 768 KB Output is correct
5 Correct 10 ms 896 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Incorrect 10 ms 896 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -