Submission #493860

#TimeUsernameProblemLanguageResultExecution timeMemory
493860AlexandruabcdeRestore Array (RMI19_restore)C++14
20 / 100
1054 ms968 KiB
#include <bits/stdc++.h> using namespace std; constexpr int INF = 1000000000; constexpr int NMAX = 5005; typedef pair <int, int> PII; int N, M; vector <PII> G[NMAX]; int sp[NMAX]; void Read () { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M; for (int i = 1; i <= M; ++ i ) { int L, R, K, Val; cin >> L >> R >> K >> Val; ++ L; ++ R; int Lg = R - L + 1; if (Val == 0) { G[L-1].push_back({Lg-K, R}); } else G[R].push_back({-Lg+K-1, L-1}); } for (int i = 0; i <= N; ++ i ) sp[i] = INF; for (int i = 1; i <= N; ++ i ) { int L = i, R = i; int K = 1, Lg = 1; G[R].push_back({0, L-1}); G[L-1].push_back({1, R}); } } bool InQueue[NMAX]; int length[NMAX]; bool sol; void BFS () { queue <int> Q; Q.push(0); InQueue[0] = 1; sp[0] = 0; length[0] = 1; while (!Q.empty()) { int nod = Q.front(); Q.pop(); InQueue[nod] = 0; for (auto it : G[nod]) { int to = it.second; int cost = it.first; if (sp[nod] + cost < sp[to]) { sp[to] = sp[nod] + cost; length[to] = length[nod] + 1; if (length[to] > N) { cout << -1 << '\n'; return; } if (!InQueue[to]) { Q.push(to); InQueue[to] = 1; } } } } for (int i = 1; i <= N; ++ i ) cout << sp[i] - sp[i-1] << " "; } int main () { Read(); BFS(); }

Compilation message (stderr)

restore.cpp: In function 'void Read()':
restore.cpp:40:13: warning: unused variable 'K' [-Wunused-variable]
   40 |         int K = 1, Lg = 1;
      |             ^
restore.cpp:40:20: warning: unused variable 'Lg' [-Wunused-variable]
   40 |         int K = 1, Lg = 1;
      |                    ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...