Submission #272875

# Submission time Handle Problem Language Result Execution time Memory
272875 2020-08-18T17:32:04 Z Atill83 Restore Array (RMI19_restore) C++14
100 / 100
590 ms 960 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 5505;
const int MAXN = (int) 5e3 + 5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, m;
vector<pair<int, pii>> ed;
int d[MAXN];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    cin>>n>>m;
    memset(d, 0x7f, sizeof(d));
    for(int i = 0; i < m; i++){
        int l, r, k, val;
        cin>>l>>r>>k>>val;
        l++;r++;
        if(val == 0){
            ed.push_back({-k, {r, l - 1}});
        }else{
            ed.push_back({k - 1, {l - 1, r}});
        }
    }

    for(int i = 0; i < n; i++){
        ed.push_back({0, {i + 1, i}});
        ed.push_back({1, {i, i + 1}});
    }
    d[0] = 0;
    bool done;
    for(int i = 0; i <= n; i++){

        done = 0;

        for(auto j: ed){
            if(d[j.ss.ff] < mod){
                if(d[j.ss.ss] > d[j.ss.ff] + j.ff){
                    done = 1;
                    d[j.ss.ss] = d[j.ss.ff] + j.ff;
                }
            }
        }
    }

    if(done){
        cout<<-1<<endl;
        return 0;
    }

    for(int i = 0; i < n; i++){
        cout<<((d[i + 1] - d[i]) ^ 1)<<" ";

    }


    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:59:5: warning: 'done' may be used uninitialized in this function [-Wmaybe-uninitialized]
   59 |     if(done){
      |     ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 832 KB Output is correct
2 Correct 161 ms 832 KB Output is correct
3 Correct 184 ms 832 KB Output is correct
4 Correct 165 ms 832 KB Output is correct
5 Correct 590 ms 832 KB Output is correct
6 Correct 555 ms 832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 832 KB Output is correct
2 Correct 161 ms 832 KB Output is correct
3 Correct 184 ms 832 KB Output is correct
4 Correct 165 ms 832 KB Output is correct
5 Correct 590 ms 832 KB Output is correct
6 Correct 555 ms 832 KB Output is correct
7 Correct 163 ms 832 KB Output is correct
8 Correct 158 ms 832 KB Output is correct
9 Correct 158 ms 832 KB Output is correct
10 Correct 163 ms 832 KB Output is correct
11 Correct 331 ms 832 KB Output is correct
12 Correct 337 ms 832 KB Output is correct
13 Correct 156 ms 960 KB Output is correct
14 Correct 162 ms 832 KB Output is correct
15 Correct 177 ms 884 KB Output is correct
16 Correct 165 ms 832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 152 ms 832 KB Output is correct
12 Correct 161 ms 832 KB Output is correct
13 Correct 184 ms 832 KB Output is correct
14 Correct 165 ms 832 KB Output is correct
15 Correct 590 ms 832 KB Output is correct
16 Correct 555 ms 832 KB Output is correct
17 Correct 163 ms 832 KB Output is correct
18 Correct 158 ms 832 KB Output is correct
19 Correct 158 ms 832 KB Output is correct
20 Correct 163 ms 832 KB Output is correct
21 Correct 331 ms 832 KB Output is correct
22 Correct 337 ms 832 KB Output is correct
23 Correct 156 ms 960 KB Output is correct
24 Correct 162 ms 832 KB Output is correct
25 Correct 177 ms 884 KB Output is correct
26 Correct 165 ms 832 KB Output is correct
27 Correct 152 ms 832 KB Output is correct
28 Correct 165 ms 832 KB Output is correct
29 Correct 159 ms 880 KB Output is correct
30 Correct 161 ms 832 KB Output is correct
31 Correct 153 ms 884 KB Output is correct
32 Correct 157 ms 884 KB Output is correct
33 Correct 379 ms 832 KB Output is correct
34 Correct 387 ms 832 KB Output is correct
35 Correct 159 ms 832 KB Output is correct
36 Correct 162 ms 832 KB Output is correct