Submission #312797

#TimeUsernameProblemLanguageResultExecution timeMemory
312797BeanZRestore Array (RMI19_restore)C++14
100 / 100
379 ms1404 KiB
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 5005;
struct viet{
    ll u, v, c;
};
ll d[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("A.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) d[i] = i;
    vector<viet> E;
    for (int i = 1; i <= m; i++){
        ll l, r, k, v;
        cin >> l >> r >> k >> v;
        l++;
        r++;
        if (v == 1){
            E.push_back({r, l - 1, -(r - l + 1 - k + 1)});
        } else {
            // S(r) - S(l - 1) <= (r - l + 1 - k)
            E.push_back({l - 1, r, r - l + 1 - k});
        }
    }
    for (int i = 1; i <= n; i++){
        E.push_back({i - 1, i, 1});
        E.push_back({i, i - 1, 0});
    }
    ll x;
    for (int i = 1; i <= n; i++){
        x = -1;
        for (auto j : E){
            if (d[j.v] > (d[j.u] + j.c)){
                d[j.v] = d[j.u] + j.c;
                x = j.v;
            }
        }
    }
    if (x != -1) cout << -1;
    else {
        for (int i = 1; i <= n; i++){
            //cout << d[i] << " ";
            if (d[i] > d[i - 1]) cout << 1 << " ";
            else cout << 0 << " ";
        }
    }
}
/*
*/

Compilation message (stderr)

restore.cpp: In function 'int main()':
restore.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   15 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
restore.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   16 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
restore.cpp:48:5: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |     if (x != -1) cout << -1;
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...