답안 #940564

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940564 2024-03-07T10:43:47 Z Macker Restore Array (RMI19_restore) C++17
0 / 100
11 ms 1236 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef pair<int, int> pii;
#define all(v) v.begin(), v.end()
#define FOR(i, n) for (int i = 0; i < n; i++)
#define inf LLONG_MAX/2
#define fi first
#define se second

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")

vector<vector<pii>> adj;
vector<int> dist;
int n;

/*
bool SSSP(int s){
    dist.assign(n, inf);
    dist[s] = 0;
    int upd = -1;
    FOR(it, n){
        upd = -1;
        FOR(a, n) for (auto &[b, c] : adj[a]) {
            if(dist[a] == inf) continue;
            if(dist[b] > dist[a] + c){
                dist[b] = dist[a] + c;
                upd = b;
            }
        }
    }
    if(upd != -1) return false;
    else return true;
}
*/

bool spfa(int s) {  /// Shortest Path Faster Algorithm
    vector<bool> inq(n);
    vector<int> cnt(n);
    dist.resize(n);
    for(int i=0; i<n; i++) {
        dist[i] = inf;
        cnt[i] = 0; inq[i] = 0;
    }
    queue<int> q;

    dist[s] = 0;
    q.push(s); inq[s] = 1;
    while (!q.empty()) {
        int v = q.front();
        q.pop(); inq[v] = 0;

        for(auto e : adj[v]) {
            int u = e.fi, w = e.se;
            if(dist[v] + w < dist[u]) {
                dist[u] = dist[v] + w;
                if(dist[u] < 0 ) return false; /// optimization for TLE.
                if(!inq[u]) {
                    q.push(u); inq[u] = 1;
                    cnt[u]++;
                    if(cnt[u]>n) return false;
                }
            }
        }
    }

    return true;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int m; cin >> n >> m;
    adj.resize(n + 2);
    FOR(i, m){
        int l, r, k, val; cin >> l >> r >> k >> val; r++;
        if(val == 0){
            adj[l].push_back({r, (r - l) - k});
        }
        else{
            adj[r].push_back({l, k - r + l + 1});
        }
    }
    FOR(i, n){
        adj[i].push_back({i + 1, 1});
        adj[i + 1].push_back({i, 0});
    }
    n++;
    if(!spfa(0)){
        cout << -1 << endl;
    }
    else{
        FOR(i, n-1){
            if(dist[i] < dist[i + 1]) cout << 1;
            else cout << 0;
            cout << " \n"[i == n - 2];
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 456 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1112 KB Output is correct
2 Correct 11 ms 1152 KB Output is correct
3 Correct 10 ms 1108 KB Output is correct
4 Incorrect 9 ms 1236 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1112 KB Output is correct
2 Correct 11 ms 1152 KB Output is correct
3 Correct 10 ms 1108 KB Output is correct
4 Incorrect 9 ms 1236 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 456 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -