Submission #298452

# Submission time Handle Problem Language Result Execution time Memory
298452 2020-09-12T21:25:34 Z mat_v Restore Array (RMI19_restore) C++14
100 / 100
388 ms 1024 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define maxn 100005

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n,m;
int x[maxn], y[maxn];
ll w[maxn];
int br = 1;
ll dist[5005];


int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    ff(i,0,n - 1){
        x[br] = i;
        y[br] = i+1;
        w[br] = 0;
        br++;
        x[br] = i+1;
        y[br] = i;
        w[br] = 1;
        br++;
    }
    ff(i,1,m){
        int a, b;
        int k;
        int val;
        cin >> a >> b >> k >> val;
        a++;
        b++;
        if(val == 0){
            /// barem (r - l + 1 - k + 1) keca
            x[br] = b;
            y[br] = a - 1;
            w[br] = b - a + 1 - k;
            br++;
        }
        else{
            /// maksimalno (r - l + 2 - k) keca
            x[br] = a - 1;
            y[br] = b;
            w[br] = k + a - 2 - b;
            br++;
        }
    }
    dist[0] = 0;
    ff(i,1,n)dist[i] = 1e9;

    ff(i,1,n){
        ff(j,1,br - 1){
            int p1 = x[j];
            int p2 = y[j];
            ll c = w[j];
            if(dist[p1] > dist[p2] + c)dist[p1] = dist[p2] + c;
        }
    }
    ff(j,1,br - 1){
        int p1 = x[j];
        int p2 = y[j];
        ll c = w[j];
        if(dist[p1] > dist[p2] + c){
            cout << -1 << "\n";
            return 0;
        }
    }
    ff(i,1,n){
        cout << dist[i] - dist[i - 1] << " ";
    }
    cout << "\n";
    return 0;

}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
restore.cpp:35:5: note: in expansion of macro 'ff'
   35 |     ff(i,0,n - 1){
      |     ^~
restore.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
restore.cpp:45:5: note: in expansion of macro 'ff'
   45 |     ff(i,1,m){
      |     ^~
restore.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
restore.cpp:68:5: note: in expansion of macro 'ff'
   68 |     ff(i,1,n)dist[i] = 1e9;
      |     ^~
restore.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
restore.cpp:70:5: note: in expansion of macro 'ff'
   70 |     ff(i,1,n){
      |     ^~
restore.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
restore.cpp:71:9: note: in expansion of macro 'ff'
   71 |         ff(j,1,br - 1){
      |         ^~
restore.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
restore.cpp:78:5: note: in expansion of macro 'ff'
   78 |     ff(j,1,br - 1){
      |     ^~
restore.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
restore.cpp:87:5: note: in expansion of macro 'ff'
   87 |     ff(i,1,n){
      |     ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 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 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 856 KB Output is correct
2 Correct 144 ms 868 KB Output is correct
3 Correct 142 ms 888 KB Output is correct
4 Correct 149 ms 888 KB Output is correct
5 Correct 367 ms 888 KB Output is correct
6 Correct 339 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 856 KB Output is correct
2 Correct 144 ms 868 KB Output is correct
3 Correct 142 ms 888 KB Output is correct
4 Correct 149 ms 888 KB Output is correct
5 Correct 367 ms 888 KB Output is correct
6 Correct 339 ms 768 KB Output is correct
7 Correct 150 ms 1016 KB Output is correct
8 Correct 147 ms 896 KB Output is correct
9 Correct 147 ms 896 KB Output is correct
10 Correct 149 ms 888 KB Output is correct
11 Correct 381 ms 768 KB Output is correct
12 Correct 388 ms 896 KB Output is correct
13 Correct 143 ms 888 KB Output is correct
14 Correct 148 ms 1024 KB Output is correct
15 Correct 152 ms 900 KB Output is correct
16 Correct 158 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 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 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 141 ms 856 KB Output is correct
12 Correct 144 ms 868 KB Output is correct
13 Correct 142 ms 888 KB Output is correct
14 Correct 149 ms 888 KB Output is correct
15 Correct 367 ms 888 KB Output is correct
16 Correct 339 ms 768 KB Output is correct
17 Correct 150 ms 1016 KB Output is correct
18 Correct 147 ms 896 KB Output is correct
19 Correct 147 ms 896 KB Output is correct
20 Correct 149 ms 888 KB Output is correct
21 Correct 381 ms 768 KB Output is correct
22 Correct 388 ms 896 KB Output is correct
23 Correct 143 ms 888 KB Output is correct
24 Correct 148 ms 1024 KB Output is correct
25 Correct 152 ms 900 KB Output is correct
26 Correct 158 ms 896 KB Output is correct
27 Correct 140 ms 888 KB Output is correct
28 Correct 148 ms 1016 KB Output is correct
29 Correct 147 ms 888 KB Output is correct
30 Correct 148 ms 896 KB Output is correct
31 Correct 138 ms 888 KB Output is correct
32 Correct 141 ms 888 KB Output is correct
33 Correct 366 ms 1020 KB Output is correct
34 Correct 368 ms 888 KB Output is correct
35 Correct 145 ms 896 KB Output is correct
36 Correct 146 ms 896 KB Output is correct