Submission #672173

# Submission time Handle Problem Language Result Execution time Memory
672173 2022-12-14T22:59:14 Z danikoynov Restore Array (RMI19_restore) C++14
0 / 100
169 ms 968 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(r, l - 1, - (r - l + 1 - k)));
            ///cout << l - 1 << " " << r << " " <<  - (r - l + 1 - k) << endl;
        }
        else
        {
            e.push_back(edge(l - 1, r, 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));
        ///cout << i - 1 << " " << i << " " << 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])
            {
                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;
}

/**
5 2
0 3 2 1
0 3 1 0
*/
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -