답안 #199524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199524 2020-02-01T19:04:29 Z Ruxandra985 Restore Array (RMI19_restore) C++14
0 / 100
11 ms 1016 KB
#include <bits/stdc++.h>
#define DIMN 5010
#define DIMM 10010
using namespace std;
vector <pair <int , pair <int,int> > > v[DIMN];
int inq[DIMN], sir[DIMN];
deque <int> q;
pair <int,int> sol[DIMN];
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , m , i , l , r , k , val , nod , vecin , mini , maxi , until;
    fscanf (fin,"%d%d",&n,&m);
    for ( i = 1 ; i <= m ; i++ ){
        fscanf (fin,"%d%d%d%d",&l,&r,&k,&val);
        l++;
        r++;
        if (val == 1){
            mini = (r - k + 1);
            maxi = (r - l + 1);
        }
        else {
            mini = 0;
            maxi = (r - (k + 1) + 1);
        }
        ///mini si maxi = cate 1 uri ar putea fi in intervalul i
        v[l].push_back(make_pair (r , make_pair(mini , maxi)));
        v[r].push_back(make_pair (l , make_pair(mini , maxi)));
    }
    for (i=1;i<=n;i++){
        sol[i] = make_pair(0 , i); /// intre 0 si i 1 - uri
        q.push_back(i);
        inq[i] = 1;
    }
    while (!q.empty()){
        nod = q.front();
        q.pop_front();
        inq[nod] = 0;
        for (i = 0 ; i < v[nod].size() ; i++){
            vecin = v[nod][i].first;
            mini = v[nod][i].second.first;
            maxi = v[nod][i].second.second;
            if (sol[nod-1].first + mini > sol[vecin].first || sol[nod-1].second + maxi < sol[vecin].second){
                sol[vecin].first = max(sol[vecin].first , sol[nod-1].first + mini);
                sol[vecin].second = min(sol[vecin].second , sol[nod-1].second + maxi);
                if (sol[vecin].first > sol[vecin].second){
                    fprintf (fout,"-1");
                    return 0;
                }
                if (!inq[vecin]){
                    inq[vecin] = 1;
                    q.push_back(vecin);
                }
            }
        }
    }
    for (i = 1 ; i <= n ; i++){
        sol[i].first = max(sol[i].first , sol[i-1].first);
    }
    for (i=1;i<=n;i++){
        fprintf (fout,"%d ",sol[i].first - sol[i-1].first);
    }
    return 0;
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:40:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0 ; i < v[nod].size() ; i++){
                      ~~^~~~~~~~~~~~~~~
restore.cpp:13:67: warning: unused variable 'until' [-Wunused-variable]
     int n , m , i , l , r , k , val , nod , vecin , mini , maxi , until;
                                                                   ^~~~~
restore.cpp:14:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d",&n,&m);
     ~~~~~~~^~~~~~~~~~~~~~~~~~
restore.cpp:16:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d%d%d%d",&l,&r,&k,&val);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -