#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#define ll long long
//#define int ll
#define ull unsigned ll
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define chkmin(a,b) (a=min(a,b))
#define chkmax(a,b) (a=max(a,b))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define inf 1010000000
//#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 777771449
#endif
const int mod=1000000007;
const int maxn=5005,maxm=5,maxk=7777714;
//i_am_noob
int n,m,dis[maxn];
vector<array<int,3>> edges;
void orzck(){
cin >> n >> m;
rep(n) edges.pb({i,i+1,1}),edges.pb({i+1,i,0});
rep(n+1) edges.pb({n+1,i,0});
rep(n+2) dis[i]=inf;
rep(m){
int l,r,k,x;
cin >> l >> r >> k >> x;
if(x==0){
edges.pb({l,r+1,r+1-l-k});
}
else{
edges.pb({r+1,l,-(r-l+2-k)});
}
}
dis[n+1]=0;
rep1(_,n+1){
for(auto [u,v,w]: edges) chkmin(dis[v],dis[u]+w);
}
for(auto [u,v,w]: edges) if(dis[v]>dis[u]+w){
cout << "-1\n";
return;
}
rep(n) cout << dis[i+1]-dis[i] << ' ';
cout << "\n";
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
orzck();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
385 ms |
780 KB |
Output is correct |
2 |
Correct |
424 ms |
780 KB |
Output is correct |
3 |
Correct |
402 ms |
780 KB |
Output is correct |
4 |
Correct |
404 ms |
780 KB |
Output is correct |
5 |
Correct |
397 ms |
780 KB |
Output is correct |
6 |
Correct |
400 ms |
780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
385 ms |
780 KB |
Output is correct |
2 |
Correct |
424 ms |
780 KB |
Output is correct |
3 |
Correct |
402 ms |
780 KB |
Output is correct |
4 |
Correct |
404 ms |
780 KB |
Output is correct |
5 |
Correct |
397 ms |
780 KB |
Output is correct |
6 |
Correct |
400 ms |
780 KB |
Output is correct |
7 |
Correct |
420 ms |
780 KB |
Output is correct |
8 |
Correct |
402 ms |
780 KB |
Output is correct |
9 |
Correct |
384 ms |
780 KB |
Output is correct |
10 |
Correct |
410 ms |
780 KB |
Output is correct |
11 |
Correct |
385 ms |
780 KB |
Output is correct |
12 |
Correct |
407 ms |
780 KB |
Output is correct |
13 |
Correct |
394 ms |
780 KB |
Output is correct |
14 |
Correct |
413 ms |
780 KB |
Output is correct |
15 |
Correct |
432 ms |
780 KB |
Output is correct |
16 |
Correct |
407 ms |
780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
385 ms |
780 KB |
Output is correct |
12 |
Correct |
424 ms |
780 KB |
Output is correct |
13 |
Correct |
402 ms |
780 KB |
Output is correct |
14 |
Correct |
404 ms |
780 KB |
Output is correct |
15 |
Correct |
397 ms |
780 KB |
Output is correct |
16 |
Correct |
400 ms |
780 KB |
Output is correct |
17 |
Correct |
420 ms |
780 KB |
Output is correct |
18 |
Correct |
402 ms |
780 KB |
Output is correct |
19 |
Correct |
384 ms |
780 KB |
Output is correct |
20 |
Correct |
410 ms |
780 KB |
Output is correct |
21 |
Correct |
385 ms |
780 KB |
Output is correct |
22 |
Correct |
407 ms |
780 KB |
Output is correct |
23 |
Correct |
394 ms |
780 KB |
Output is correct |
24 |
Correct |
413 ms |
780 KB |
Output is correct |
25 |
Correct |
432 ms |
780 KB |
Output is correct |
26 |
Correct |
407 ms |
780 KB |
Output is correct |
27 |
Correct |
413 ms |
780 KB |
Output is correct |
28 |
Correct |
395 ms |
780 KB |
Output is correct |
29 |
Correct |
418 ms |
780 KB |
Output is correct |
30 |
Correct |
414 ms |
780 KB |
Output is correct |
31 |
Correct |
389 ms |
780 KB |
Output is correct |
32 |
Correct |
411 ms |
780 KB |
Output is correct |
33 |
Correct |
409 ms |
780 KB |
Output is correct |
34 |
Correct |
420 ms |
780 KB |
Output is correct |
35 |
Correct |
408 ms |
780 KB |
Output is correct |
36 |
Correct |
398 ms |
780 KB |
Output is correct |