답안 #332213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332213 2020-12-01T17:08:55 Z Knps4422 Restore Array (RMI19_restore) C++14
100 / 100
394 ms 1072 KB
//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/
#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define forn(x,y) for(int x = 1 ; x <= (int)y ; ++x)
#define all(x) (x).begin(),(x).end()
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
 
using namespace std;
 
typedef long long ll;
typedef unsigned int uint;
typedef pair<ll,ll> pll;
typedef complex<int> point;
const int nmax = 5005;
const ll linf = 1e18;
const ll mod = 998244353;
const int inf = 1e9;
const int sq = 500;


int n, m;
vec < pair < pii , int > > edges;
int dist[nmax];

void bellman(){
	for(int t = 0; t <= n; t++){
		for(auto edge : edges){
			dist[edge.fr.sc] = min(dist[edge.fr.fr] + edge.sc , dist[edge.fr.sc]);
		}
	}
	for(auto edge : edges){
			if(dist[edge.fr.sc] > dist[edge.fr.fr] + edge.sc){
				cout << -1 << '\n';
				return ;
			}
	}
	for(int i = 1; i <= n ; i++){
		cout << dist[i] - dist[i-1] << ' ';
	}
}


int main(){
	cin >> n >> m;
	for(int i = 1; i <= n ; i++){
		dist[i] = inf;
		edges.pb({{i-1,i},1});
		edges.pb({{i,i-1},0});
	}
	for(int i = 1; i <= m ; i++){
		int l , r , k , v;
		cin >> l >> r >> k >> v;
		l++,r++;
		if(v == 0){
			edges.pb({{l-1,r},r-l+1-k});
		}else{
			edges.pb({{r,l-1},l-r+k-2});
		}
	}
	bellman();

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 365 ms 812 KB Output is correct
2 Correct 378 ms 812 KB Output is correct
3 Correct 366 ms 1000 KB Output is correct
4 Correct 365 ms 812 KB Output is correct
5 Correct 366 ms 940 KB Output is correct
6 Correct 384 ms 940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 365 ms 812 KB Output is correct
2 Correct 378 ms 812 KB Output is correct
3 Correct 366 ms 1000 KB Output is correct
4 Correct 365 ms 812 KB Output is correct
5 Correct 366 ms 940 KB Output is correct
6 Correct 384 ms 940 KB Output is correct
7 Correct 374 ms 940 KB Output is correct
8 Correct 375 ms 1020 KB Output is correct
9 Correct 374 ms 940 KB Output is correct
10 Correct 368 ms 1000 KB Output is correct
11 Correct 360 ms 812 KB Output is correct
12 Correct 368 ms 940 KB Output is correct
13 Correct 363 ms 1000 KB Output is correct
14 Correct 383 ms 1000 KB Output is correct
15 Correct 372 ms 940 KB Output is correct
16 Correct 394 ms 1000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 365 ms 812 KB Output is correct
12 Correct 378 ms 812 KB Output is correct
13 Correct 366 ms 1000 KB Output is correct
14 Correct 365 ms 812 KB Output is correct
15 Correct 366 ms 940 KB Output is correct
16 Correct 384 ms 940 KB Output is correct
17 Correct 374 ms 940 KB Output is correct
18 Correct 375 ms 1020 KB Output is correct
19 Correct 374 ms 940 KB Output is correct
20 Correct 368 ms 1000 KB Output is correct
21 Correct 360 ms 812 KB Output is correct
22 Correct 368 ms 940 KB Output is correct
23 Correct 363 ms 1000 KB Output is correct
24 Correct 383 ms 1000 KB Output is correct
25 Correct 372 ms 940 KB Output is correct
26 Correct 394 ms 1000 KB Output is correct
27 Correct 359 ms 1000 KB Output is correct
28 Correct 382 ms 940 KB Output is correct
29 Correct 370 ms 1000 KB Output is correct
30 Correct 354 ms 940 KB Output is correct
31 Correct 361 ms 1000 KB Output is correct
32 Correct 365 ms 1072 KB Output is correct
33 Correct 374 ms 940 KB Output is correct
34 Correct 365 ms 940 KB Output is correct
35 Correct 377 ms 1000 KB Output is correct
36 Correct 365 ms 940 KB Output is correct