답안 #672182

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672182 2022-12-14T23:18:14 Z danikoynov Restore Array (RMI19_restore) C++14
100 / 100
327 ms 1240 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 10010;
const ll inf = 1e15;

struct edge
{
    int v, u;
    ll w;

    edge(int _v = 0, int _u = 0, ll _w = 0)
    {
        v = _v;
        u = _u;
        w = _w;
    }
};

vector < edge > e;
int n, m;
ll d[maxn];
void solve()
{
    cin >> n >> m;

    for (int i = 1; i <= m; i ++)
    {
        int l, r, k, v;
        cin >> l >> r >> k >> v;
        l ++;
        r ++;
        if (v == 0)
        {
            e.push_back(edge(l - 1, r, r - l + 1 - k));
            //cout << l - 1 << " " << r << " " <<   r - l + 1 - k << endl;
        }
        else
        {
            e.push_back(edge(r, l - 1, - (r - l + 1 - k + 1)));
           // cout << r << " " << l - 1 << " " << - (r - l + 1 - k + 1) << endl;
        }
    }

    for (int i = 1; i <= n; i ++)
    {
        e.push_back(edge(i - 1, i, 1));
        e.push_back(edge(i, i - 1, 0));
        //cout << i - 1 << " " << i << " " << 1 << endl;
        //cout << i << " " << i - 1 << " " << -1 << endl;
    }
    //cout << "0 0 0 " << endl;
    e.push_back(edge(0, 0, 0));

    int last = -1;
    for (int step = 0; step <= n; step ++)
    {
        int x = -1;
        for (edge ed : e)
        {
            if (d[ed.v] + ed.w < d[ed.u])
            {
                //cout << "relax " << ed.v << " " << ed.u << " " << ed.w << endl;
                d[ed.u] = max(- inf, d[ed.v] + ed.w);
                x = ed.u;
            }
        }

       //for (int j = 0; j <= n; j ++)
        //   cout << d[j] << " ";
          //  cout << endl;
        last = x;
    }

    if (last != -1)
        cout << -1 << endl;
    else
    {
        for (int i = 0; i <= n + 1; i ++)
            d[i] = inf;
        for (int i = 0; i <= n; i ++)
        {
            e.push_back(edge(n + 1, i, 0));
        }

        d[n + 1] = 0;
        for (int step = 1; step <= n; step ++)
        {
            for (edge ed : e)
            {
                if (d[ed.v] < inf && d[ed.v] + ed.w < d[ed.u])
                {
                    d[ed.u] = d[ed.v] + ed.w;
                }
            }
        }

        for (int i = 1; i <= n; i ++)
            cout << d[i] - d[i - 1] << " ";
        cout << endl;
    }
}

int main()
{
    speed();
    solve();
    return 0;
}

/**
7 10
0 3 4 1
2 3 1 0
1 2 2 0
1 3 2 0
0 5 3 0
0 5 5 1
1 4 2 0
2 4 1 0
1 3 3 0
3 5 2 0

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 984 KB Output is correct
2 Correct 217 ms 1112 KB Output is correct
3 Correct 235 ms 1116 KB Output is correct
4 Correct 215 ms 1068 KB Output is correct
5 Correct 301 ms 1112 KB Output is correct
6 Correct 301 ms 984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 984 KB Output is correct
2 Correct 217 ms 1112 KB Output is correct
3 Correct 235 ms 1116 KB Output is correct
4 Correct 215 ms 1068 KB Output is correct
5 Correct 301 ms 1112 KB Output is correct
6 Correct 301 ms 984 KB Output is correct
7 Correct 220 ms 1108 KB Output is correct
8 Correct 219 ms 1112 KB Output is correct
9 Correct 219 ms 1112 KB Output is correct
10 Correct 219 ms 1096 KB Output is correct
11 Correct 320 ms 1112 KB Output is correct
12 Correct 327 ms 1120 KB Output is correct
13 Correct 211 ms 1112 KB Output is correct
14 Correct 219 ms 1108 KB Output is correct
15 Correct 228 ms 1112 KB Output is correct
16 Correct 262 ms 1240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 227 ms 984 KB Output is correct
12 Correct 217 ms 1112 KB Output is correct
13 Correct 235 ms 1116 KB Output is correct
14 Correct 215 ms 1068 KB Output is correct
15 Correct 301 ms 1112 KB Output is correct
16 Correct 301 ms 984 KB Output is correct
17 Correct 220 ms 1108 KB Output is correct
18 Correct 219 ms 1112 KB Output is correct
19 Correct 219 ms 1112 KB Output is correct
20 Correct 219 ms 1096 KB Output is correct
21 Correct 320 ms 1112 KB Output is correct
22 Correct 327 ms 1120 KB Output is correct
23 Correct 211 ms 1112 KB Output is correct
24 Correct 219 ms 1108 KB Output is correct
25 Correct 228 ms 1112 KB Output is correct
26 Correct 262 ms 1240 KB Output is correct
27 Correct 210 ms 1112 KB Output is correct
28 Correct 212 ms 1112 KB Output is correct
29 Correct 209 ms 1112 KB Output is correct
30 Correct 271 ms 1112 KB Output is correct
31 Correct 210 ms 1112 KB Output is correct
32 Correct 206 ms 1112 KB Output is correct
33 Correct 306 ms 1112 KB Output is correct
34 Correct 308 ms 1112 KB Output is correct
35 Correct 214 ms 1112 KB Output is correct
36 Correct 211 ms 1104 KB Output is correct