답안 #312797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
312797 2020-10-14T11:34:04 Z BeanZ Restore Array (RMI19_restore) C++14
100 / 100
379 ms 1404 KB
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 5005;
struct viet{
    ll u, v, c;
};
ll d[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("A.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) d[i] = i;
    vector<viet> E;
    for (int i = 1; i <= m; i++){
        ll l, r, k, v;
        cin >> l >> r >> k >> v;
        l++;
        r++;
        if (v == 1){
            E.push_back({r, l - 1, -(r - l + 1 - k + 1)});
        } else {
            // S(r) - S(l - 1) <= (r - l + 1 - k)
            E.push_back({l - 1, r, r - l + 1 - k});
        }
    }
    for (int i = 1; i <= n; i++){
        E.push_back({i - 1, i, 1});
        E.push_back({i, i - 1, 0});
    }
    ll x;
    for (int i = 1; i <= n; i++){
        x = -1;
        for (auto j : E){
            if (d[j.v] > (d[j.u] + j.c)){
                d[j.v] = d[j.u] + j.c;
                x = j.v;
            }
        }
    }
    if (x != -1) cout << -1;
    else {
        for (int i = 1; i <= n; i++){
            //cout << d[i] << " ";
            if (d[i] > d[i - 1]) cout << 1 << " ";
            else cout << 0 << " ";
        }
    }
}
/*
*/

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   15 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
restore.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   16 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
restore.cpp:48:5: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |     if (x != -1) cout << -1;
      |     ^~
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 1404 KB Output is correct
2 Correct 166 ms 1404 KB Output is correct
3 Correct 165 ms 1404 KB Output is correct
4 Correct 164 ms 1404 KB Output is correct
5 Correct 341 ms 1404 KB Output is correct
6 Correct 331 ms 1404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 1404 KB Output is correct
2 Correct 166 ms 1404 KB Output is correct
3 Correct 165 ms 1404 KB Output is correct
4 Correct 164 ms 1404 KB Output is correct
5 Correct 341 ms 1404 KB Output is correct
6 Correct 331 ms 1404 KB Output is correct
7 Correct 167 ms 1404 KB Output is correct
8 Correct 168 ms 1404 KB Output is correct
9 Correct 171 ms 1404 KB Output is correct
10 Correct 164 ms 1404 KB Output is correct
11 Correct 372 ms 1404 KB Output is correct
12 Correct 379 ms 1404 KB Output is correct
13 Correct 160 ms 1404 KB Output is correct
14 Correct 175 ms 1404 KB Output is correct
15 Correct 170 ms 1404 KB Output is correct
16 Correct 181 ms 1404 KB Output is correct
# 결과 실행 시간 메모리 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 165 ms 1404 KB Output is correct
12 Correct 166 ms 1404 KB Output is correct
13 Correct 165 ms 1404 KB Output is correct
14 Correct 164 ms 1404 KB Output is correct
15 Correct 341 ms 1404 KB Output is correct
16 Correct 331 ms 1404 KB Output is correct
17 Correct 167 ms 1404 KB Output is correct
18 Correct 168 ms 1404 KB Output is correct
19 Correct 171 ms 1404 KB Output is correct
20 Correct 164 ms 1404 KB Output is correct
21 Correct 372 ms 1404 KB Output is correct
22 Correct 379 ms 1404 KB Output is correct
23 Correct 160 ms 1404 KB Output is correct
24 Correct 175 ms 1404 KB Output is correct
25 Correct 170 ms 1404 KB Output is correct
26 Correct 181 ms 1404 KB Output is correct
27 Correct 164 ms 1404 KB Output is correct
28 Correct 169 ms 1404 KB Output is correct
29 Correct 164 ms 1404 KB Output is correct
30 Correct 172 ms 1404 KB Output is correct
31 Correct 161 ms 1404 KB Output is correct
32 Correct 164 ms 1404 KB Output is correct
33 Correct 354 ms 1404 KB Output is correct
34 Correct 355 ms 1404 KB Output is correct
35 Correct 170 ms 1404 KB Output is correct
36 Correct 168 ms 1404 KB Output is correct