Submission #199526

# Submission time Handle Problem Language Result Execution time Memory
199526 2020-02-01T19:32:45 Z Ruxandra985 Restore Array (RMI19_restore) C++14
0 / 100
10 ms 888 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 - (l + k - 1) + 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 (vecin >= nod){
                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);
                    //printf ("%d %d %d %d\n",nod , vecin , sol[vecin].first , sol[vecin].second);
                    if (sol[vecin].first > sol[vecin].second){
                        fprintf (fout,"-1");
                        return 0;
                    }
                    if (!inq[vecin]){
                        inq[vecin] = 1;
                        q.push_back(vecin);
                    }
                }
            }
            else {
                if (vecin-1 && sol[nod].first - mini > sol[vecin-1].first || sol[nod].second - maxi < sol[vecin-1].second){
                    sol[vecin-1].first = max(sol[vecin-1].first , sol[nod].first - mini);
                    sol[vecin-1].second = min(sol[vecin-1].second , sol[nod].second - maxi);
                    //printf ("%d %d %d %d\n",nod , vecin-1 , sol[vecin-1].first , sol[vecin-1].second);
                    if (sol[vecin-1].first > sol[vecin-1].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:60:29: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
                 if (vecin-1 && sol[nod].first - mini > sol[vecin-1].first || sol[nod].second - maxi < sol[vecin-1].second){
                     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -