답안 #711591

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711591 2023-03-17T09:27:33 Z Sanzhar23 Restore Array (RMI19_restore) C++14
100 / 100
497 ms 1232 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long	
#define pb push_back
#define bug cout << "bug" << endl
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pll pair <ll, ll> 
#define pii pair <int, int> 
#define triple pair <pair <ll, ll> , ll>   
#define ull unsigned long long
#define ld long double
#define pinode pair <node*, node*>

const ll INF = 9e18 + 5;
const ll inf = 1e9 + 5;
const ll N = 5e3 + 5;
const ll shift = 2e6;
const ll mod = 998244353;
const ll mod2 = 1e9 + 9;
const ll M = 1e3 + 5;
const ll LOG = 21;
const ll sp = 263;
const ll sp2 = 9973;
const int block = 100;
const double eps = 1e-10;

ll n, m, d[N];
vector <array <ll, 3>> vt; 

int main(){
	speed;
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		int l, r, k, val;
		cin >> l >> r >> k >> val;
		l++;
		r++;
//		cout << "OGRANI : " << l << " " << r << " " << k << " " << val << endl;
		ll len = r - l + 1;
		if(val == 0){
			vt.pb({l - 1, r, len - k});
		}else{
			vt.pb({r, l - 1, -(len - k + 1)});
		}
	}
	for(int i = 1; i <= n; i++){	
		vt.pb({i - 1, i, 1});
		vt.pb({i, i - 1, 0});
	}
	for(int i = 0; i <= n; i++){
		vt.pb({n + 1, i, 0});
	}
	for(int i = 0; i <= n + 1; i++){
		d[i] = INF;
	}
	d[n + 1] = 0;
	for(int col = 0; col <= n; col++){
		for(int i = 0; i < vt.size(); i++){
			ll a = vt[i][0], b = vt[i][1], w = vt[i][2];
			if(d[a] < INF){
				if(d[b] > d[a] + w){
					d[b] = max(-INF, d[a] + w);
				}
			}
		}
	}
	bool cycle = false;
	for(int i = 0; i < vt.size(); i++){
		ll a = vt[i][0], b = vt[i][1], w = vt[i][2];
		if(d[a] < INF){
			if(d[b] > d[a] + w){
				cycle = true;
				break;
			}
		}
		if(cycle)
			break;
	}
	if(cycle){
		cout << -1 << endl;
		return 0;
	}
	for(int i = 1; i <= n; i++){
		cout << d[i] - d[i - 1] << " ";
	}
}
/*		
%I64d6


7 7
0 2 1 0
0 6 1 0
0 1 1 0
1 1 1 1
6 6 1 1
3 6 1 1
2 4 1 1



0 1 1 1 1 1 1
		



%I64d
*/ 

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:63:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for(int i = 0; i < vt.size(); i++){
      |                  ~~^~~~~~~~~~~
restore.cpp:73:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for(int i = 0; i < vt.size(); i++){
      |                 ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 1232 KB Output is correct
2 Correct 147 ms 1232 KB Output is correct
3 Correct 141 ms 1232 KB Output is correct
4 Correct 175 ms 1232 KB Output is correct
5 Correct 420 ms 1232 KB Output is correct
6 Correct 497 ms 1232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 1232 KB Output is correct
2 Correct 147 ms 1232 KB Output is correct
3 Correct 141 ms 1232 KB Output is correct
4 Correct 175 ms 1232 KB Output is correct
5 Correct 420 ms 1232 KB Output is correct
6 Correct 497 ms 1232 KB Output is correct
7 Correct 162 ms 1232 KB Output is correct
8 Correct 198 ms 1232 KB Output is correct
9 Correct 140 ms 1232 KB Output is correct
10 Correct 277 ms 1144 KB Output is correct
11 Correct 410 ms 1232 KB Output is correct
12 Correct 440 ms 1232 KB Output is correct
13 Correct 146 ms 1232 KB Output is correct
14 Correct 196 ms 1176 KB Output is correct
15 Correct 160 ms 1232 KB Output is correct
16 Correct 165 ms 1184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 144 ms 1232 KB Output is correct
12 Correct 147 ms 1232 KB Output is correct
13 Correct 141 ms 1232 KB Output is correct
14 Correct 175 ms 1232 KB Output is correct
15 Correct 420 ms 1232 KB Output is correct
16 Correct 497 ms 1232 KB Output is correct
17 Correct 162 ms 1232 KB Output is correct
18 Correct 198 ms 1232 KB Output is correct
19 Correct 140 ms 1232 KB Output is correct
20 Correct 277 ms 1144 KB Output is correct
21 Correct 410 ms 1232 KB Output is correct
22 Correct 440 ms 1232 KB Output is correct
23 Correct 146 ms 1232 KB Output is correct
24 Correct 196 ms 1176 KB Output is correct
25 Correct 160 ms 1232 KB Output is correct
26 Correct 165 ms 1184 KB Output is correct
27 Correct 152 ms 1232 KB Output is correct
28 Correct 132 ms 1232 KB Output is correct
29 Correct 201 ms 1232 KB Output is correct
30 Correct 137 ms 1232 KB Output is correct
31 Correct 249 ms 1232 KB Output is correct
32 Correct 166 ms 1232 KB Output is correct
33 Correct 466 ms 1232 KB Output is correct
34 Correct 419 ms 1232 KB Output is correct
35 Correct 153 ms 1232 KB Output is correct
36 Correct 138 ms 1232 KB Output is correct