#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
signed main() {
int n, m;
cin >> n >> m;
vector<array<int, 3> > edges;
for(int i=0; i<m; i++) {
int l, r, k, val;
cin >> l >> r >> k >> val; l++; r++;
if(val == 0) {
//ako k-ti element e 0, togas sigurno prvite k elemnti se 0
//pref[r] - pref[l-1] <= (r - l + 1) - k (ako site drugi se 1)
edges.push_back({ l - 1, r, r - l + 1 - k});
} else {
//ako k-ti element e 1, togas sigurno narednite elementi se 1
// pref[r] - pref[l-1] >= (r - l + 1) - k - 1 = r - l - k
// pref[l-1] - pref[r] <= l + k - r
edges.push_back({ r, l - 1, l + k - r });
}
}
//pref[i+1] - pref[i] <= 1
//pref[i+1] - pref[i] >= 0
//pref[i] - pref[i+1] <= 0
for(int i=1; i<n; i++) edges.push_back({ i, i + 1, 1 });
for(int i=2; i<=n; i++) edges.push_back({ i + 1, 1, 0 });
vector<ll> dist(n+1, 1e18); dist[1] = 0;
for(int i=1; i<n; i++)
for(auto &[u, v, w] : edges) dist[v] = min(dist[v], dist[u] + w);
for(auto &[u, v, w] : edges) {
if(dist[v] > dist[u] + w) {
cout << -1 << '\n';
return 0;
}
}
vector<int> ans(n+1);
for(int i=2; i<=n; i++) {
if(dist[i+1] > dist[i]) ans[i] = 1;
else ans[i] = 0;
}
for(int i=1; i<=n; i++) cout << ans[i] << " ";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
105 ms |
1052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
105 ms |
1052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |