Submission #272311

# Submission time Handle Problem Language Result Execution time Memory
272311 2020-08-18T11:20:46 Z MrTEK Restore Array (RMI19_restore) Java 11
7 / 100
600 ms 49268 KB
import java.util.*;
public class restore{
	public static class Edge {
		public int u,v,cost;
		public Edge(int _u,int _v,int _cost) {
			u = _u;
			v = _v;
			cost = _cost;
		}
	}
	static int n,m;
	static int[] pre;
	static ArrayList <Edge> edges;
	static boolean SP() {
		pre[0] = 0;
		for (int i = 1 ; i <= n ; i++)
			pre[i] = 1000000000;

		for (int i = 0 ; i < n ; i++) {
			for (Edge j : edges) {
				int val = pre[j.u] + j.cost;
				pre[j.v] = Math.min(val,pre[j.v]);
			}
		}

		for (Edge j : edges) {
			int val = pre[j.u] + j.cost;
			if (pre[j.v] > val)
				return false;
		}

		return true;
	}
	public static void main(String[] args) {
    	Scanner scan = new Scanner(System.in);
    	n = scan.nextInt();
    	m = scan.nextInt();
    	edges = new ArrayList<Edge>();
    	pre = new int[n+1];
    	for (int i = 1 ; i <= n ; i++) {
    		edges.add(new Edge(i-1,i,1));
    		edges.add(new Edge(i,i-1,0));
    	}
    	while((m--) != 0) {
    		int l = scan.nextInt();
    		int r = scan.nextInt();
    		int k = scan.nextInt();
    		int val = scan.nextInt();
    		l++;
    		r++;
    		if (val == 0)
    			edges.add(new Edge(l-1,r,r-l-k+1));
    		else 
    			edges.add(new Edge(r,l-1,-(r-l-k+2)));
    	}
		if (SP() == false)
 			System.out.println("-1");
    	else {
    		for (int i = n ; i >= 1 ; i--)
    			pre[i] -= pre[i - 1];
    		for (int i = 1 ; i <= n ; i++)
    			System.out.printf("%d ",pre[i]);
    		System.out.println();
    	}
    }



}
# Verdict Execution time Memory Grader output
1 Correct 115 ms 11764 KB Output is correct
2 Correct 122 ms 11860 KB Output is correct
3 Correct 187 ms 14572 KB Output is correct
4 Correct 188 ms 14612 KB Output is correct
5 Correct 184 ms 14560 KB Output is correct
6 Correct 171 ms 13960 KB Output is correct
7 Correct 178 ms 14948 KB Output is correct
8 Correct 191 ms 15012 KB Output is correct
9 Correct 184 ms 15200 KB Output is correct
10 Correct 119 ms 11624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 49268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 49268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 115 ms 11764 KB Output is correct
2 Correct 122 ms 11860 KB Output is correct
3 Correct 187 ms 14572 KB Output is correct
4 Correct 188 ms 14612 KB Output is correct
5 Correct 184 ms 14560 KB Output is correct
6 Correct 171 ms 13960 KB Output is correct
7 Correct 178 ms 14948 KB Output is correct
8 Correct 191 ms 15012 KB Output is correct
9 Correct 184 ms 15200 KB Output is correct
10 Correct 119 ms 11624 KB Output is correct
11 Execution timed out 1080 ms 49268 KB Time limit exceeded
12 Halted 0 ms 0 KB -