답안 #341555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341555 2020-12-30T01:13:10 Z Gajowy Restore Array (RMI19_restore) C++14
100 / 100
386 ms 1132 KB
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define mp make_pair
#define e1 first
#define e2 second

const int MAXN=5e3+10;
const int inf=1e9+2137;

vector<pair<int,int>> g[MAXN];

int d[MAXN];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		d[i]=inf;
		g[i-1].eb(mp(i,1));
		g[i].eb(mp(i-1,0));
	}
	while(m--){
		int l,r,k,v;
		cin>>l>>r>>k>>v;
		l++,r++;
		if(v==0){
			g[l-1].eb(mp(r,r-l+1-k));
		}
		else{
			g[r].eb(mp(l-1,-r+l-2+k));
		}
	}
	int lastRelax=0;
	for(int i=0;i<=n;i++){
		for(int u=0;u<=n;u++)
			for(auto v:g[u])
				if(d[u]+v.e2<d[v.e1]){
					d[v.e1]=d[u]+v.e2,lastRelax=i;
					if(d[v.e1]<0){
						cout<<"-1\n";
						return 0;
					}
				}
	}
	if(lastRelax==n){
		cout<<"-1\n";
		return 0;
	}
	else{
		for(int i=1;i<=n;i++)
			cout<<(d[i]-d[i-1])<<' ';
		cout<<'\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 347 ms 1024 KB Output is correct
2 Correct 344 ms 876 KB Output is correct
3 Correct 348 ms 876 KB Output is correct
4 Correct 350 ms 1044 KB Output is correct
5 Correct 5 ms 1004 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 347 ms 1024 KB Output is correct
2 Correct 344 ms 876 KB Output is correct
3 Correct 348 ms 876 KB Output is correct
4 Correct 350 ms 1044 KB Output is correct
5 Correct 5 ms 1004 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 373 ms 1004 KB Output is correct
8 Correct 373 ms 1004 KB Output is correct
9 Correct 375 ms 1132 KB Output is correct
10 Correct 381 ms 1028 KB Output is correct
11 Correct 5 ms 992 KB Output is correct
12 Correct 5 ms 1004 KB Output is correct
13 Correct 369 ms 1004 KB Output is correct
14 Correct 373 ms 1040 KB Output is correct
15 Correct 377 ms 1036 KB Output is correct
16 Correct 386 ms 1036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 347 ms 1024 KB Output is correct
12 Correct 344 ms 876 KB Output is correct
13 Correct 348 ms 876 KB Output is correct
14 Correct 350 ms 1044 KB Output is correct
15 Correct 5 ms 1004 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 373 ms 1004 KB Output is correct
18 Correct 373 ms 1004 KB Output is correct
19 Correct 375 ms 1132 KB Output is correct
20 Correct 381 ms 1028 KB Output is correct
21 Correct 5 ms 992 KB Output is correct
22 Correct 5 ms 1004 KB Output is correct
23 Correct 369 ms 1004 KB Output is correct
24 Correct 373 ms 1040 KB Output is correct
25 Correct 377 ms 1036 KB Output is correct
26 Correct 386 ms 1036 KB Output is correct
27 Correct 365 ms 1064 KB Output is correct
28 Correct 378 ms 1004 KB Output is correct
29 Correct 364 ms 1004 KB Output is correct
30 Correct 378 ms 1044 KB Output is correct
31 Correct 358 ms 1004 KB Output is correct
32 Correct 368 ms 1040 KB Output is correct
33 Correct 6 ms 1004 KB Output is correct
34 Correct 5 ms 1004 KB Output is correct
35 Correct 374 ms 1004 KB Output is correct
36 Correct 379 ms 1004 KB Output is correct