답안 #940558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940558 2024-03-07T10:38:11 Z Macker Restore Array (RMI19_restore) C++17
0 / 100
244 ms 1200 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;
}

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(!SSSP(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 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 244 ms 1116 KB Output is correct
2 Correct 234 ms 1200 KB Output is correct
3 Correct 240 ms 1192 KB Output is correct
4 Incorrect 233 ms 1116 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 244 ms 1116 KB Output is correct
2 Correct 234 ms 1200 KB Output is correct
3 Correct 240 ms 1192 KB Output is correct
4 Incorrect 233 ms 1116 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -