답안 #484846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
484846 2021-11-05T15:49:11 Z blue Restore Array (RMI19_restore) C++17
100 / 100
355 ms 972 KB
#include <iostream>
#include <vector>
using namespace std;

using vi = vector<int>;
#define pb push_back

const int INF = 1'000'000;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N, M;
    cin >> N >> M;

    vi u, v, w;

    for(int j = 1; j <= M; j++)
    {
        int l, r, k, val;
        cin >> l >> r >> k >> val;
        l++;
        r++;

        if(val == 0)
        {
            u.pb(l-1);
            v.pb(r);
            w.pb(r-l+1 - k);
        }
        else
        {
            u.pb(r);
            v.pb(l-1);
            w.pb(-(r-l+2 - k));
        }
    }

    for(int i = 0; i < N; i++)
    {
        u.pb(i);
        v.pb(i+1);
        w.pb(1);

        u.pb(i+1);
        v.pb(i);
        w.pb(0);
    }

    vi sp(1+N, INF);
    sp[0] = 0;

    for(int q = 1; q <= N; q++)
    {
        for(int j = 0; j < 2*N+M; j++)
        {
            sp[v[j]] = min(sp[v[j]], sp[u[j]] + w[j]);
        }
    }

    bool works = 1;
    for(int j = 0; j < 2*N+M; j++)
        if(sp[v[j]] > sp[u[j]] + w[j])
            works = 0;

    // cerr << u[0] << ' '<< v[0] << ' ' << w[0] << '\n';

    if(!works) cout << "-1\n";
    else
    {
        for(int i = 1; i <= N; i++)
        {
            cout << (sp[i] != sp[i-1]) << ' ';
        }
        cout << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 343 ms 736 KB Output is correct
2 Correct 346 ms 860 KB Output is correct
3 Correct 333 ms 844 KB Output is correct
4 Correct 346 ms 844 KB Output is correct
5 Correct 339 ms 844 KB Output is correct
6 Correct 322 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 343 ms 736 KB Output is correct
2 Correct 346 ms 860 KB Output is correct
3 Correct 333 ms 844 KB Output is correct
4 Correct 346 ms 844 KB Output is correct
5 Correct 339 ms 844 KB Output is correct
6 Correct 322 ms 844 KB Output is correct
7 Correct 348 ms 880 KB Output is correct
8 Correct 349 ms 872 KB Output is correct
9 Correct 347 ms 864 KB Output is correct
10 Correct 348 ms 852 KB Output is correct
11 Correct 347 ms 844 KB Output is correct
12 Correct 338 ms 844 KB Output is correct
13 Correct 332 ms 864 KB Output is correct
14 Correct 350 ms 876 KB Output is correct
15 Correct 355 ms 868 KB Output is correct
16 Correct 350 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 343 ms 736 KB Output is correct
12 Correct 346 ms 860 KB Output is correct
13 Correct 333 ms 844 KB Output is correct
14 Correct 346 ms 844 KB Output is correct
15 Correct 339 ms 844 KB Output is correct
16 Correct 322 ms 844 KB Output is correct
17 Correct 348 ms 880 KB Output is correct
18 Correct 349 ms 872 KB Output is correct
19 Correct 347 ms 864 KB Output is correct
20 Correct 348 ms 852 KB Output is correct
21 Correct 347 ms 844 KB Output is correct
22 Correct 338 ms 844 KB Output is correct
23 Correct 332 ms 864 KB Output is correct
24 Correct 350 ms 876 KB Output is correct
25 Correct 355 ms 868 KB Output is correct
26 Correct 350 ms 876 KB Output is correct
27 Correct 326 ms 844 KB Output is correct
28 Correct 334 ms 888 KB Output is correct
29 Correct 328 ms 872 KB Output is correct
30 Correct 337 ms 888 KB Output is correct
31 Correct 323 ms 860 KB Output is correct
32 Correct 331 ms 964 KB Output is correct
33 Correct 336 ms 844 KB Output is correct
34 Correct 325 ms 844 KB Output is correct
35 Correct 337 ms 972 KB Output is correct
36 Correct 332 ms 888 KB Output is correct