Submission #332261

# Submission time Handle Problem Language Result Execution time Memory
332261 2020-12-01T19:51:38 Z 2fat2code Restore Array (RMI19_restore) C++17
0 / 100
2 ms 364 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)

// restore array rmi 2019

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int nmax = 5005;

int n, m, dist[nmax];

struct item{
    int l, r, val;
};

vector <item> edges;

void add_edge(int l, int r, int k, int val){
    if(val == 0){
        int curr = (r - l + 1) - k;
        edges.push_back({l - 1, r, curr});
    }
    else{
        edges.push_back({r, l - 1, r - l + 1 - (k - 1)});
    }
}

bool bellman_ford(){
    for(int i=1;i<=n+1;i++){
        for(auto it : edges){
            if(dist[it.r] > dist[it.l] + it.val){
                dist[it.r] = dist[it.l] + it.val;
            }
        }
    }
    for(auto it : edges){
        if(dist[it.r] > dist[it.l] + it.val){
            return false;
        }
    }
    return true;
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    freopen("input.in", "r", stdin);
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        dist[i] = 1e18;
    }
    for(int i=0;i<n;i++){
        edges.push_back({i, i+1, 1});
    }
    for(int i=1;i<=n;i++){
        edges.push_back({i, i - 1, 0});
    }
    for(int i=1;i<=m;i++){
        int l, r, k, val;
        cin >> l >> r >> k >> val;
        ++l; ++r;
        add_edge(l, r, k, val);
    }
    if(bellman_ford() == false){
        rc(-1);
    }
    else{
        for(int i=1;i<=n;i++){
            cout << dist[i] - dist[i - 1] << ' ';
        }
        return 0;
    }
}

Compilation message

restore.cpp: In function 'int32_t main()':
restore.cpp:56:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   56 |     freopen("input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -