Submission #629996

# Submission time Handle Problem Language Result Execution time Memory
629996 2022-08-15T13:41:19 Z Do_you_copy Restore Array (RMI19_restore) C++17
100 / 100
116 ms 3248 KB
#include <bits/stdc++.h>
//#define int long long
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

//const ll Mod = 1000000007;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;
const ll inf = 0x3f3f3f3f3f3f3f3f;
int n, m;

ll d[maxN];
vector <pii> adj[maxN];
bool onstack[maxN];
int cnt[maxN];

bool SPFA(int s){
    fill(d, d + n + 2, inf);
    queue <int> Q;
    Q.push(s);
    onstack[s] = 1;
    d[s] = 0;
    while (!Q.empty()){
        int u = Q.front(); Q.pop();
        onstack[u] = 0;
        for (auto &i: adj[u]){
            if (d[u] + i.se < d[i.fi]){
                d[i.fi] = d[u] + i.se;
                cnt[i.fi] = cnt[u] + 1;
                if (cnt[i.fi] == n + 1 || d[i.fi] < 0){
                    //negative cycle
                    return 0;
                }
                if (!onstack[i.fi]){
                    onstack[i.fi] = 1;
                    Q.push(i.fi);
                }
            }
        }
    }
    return 1;
}

void Init(){
    cin >> n >> m;
    for (int i = 1; i <= m; ++i){
        int l, r, k, val;
        cin >> l >> r >> k >> val;
        ++l; ++r;
        if (val){
            adj[r].pb({l - 1, -(r - l + 1) + k - 1});
        }
        else adj[l - 1].pb({r, (r - l + 1) - k});
    }
    for (int i = 1; i <= n; ++i){
        adj[i - 1].pb({i, 1});
        adj[i].pb({i - 1, 0});
    }
    if (!SPFA(0)){
        cout << -1; exit(0);
    };
    for (int i = 1; i <= n; ++i){
        cout << d[i] - d[i - 1] << " ";
    }
    cout << "\n";
}

#define debu
#define taskname "test"
signed main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        #ifdef debug
        freopen(taskname".out", "w", stdout);
        #endif
    }
    faster;
    ll tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream timeout("timeout.txt");
        timeout << 1000 * double(clock()) / CLOCKS_PER_SEC;
        #ifndef debug
        cerr << "\nTime elapsed: " << 1000 * double(clock()) / CLOCKS_PER_SEC << "ms\n";
        #endif
    }
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 3020 KB Output is correct
2 Correct 16 ms 3044 KB Output is correct
3 Correct 13 ms 3028 KB Output is correct
4 Correct 15 ms 3048 KB Output is correct
5 Correct 4 ms 3028 KB Output is correct
6 Correct 5 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 3020 KB Output is correct
2 Correct 16 ms 3044 KB Output is correct
3 Correct 13 ms 3028 KB Output is correct
4 Correct 15 ms 3048 KB Output is correct
5 Correct 4 ms 3028 KB Output is correct
6 Correct 5 ms 3028 KB Output is correct
7 Correct 13 ms 3048 KB Output is correct
8 Correct 13 ms 3104 KB Output is correct
9 Correct 18 ms 3100 KB Output is correct
10 Correct 11 ms 3028 KB Output is correct
11 Correct 4 ms 3028 KB Output is correct
12 Correct 6 ms 3156 KB Output is correct
13 Correct 13 ms 3212 KB Output is correct
14 Correct 19 ms 3156 KB Output is correct
15 Correct 35 ms 3156 KB Output is correct
16 Correct 116 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 16 ms 3020 KB Output is correct
12 Correct 16 ms 3044 KB Output is correct
13 Correct 13 ms 3028 KB Output is correct
14 Correct 15 ms 3048 KB Output is correct
15 Correct 4 ms 3028 KB Output is correct
16 Correct 5 ms 3028 KB Output is correct
17 Correct 13 ms 3048 KB Output is correct
18 Correct 13 ms 3104 KB Output is correct
19 Correct 18 ms 3100 KB Output is correct
20 Correct 11 ms 3028 KB Output is correct
21 Correct 4 ms 3028 KB Output is correct
22 Correct 6 ms 3156 KB Output is correct
23 Correct 13 ms 3212 KB Output is correct
24 Correct 19 ms 3156 KB Output is correct
25 Correct 35 ms 3156 KB Output is correct
26 Correct 116 ms 3156 KB Output is correct
27 Correct 7 ms 3156 KB Output is correct
28 Correct 7 ms 3200 KB Output is correct
29 Correct 7 ms 3156 KB Output is correct
30 Correct 8 ms 3248 KB Output is correct
31 Correct 8 ms 3156 KB Output is correct
32 Correct 7 ms 3156 KB Output is correct
33 Correct 5 ms 3156 KB Output is correct
34 Correct 5 ms 3212 KB Output is correct
35 Correct 7 ms 3156 KB Output is correct
36 Correct 7 ms 3216 KB Output is correct