답안 #548171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548171 2022-04-12T15:53:05 Z CommandMaster Restore Array (RMI19_restore) C++17
100 / 100
347 ms 936 KB
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll,ll>

int main() {
    ll n, m;
    cin >> n >> m;
    vector<vector<pll>> graph(n+1);
    for (ll i = 0; i < n; i++) graph[i].push_back({i+1, 1}), graph[i+1].push_back({i, 0});
    for (ll i = 0; i < m; i++) {
        ll l, r, k, v;
        cin >> l >> r >> k >> v;
        k--;
        if (v == 1) {
            // cout << l << ' ' << r+1 << ' ' << -((r-l+1)-k) << endl;
            graph[r+1].push_back({l, k-(r-l+1)});
        } else {
            // cout << r+1 << ' ' << l << ' ' << (r-l+1)-k-1 << endl;
            graph[l].push_back({r+1, (r-l+1)-k-1});
        }
    }
    vll dist(n+1, 1e9);
    dist[0] = 0;
    bool changed = true;
    for (ll i = 0; i < 2500; i++) {
        // for (ll j = 0; j < n+1; j++) cout << dist[j] << ' ';
        // cout << endl;
        changed = false;
        for (ll j = 0; j < n+1; j++) {
            for (pll e : graph[j]) {
                if (dist[e.first] > dist[j] + e.second) {
                    changed = true;
                    dist[e.first] = dist[j] + e.second;
                }
            }
        }
        if (!changed) break;
    }
    if (changed) {
        cout << -1 << endl;
        return 0;
    }
    for (ll i = 0; i < n; i++) cout << dist[i+1] - dist[i] << ' ';
    cout << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 816 KB Output is correct
2 Correct 11 ms 800 KB Output is correct
3 Correct 15 ms 812 KB Output is correct
4 Correct 14 ms 848 KB Output is correct
5 Correct 264 ms 880 KB Output is correct
6 Correct 268 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 816 KB Output is correct
2 Correct 11 ms 800 KB Output is correct
3 Correct 15 ms 812 KB Output is correct
4 Correct 14 ms 848 KB Output is correct
5 Correct 264 ms 880 KB Output is correct
6 Correct 268 ms 860 KB Output is correct
7 Correct 15 ms 824 KB Output is correct
8 Correct 15 ms 884 KB Output is correct
9 Correct 13 ms 852 KB Output is correct
10 Correct 15 ms 804 KB Output is correct
11 Correct 347 ms 888 KB Output is correct
12 Correct 340 ms 908 KB Output is correct
13 Correct 17 ms 880 KB Output is correct
14 Correct 13 ms 824 KB Output is correct
15 Correct 15 ms 936 KB Output is correct
16 Correct 92 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 9 ms 816 KB Output is correct
12 Correct 11 ms 800 KB Output is correct
13 Correct 15 ms 812 KB Output is correct
14 Correct 14 ms 848 KB Output is correct
15 Correct 264 ms 880 KB Output is correct
16 Correct 268 ms 860 KB Output is correct
17 Correct 15 ms 824 KB Output is correct
18 Correct 15 ms 884 KB Output is correct
19 Correct 13 ms 852 KB Output is correct
20 Correct 15 ms 804 KB Output is correct
21 Correct 347 ms 888 KB Output is correct
22 Correct 340 ms 908 KB Output is correct
23 Correct 17 ms 880 KB Output is correct
24 Correct 13 ms 824 KB Output is correct
25 Correct 15 ms 936 KB Output is correct
26 Correct 92 ms 924 KB Output is correct
27 Correct 24 ms 860 KB Output is correct
28 Correct 24 ms 868 KB Output is correct
29 Correct 28 ms 920 KB Output is correct
30 Correct 23 ms 924 KB Output is correct
31 Correct 20 ms 888 KB Output is correct
32 Correct 21 ms 884 KB Output is correct
33 Correct 310 ms 912 KB Output is correct
34 Correct 305 ms 908 KB Output is correct
35 Correct 25 ms 928 KB Output is correct
36 Correct 22 ms 844 KB Output is correct