답안 #711475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711475 2023-03-17T04:02:12 Z Nursik Restore Array (RMI19_restore) C++14
100 / 100
306 ms 824 KB
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <functional>
#include <complex>
#include <random>
 
using namespace std;
 
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
 
const ll maxn = 1e4 + 1, maxm = 1e4 + 1;
const ll mod = 1e9 + 7, cmod = 998244353, inf = 1e9, block = 5000, p2 = 31, bit = 30;
const ld eps = 1e-9;

int n, m;
int dp[maxn];
vector<pair<pair<int, int>, int>> edge;
int bellman_ford(){
    for (int i = 0; i <= n; ++i){
        dp[i] = inf;
    }
    int last = -1;
    dp[0] = 0;
    for (int i = 1; i <= n + 1; ++i){
        last = -1;
        for (auto it : edge){
            int x = it.f.f, y = it.f.s, z = it.s;
            if (dp[x] != inf && dp[y] > dp[x] + z){
                dp[y] = dp[x] + z;
                last = i;
            }
        }
    }
    //cout << "ok\n";
    return (last == n + 1);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; ++i){
        int l, r, k, val;
        cin >> l >> r >> k >> val;
        r++;
        k = r - l - k;
        if (val == 1){
            ++k;
            edge.pb(mp(mp(r, l), -k));
         //   cout << r << " " << l << " " << -k << '\n';
        }
        else{
            edge.pb(mp(mp(l, r), k));
        //    cout << l << " " << r << " " << k << '\n';
        }
    }
    for (int i = 1; i <= n; ++i){
        edge.pb(mp(mp(i, i - 1), 0));
   //     cout << i << " " << i - 1 << " " << 0 << '\n';
        edge.pb(mp(mp(i - 1, i), 1));
   //     cout << i - 1 << " " << i << " " << 1 << '\n';
    }
    if (bellman_ford()){
        cout << -1;
        exit(0);
    }
    for (int i = 1; i <= n; ++i){
        cout << dp[i] - dp[i - 1] << " ";
    } 
}
/*
pref[r] - pref[l] >= k
pref[l] - pref[r] <= -k

pref[r] - pref[l] <= k;

p[i - 1] - p[i] <= 0
p[i] - p[i - 1] <= 1
ajj, ajj, ajj, ajj, aj, aj, aj, aj, aj, aj, ak, ak, ak, ak, ak, ai, ai, ai
 */





# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 788 KB Output is correct
2 Correct 91 ms 788 KB Output is correct
3 Correct 88 ms 788 KB Output is correct
4 Correct 92 ms 788 KB Output is correct
5 Correct 294 ms 824 KB Output is correct
6 Correct 270 ms 788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 788 KB Output is correct
2 Correct 91 ms 788 KB Output is correct
3 Correct 88 ms 788 KB Output is correct
4 Correct 92 ms 788 KB Output is correct
5 Correct 294 ms 824 KB Output is correct
6 Correct 270 ms 788 KB Output is correct
7 Correct 103 ms 788 KB Output is correct
8 Correct 98 ms 788 KB Output is correct
9 Correct 94 ms 788 KB Output is correct
10 Correct 88 ms 788 KB Output is correct
11 Correct 306 ms 788 KB Output is correct
12 Correct 303 ms 788 KB Output is correct
13 Correct 91 ms 788 KB Output is correct
14 Correct 94 ms 788 KB Output is correct
15 Correct 98 ms 784 KB Output is correct
16 Correct 105 ms 788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 90 ms 788 KB Output is correct
12 Correct 91 ms 788 KB Output is correct
13 Correct 88 ms 788 KB Output is correct
14 Correct 92 ms 788 KB Output is correct
15 Correct 294 ms 824 KB Output is correct
16 Correct 270 ms 788 KB Output is correct
17 Correct 103 ms 788 KB Output is correct
18 Correct 98 ms 788 KB Output is correct
19 Correct 94 ms 788 KB Output is correct
20 Correct 88 ms 788 KB Output is correct
21 Correct 306 ms 788 KB Output is correct
22 Correct 303 ms 788 KB Output is correct
23 Correct 91 ms 788 KB Output is correct
24 Correct 94 ms 788 KB Output is correct
25 Correct 98 ms 784 KB Output is correct
26 Correct 105 ms 788 KB Output is correct
27 Correct 88 ms 788 KB Output is correct
28 Correct 92 ms 788 KB Output is correct
29 Correct 96 ms 788 KB Output is correct
30 Correct 94 ms 788 KB Output is correct
31 Correct 88 ms 788 KB Output is correct
32 Correct 87 ms 788 KB Output is correct
33 Correct 287 ms 788 KB Output is correct
34 Correct 291 ms 788 KB Output is correct
35 Correct 89 ms 788 KB Output is correct
36 Correct 120 ms 788 KB Output is correct