답안 #1111140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111140 2024-11-11T15:16:50 Z kh0i Restore Array (RMI19_restore) C++17
100 / 100
172 ms 1096 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif

using ll = long long;
using pii = pair<int, int>;

#define F first
#define S second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll get_rand(ll l, ll r) {
    assert(l <= r);
    return uniform_int_distribution<ll> (l, r)(rng);
}

const int N = 5003;

int n, m, d[N];
vector<pii> g[N];

void solve(){
    cin >> n >> m;
    for(int i = 1; i <= n; ++i){
        g[i].emplace_back(i - 1, 0);
        g[i - 1].emplace_back(i, -1);
    }
    for(int i = 1; i <= m; ++i){
        int l, r, k, v;
        cin >> l >> r >> k >> v;
        int len = r - l + 1;
        ++l, ++r;
        if(v)
            g[r].emplace_back(l - 1, len - k + 1);
        else
            g[l - 1].emplace_back(r, k - len);
    }

    memset(d, -0x3f, sizeof(d));
    d[0] = 0;
    for(int iter = 0; iter <= n; ++iter){
        for(int i = n; i >= 0; --i){
            for(auto [v, x] : g[i])
                d[i] = max(d[i], d[v] + x);
        }
    }

    for(int i = 0; i <= n; ++i){
        for(auto [v, x] : g[i]){
            if(d[i] < d[v] + x){
                debug(i, v, x);
                cout << -1;
                return;
            }
        }
    }

    for(int i = 1; i <= n; ++i)
        cout << d[i] - d[i - 1] << " \n"[i == n];
}

int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(0);
    #define task "restore"
    if(fopen(task".in", "r")){
        freopen(task".in", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int test = 1;
//    cin >> test;
    for(int i = 1; i <= test; ++i){
//        cout << "Case #" << i << ": ";
        solve();
    }
    #ifdef LOCAL
        cerr << "\n[Time]: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    #endif
    return 0;
}

Compilation message

restore.cpp: In function 'int32_t main()':
restore.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(task".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
restore.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 848 KB Output is correct
2 Correct 143 ms 1016 KB Output is correct
3 Correct 134 ms 952 KB Output is correct
4 Correct 136 ms 952 KB Output is correct
5 Correct 139 ms 848 KB Output is correct
6 Correct 141 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 848 KB Output is correct
2 Correct 143 ms 1016 KB Output is correct
3 Correct 134 ms 952 KB Output is correct
4 Correct 136 ms 952 KB Output is correct
5 Correct 139 ms 848 KB Output is correct
6 Correct 141 ms 1016 KB Output is correct
7 Correct 142 ms 948 KB Output is correct
8 Correct 162 ms 848 KB Output is correct
9 Correct 144 ms 952 KB Output is correct
10 Correct 146 ms 952 KB Output is correct
11 Correct 139 ms 848 KB Output is correct
12 Correct 132 ms 848 KB Output is correct
13 Correct 136 ms 848 KB Output is correct
14 Correct 153 ms 848 KB Output is correct
15 Correct 147 ms 848 KB Output is correct
16 Correct 156 ms 952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 132 ms 848 KB Output is correct
12 Correct 143 ms 1016 KB Output is correct
13 Correct 134 ms 952 KB Output is correct
14 Correct 136 ms 952 KB Output is correct
15 Correct 139 ms 848 KB Output is correct
16 Correct 141 ms 1016 KB Output is correct
17 Correct 142 ms 948 KB Output is correct
18 Correct 162 ms 848 KB Output is correct
19 Correct 144 ms 952 KB Output is correct
20 Correct 146 ms 952 KB Output is correct
21 Correct 139 ms 848 KB Output is correct
22 Correct 132 ms 848 KB Output is correct
23 Correct 136 ms 848 KB Output is correct
24 Correct 153 ms 848 KB Output is correct
25 Correct 147 ms 848 KB Output is correct
26 Correct 156 ms 952 KB Output is correct
27 Correct 142 ms 848 KB Output is correct
28 Correct 142 ms 848 KB Output is correct
29 Correct 159 ms 1096 KB Output is correct
30 Correct 143 ms 948 KB Output is correct
31 Correct 137 ms 980 KB Output is correct
32 Correct 151 ms 860 KB Output is correct
33 Correct 172 ms 848 KB Output is correct
34 Correct 138 ms 1036 KB Output is correct
35 Correct 138 ms 952 KB Output is correct
36 Correct 147 ms 952 KB Output is correct