답안 #199597

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199597 2020-02-02T06:32:13 Z Ruxandra985 Restore Array (RMI19_restore) C++14
0 / 100
83 ms 117548 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];
pair <int,int> pos[DIMN][DIMN];
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , m , i , l , r , k , val , nod , vecin , mini , maxi , j , poz;
    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 , min(vecin , sol[nod-1].first + mini));
                    sol[vecin].second = min(sol[vecin].second , min(vecin , 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 , max (0 , sol[nod].first - maxi));
                    sol[vecin-1].second = min(sol[vecin-1].second , max(0 , sol[nod].second - mini));
                    //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");
                        //printf ("aici");
                        return 0;
                    }
                    if (!inq[vecin]){
                        inq[vecin] = 1;
                        q.push_back(vecin);
                    }
                }
            }
        }
    }
    if (0>=sol[i].first)
        pos[1][0] = make_pair(1 , 0);
    if (1<=sol[i].second)
        pos[1][1] = make_pair(1 , 0);
    for (i = 2 ; i <= n ; i++){
        for (j = sol[i].first ; j <= sol[i].second ; j++){

            if (j-1>=0 && pos[i-1][j-1].first){ /// add 1
                pos[i][j] = make_pair(1 , j-1);
            }
            else {
                if (pos[i-1][j].first){ /// add 0
                    pos[i][j] = make_pair(1 , j);
                }
            }
        }
    }
    int stot = 0;
    for (j = sol[n].first ; j <= sol[n].second ; j++){
        if (pos[n][j].first){
            stot = j;
            break;
        }
    }
    poz = n;
    while (poz){
        sir[poz] = stot;
        stot = pos[poz][stot].second;
        poz--;
    }
    for (i=1;i<=n;i++){
        fprintf (fout,"%d ",sir[i] - sir[i-1]);
    }
    return 0;
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:41:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0 ; i < v[nod].size() ; i++){
                      ~~^~~~~~~~~~~~~~~
restore.cpp:15: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:17: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 408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 117548 KB Output is correct
2 Incorrect 83 ms 116220 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 117548 KB Output is correct
2 Incorrect 83 ms 116220 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 408 KB Output isn't correct
2 Halted 0 ms 0 KB -