답안 #198084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198084 2020-01-24T16:14:37 Z model_code Restore Array (RMI19_restore) C++17
100 / 100
123 ms 1016 KB
/**
* user:  tudose-aad
* fname: Maria Alexa
* lname: Tudose
* task:  restore
* score: 100.0
* date:  2019-10-10 06:37:16.189929
*/
#include <bits/stdc++.h>
#define impossible { cout << "-1\n"; exit(0); }

using namespace std;

const int Nmax = 10005;
typedef long long ll;
const int inf = 5005;


vector<pair<int,int>> v[Nmax];
int n, m;
int dist[Nmax];
bool inQ[Nmax];
int bagat[Nmax];


void add_edge(int x, int y, int c)
{
    v[x].push_back({y, c});
}

void add_res(int i, int j, int k, int val)
{
    if(val == 0)
        add_edge(j, i-1, -k);
    else add_edge(i-1, j, k-1);
}

static bool min_to(int &x, int y)
{
    if(x <= y) return 0;
    x = y;
    if(x < 0) impossible;
    return 1;
}

void bellman(int start)
{
    queue<int> q;
    int i;
    for(i=0; i<=n; ++i) inQ[i] = 0, dist[i] = inf;

    inQ[start] = 1;
    q.push(start);
    dist[start] = 0;

    while(q.size())
    {
        int node = q.front();
        q.pop();
        inQ[node] = 0;

        for(auto it : v[node])
            if(min_to(dist[it.first], dist[node] + it.second))
            {
                ++bagat[it.first];
                if(bagat[it.first] > m) impossible;

                if(!inQ[it.first])
                {
                    inQ[it.first] = 1;
                    q.push(it.first);

                }
            }
    }
}

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;
    int i;
    for(i=1; i<=m; ++i)
    {
        int L, R, K, Val;
        cin >> L >> R >> K >> Val;
        ++L; ++R;
        add_res(L, R, K, Val);
    }

    for(i=1; i<=n; ++i)
    {
        add_edge(i-1, i, 1);
        add_edge(i, i-1, 0);
    }

    bellman(0);
    for(i=1; i<=n; ++i) cout << ((dist[i] - dist[i-1]) ^ 1) << ' ';


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 888 KB Output is correct
2 Correct 7 ms 888 KB Output is correct
3 Correct 6 ms 1016 KB Output is correct
4 Correct 8 ms 1016 KB Output is correct
5 Correct 6 ms 888 KB Output is correct
6 Correct 4 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 888 KB Output is correct
2 Correct 7 ms 888 KB Output is correct
3 Correct 6 ms 1016 KB Output is correct
4 Correct 8 ms 1016 KB Output is correct
5 Correct 6 ms 888 KB Output is correct
6 Correct 4 ms 888 KB Output is correct
7 Correct 16 ms 1016 KB Output is correct
8 Correct 16 ms 1008 KB Output is correct
9 Correct 17 ms 1016 KB Output is correct
10 Correct 27 ms 992 KB Output is correct
11 Correct 14 ms 1016 KB Output is correct
12 Correct 7 ms 888 KB Output is correct
13 Correct 16 ms 1016 KB Output is correct
14 Correct 36 ms 1008 KB Output is correct
15 Correct 95 ms 1008 KB Output is correct
16 Correct 123 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 7 ms 888 KB Output is correct
12 Correct 7 ms 888 KB Output is correct
13 Correct 6 ms 1016 KB Output is correct
14 Correct 8 ms 1016 KB Output is correct
15 Correct 6 ms 888 KB Output is correct
16 Correct 4 ms 888 KB Output is correct
17 Correct 16 ms 1016 KB Output is correct
18 Correct 16 ms 1008 KB Output is correct
19 Correct 17 ms 1016 KB Output is correct
20 Correct 27 ms 992 KB Output is correct
21 Correct 14 ms 1016 KB Output is correct
22 Correct 7 ms 888 KB Output is correct
23 Correct 16 ms 1016 KB Output is correct
24 Correct 36 ms 1008 KB Output is correct
25 Correct 95 ms 1008 KB Output is correct
26 Correct 123 ms 1016 KB Output is correct
27 Correct 10 ms 892 KB Output is correct
28 Correct 10 ms 1016 KB Output is correct
29 Correct 10 ms 1016 KB Output is correct
30 Correct 10 ms 1016 KB Output is correct
31 Correct 10 ms 888 KB Output is correct
32 Correct 10 ms 888 KB Output is correct
33 Correct 7 ms 888 KB Output is correct
34 Correct 7 ms 888 KB Output is correct
35 Correct 10 ms 1016 KB Output is correct
36 Correct 11 ms 1016 KB Output is correct