제출 #272870

#제출 시각아이디문제언어결과실행 시간메모리
272870Atill83Restore Array (RMI19_restore)C++14
7 / 100
632 ms960 KiB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, m;
vector<pair<int, pii>> ed;
ll d[MAXN];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    cin>>n>>m;

    for(int i = 0; i <= n; i++) d[i] = mod;
    for(int i = 0; i < m; i++){
        int l, r, k, val;
        cin>>l>>r>>k>>val;
        l++;r++;
        if(val == 0){
            ed.push_back({-k, {r, l - 1}});
        }else{
            ed.push_back({k - 1, {l - 1, r}});
        }
    }

    for(int i = 0; i < n; i++){
        ed.push_back({0, {i + 1, i}});
        ed.push_back({1, {i, i + 1}});
    }
    d[0] = 0;
    bool done;
    for(int i = 0; i <= n; i++){

        done = 0;

        for(auto j: ed){
            if(d[j.ss.ff] < mod){
                if(d[j.ss.ss] > d[j.ss.ff] + j.ff){
                    done = 1;
                    d[j.ss.ss] = d[j.ss.ff] + j.ff;
                }
            }
        }
    }

    if(done){
        cout<<-1<<endl;
        return 0;
    }

    for(int i = 0; i < n; i++){
        cout<<((d[i + 1] - d[i]) ^ 1)<<" ";

    }


    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

컴파일 시 표준 에러 (stderr) 메시지

restore.cpp: In function 'int main()':
restore.cpp:60:5: warning: 'done' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |     if(done){
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...