답안 #258078

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258078 2020-08-05T10:25:29 Z tqbfjotld Restore Array (RMI19_restore) C++14
0 / 100
16 ms 1148 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){
    if (a.second.first==1 && a.second.second==1) return true;
    if (b.second.first==1 && b.second.second==1) return false;
    if (a.second.first==a.first.second-a.first.first+1 && a.second.second==0) return true;
    if (b.second.first==b.first.second-b.first.first+1 && b.second.second==0) return false;
    return a<b;
}

int arr[5005];
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){
        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:22: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:25: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);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 768 KB Output is correct
2 Correct 14 ms 896 KB Output is correct
3 Correct 16 ms 768 KB Output is correct
4 Runtime error 7 ms 1148 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 768 KB Output is correct
2 Correct 14 ms 896 KB Output is correct
3 Correct 16 ms 768 KB Output is correct
4 Runtime error 7 ms 1148 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -