답안 #272853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
272853 2020-08-18T16:45:04 Z egekabas Restore Array (RMI19_restore) C++14
100 / 100
597 ms 1092 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int n, m;
vector<pair<int, pii>> edges;
int dis[5009];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    cin >> n >> m;
    while(m--){
        int l, r, k, val;
        cin >> l >> r >> k >> val;
        ++l;++r;

        if(val == 1)
            edges.pb({k-1, {l-1, r}});
        else
            edges.pb({-k, {r, l-1}});
    
    }
    for(int i = 1; i <= n; ++i){
        edges.pb({1, {i-1, i}});
        edges.pb({0, {i, i-1}});
        dis[i] = 1e9;
    }
    int cnt = 0;
    while(1){
        if(cnt > n+5){
            cout << "-1\n";
            return 0;
        }
        ++cnt;
        int br = 1;
        for(auto u : edges)
            if(dis[u.ss.ss] > dis[u.ss.ff]+u.ff){
                dis[u.ss.ss] = dis[u.ss.ff]+u.ff;
                br = 0;
            }
        if(br) break;
    }
    for(int i = 1; i <= n; ++i)
        cout << ((dis[i]-dis[i-1])^1) << ' ';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 960 KB Output is correct
2 Correct 4 ms 960 KB Output is correct
3 Correct 4 ms 960 KB Output is correct
4 Correct 6 ms 960 KB Output is correct
5 Correct 597 ms 960 KB Output is correct
6 Correct 555 ms 960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 960 KB Output is correct
2 Correct 4 ms 960 KB Output is correct
3 Correct 4 ms 960 KB Output is correct
4 Correct 6 ms 960 KB Output is correct
5 Correct 597 ms 960 KB Output is correct
6 Correct 555 ms 960 KB Output is correct
7 Correct 7 ms 960 KB Output is correct
8 Correct 7 ms 1088 KB Output is correct
9 Correct 7 ms 960 KB Output is correct
10 Correct 8 ms 960 KB Output is correct
11 Correct 349 ms 960 KB Output is correct
12 Correct 329 ms 1088 KB Output is correct
13 Correct 7 ms 960 KB Output is correct
14 Correct 30 ms 1088 KB Output is correct
15 Correct 38 ms 960 KB Output is correct
16 Correct 20 ms 1092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 4 ms 960 KB Output is correct
12 Correct 4 ms 960 KB Output is correct
13 Correct 4 ms 960 KB Output is correct
14 Correct 6 ms 960 KB Output is correct
15 Correct 597 ms 960 KB Output is correct
16 Correct 555 ms 960 KB Output is correct
17 Correct 7 ms 960 KB Output is correct
18 Correct 7 ms 1088 KB Output is correct
19 Correct 7 ms 960 KB Output is correct
20 Correct 8 ms 960 KB Output is correct
21 Correct 349 ms 960 KB Output is correct
22 Correct 329 ms 1088 KB Output is correct
23 Correct 7 ms 960 KB Output is correct
24 Correct 30 ms 1088 KB Output is correct
25 Correct 38 ms 960 KB Output is correct
26 Correct 20 ms 1092 KB Output is correct
27 Correct 10 ms 960 KB Output is correct
28 Correct 6 ms 1088 KB Output is correct
29 Correct 6 ms 960 KB Output is correct
30 Correct 6 ms 1088 KB Output is correct
31 Correct 7 ms 960 KB Output is correct
32 Correct 11 ms 1088 KB Output is correct
33 Correct 411 ms 1088 KB Output is correct
34 Correct 381 ms 1088 KB Output is correct
35 Correct 9 ms 1088 KB Output is correct
36 Correct 11 ms 1088 KB Output is correct