답안 #847114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
847114 2023-09-09T07:24:10 Z Cookie Restore Array (RMI19_restore) C++14
100 / 100
332 ms 1304 KB
#include<bits/stdc++.h>
#define ll long long
#define vt vector
#define pb push_back
#define pii pair<int, int>
#define sz(v) (int)v.size()
#define fi first
#define se second
using namespace std;
const ll base = 107, mod = 1e9 + 7, mxv = 1e4 + 5, inf = 1e9;
const int mxn = 5e3 + 5, N = 3e6 + 5;
int n, m;
int dis[mxn + 1];
bool vis[mxn + 1];
struct th{
    int u, v, w;
};
vt<th>edge;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int l, r, k, v; cin >> l >> r >> k >> v;
        l++; r++;
        if(v == 1){
            //pref[r] - k >= pref[l - 1]
            k = (r - l + 1) - k + 1;
            edge.pb({r, l - 1, -k});
            //cout << r << " " << l - 1 << " " << -k << "\n";
        }else{
            k = (r - l + 1) - k;
            edge.pb({l - 1, r, k});
           // cout << l - 1 << " " << r << " " << k << "\n";
        }
    }
    for(int i = 1; i <= n; i++){
        edge.pb({i, i - 1, 0});
        edge.pb({i - 1, i, 1});
    }
    for(int i = 1; i <= n; i++)dis[i] = inf;
    dis[0] = 0;
    bool no = 0;
    for(int i = 1; i <= n + 1; i++){
        for(auto [u, v, w]: edge){
            if(dis[v] > dis[u] + w){
                dis[v] = dis[u] + w;
                if(i == n + 1)no = 1;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        if(dis[i] == inf)dis[i] = dis[i - 1];
    }
    if(no)cout << -1 << "\n";
    else{
        for(int i = 1; i <= n; i++)cout << dis[i] - dis[i - 1] << " ";
    }
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:44:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   44 |         for(auto [u, v, w]: edge){
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 792 KB Output is correct
2 Correct 96 ms 1048 KB Output is correct
3 Correct 97 ms 1100 KB Output is correct
4 Correct 93 ms 1052 KB Output is correct
5 Correct 318 ms 1048 KB Output is correct
6 Correct 302 ms 1048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 792 KB Output is correct
2 Correct 96 ms 1048 KB Output is correct
3 Correct 97 ms 1100 KB Output is correct
4 Correct 93 ms 1052 KB Output is correct
5 Correct 318 ms 1048 KB Output is correct
6 Correct 302 ms 1048 KB Output is correct
7 Correct 93 ms 1048 KB Output is correct
8 Correct 96 ms 1048 KB Output is correct
9 Correct 97 ms 1100 KB Output is correct
10 Correct 92 ms 1048 KB Output is correct
11 Correct 309 ms 1048 KB Output is correct
12 Correct 317 ms 1052 KB Output is correct
13 Correct 94 ms 1048 KB Output is correct
14 Correct 95 ms 1304 KB Output is correct
15 Correct 101 ms 1048 KB Output is correct
16 Correct 106 ms 1248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 93 ms 792 KB Output is correct
12 Correct 96 ms 1048 KB Output is correct
13 Correct 97 ms 1100 KB Output is correct
14 Correct 93 ms 1052 KB Output is correct
15 Correct 318 ms 1048 KB Output is correct
16 Correct 302 ms 1048 KB Output is correct
17 Correct 93 ms 1048 KB Output is correct
18 Correct 96 ms 1048 KB Output is correct
19 Correct 97 ms 1100 KB Output is correct
20 Correct 92 ms 1048 KB Output is correct
21 Correct 309 ms 1048 KB Output is correct
22 Correct 317 ms 1052 KB Output is correct
23 Correct 94 ms 1048 KB Output is correct
24 Correct 95 ms 1304 KB Output is correct
25 Correct 101 ms 1048 KB Output is correct
26 Correct 106 ms 1248 KB Output is correct
27 Correct 90 ms 1048 KB Output is correct
28 Correct 93 ms 1048 KB Output is correct
29 Correct 92 ms 1048 KB Output is correct
30 Correct 93 ms 1048 KB Output is correct
31 Correct 94 ms 1100 KB Output is correct
32 Correct 92 ms 1052 KB Output is correct
33 Correct 332 ms 1048 KB Output is correct
34 Correct 313 ms 1108 KB Output is correct
35 Correct 95 ms 1048 KB Output is correct
36 Correct 93 ms 1052 KB Output is correct