답안 #203458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203458 2020-02-20T18:01:09 Z alexandra_udristoiu Restore Array (RMI19_restore) C++14
100 / 100
146 ms 1400 KB
#include<iostream>
#include<queue>
#include<vector>
#define f first
#define s second
using namespace std;
int n, m, i, x, y, t, val, nod, vecin;
int num[5005], sol[5005], viz[5005], sum[5005];
pair<int, int> d[5005];
queue<int> c;
struct str{
    int x, minim, maxim;
};
vector<str> v[5005];
int verif(int x){
    if(sum[x] < d[x].f || sum[x] > d[x].s){
        return 0;
    }
    for(int i = 0; i < v[x].size(); i++){
        int y = v[x][i].x;
        if(y > x){
            continue;
        }
        if(sum[x] - sum[y] < v[x][i].minim || sum[x] - sum[y] > v[x][i].maxim){
            return 0;
        }
    }
    return 1;
}
int main(){
    cin>> n >> m;
    for(i = 1; i <= m; i++){
        cin>> x >> y >> val >> t;
        y++;
        if(t == 1){
            v[x].push_back( {y, 0, val - 1} );
            v[y].push_back( {x, 0, val - 1} );
        }
        else{
            v[x].push_back( {y, val, y - x + 1} );
            v[y].push_back( {x, val, y - x + 1} );
        }
    }
    for(i = 1; i <= n; i++){
        v[i].push_back( {i - 1, 0, 1} );
        v[i - 1].push_back( {i, 0, 1} );
    }
    for(i = 1; i <= n; i++){
        d[i] = make_pair(0, i);
        num[i] = i;
    }
    for(i = 0; i <= n; i++){
        viz[i] = 1;
        c.push(i);
    }
    while(!c.empty()){
        nod = c.front();
        viz[nod] = 0;
        c.pop();
        for(i = 0; i < v[nod].size(); i++){
            vecin = v[nod][i].x;
            if(vecin > nod){
                d[vecin].f = max(d[vecin].f, d[nod].f + v[nod][i].minim);
                d[vecin].s = min(d[vecin].s, d[nod].s + v[nod][i].maxim);
            }
            else{
                d[vecin].f = max(d[vecin].f, d[nod].f - v[nod][i].maxim);
                d[vecin].s = min(d[vecin].s, d[nod].s - v[nod][i].minim);
            }
            if(d[vecin].s - d[vecin].f < num[vecin]){
                num[vecin] = d[vecin].s - d[vecin].f;
                if(viz[vecin] == 0){
                    viz[vecin] = 1;
                    c.push(vecin);
                }
            }
            if(d[vecin].s < d[vecin].f){
                cout<< -1;
                return 0;
            }
        }
    }
    for(i = 1; i <= n; i++){
        sum[i] = sum[i - 1];
        if(verif(i)){
            sol[i] = 1;
        }
        else{
            sol[i] = 0;
            sum[i]++;
        }
    }
    for(i = 1; i <= n; i++){
        cout<< sol[i] <<" ";
    }
    for(i = 1; i <= n; i++){
        if(verif(i) == 0){
            cout<<"\n"<< i <<" GRESIT";
        }
    }
}

Compilation message

restore.cpp: In function 'int verif(int)':
restore.cpp:19:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v[x].size(); i++){
                    ~~^~~~~~~~~~~~~
restore.cpp: In function 'int main()':
restore.cpp:60:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i = 0; i < v[nod].size(); i++){
                    ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 1144 KB Output is correct
2 Correct 19 ms 1144 KB Output is correct
3 Correct 18 ms 1144 KB Output is correct
4 Correct 25 ms 1144 KB Output is correct
5 Correct 19 ms 1272 KB Output is correct
6 Correct 18 ms 1276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 1144 KB Output is correct
2 Correct 19 ms 1144 KB Output is correct
3 Correct 18 ms 1144 KB Output is correct
4 Correct 25 ms 1144 KB Output is correct
5 Correct 19 ms 1272 KB Output is correct
6 Correct 18 ms 1276 KB Output is correct
7 Correct 22 ms 1272 KB Output is correct
8 Correct 21 ms 1272 KB Output is correct
9 Correct 21 ms 1272 KB Output is correct
10 Correct 20 ms 1272 KB Output is correct
11 Correct 19 ms 1272 KB Output is correct
12 Correct 19 ms 1272 KB Output is correct
13 Correct 19 ms 1144 KB Output is correct
14 Correct 43 ms 1272 KB Output is correct
15 Correct 113 ms 1400 KB Output is correct
16 Correct 146 ms 1392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 18 ms 1144 KB Output is correct
12 Correct 19 ms 1144 KB Output is correct
13 Correct 18 ms 1144 KB Output is correct
14 Correct 25 ms 1144 KB Output is correct
15 Correct 19 ms 1272 KB Output is correct
16 Correct 18 ms 1276 KB Output is correct
17 Correct 22 ms 1272 KB Output is correct
18 Correct 21 ms 1272 KB Output is correct
19 Correct 21 ms 1272 KB Output is correct
20 Correct 20 ms 1272 KB Output is correct
21 Correct 19 ms 1272 KB Output is correct
22 Correct 19 ms 1272 KB Output is correct
23 Correct 19 ms 1144 KB Output is correct
24 Correct 43 ms 1272 KB Output is correct
25 Correct 113 ms 1400 KB Output is correct
26 Correct 146 ms 1392 KB Output is correct
27 Correct 22 ms 1272 KB Output is correct
28 Correct 23 ms 1272 KB Output is correct
29 Correct 23 ms 1272 KB Output is correct
30 Correct 25 ms 1264 KB Output is correct
31 Correct 23 ms 1272 KB Output is correct
32 Correct 23 ms 1272 KB Output is correct
33 Correct 19 ms 1272 KB Output is correct
34 Correct 20 ms 1276 KB Output is correct
35 Correct 24 ms 1272 KB Output is correct
36 Correct 23 ms 1272 KB Output is correct