Submission #332205

# Submission time Handle Problem Language Result Execution time Memory
332205 2020-12-01T16:38:41 Z Knps4422 Restore Array (RMI19_restore) C++14
0 / 100
382 ms 1000 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});
		}
	}
	bellman();

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 382 ms 940 KB Output is correct
2 Correct 377 ms 1000 KB Output is correct
3 Correct 375 ms 940 KB Output is correct
4 Incorrect 365 ms 1000 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 382 ms 940 KB Output is correct
2 Correct 377 ms 1000 KB Output is correct
3 Correct 375 ms 940 KB Output is correct
4 Incorrect 365 ms 1000 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -