답안 #272299

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
272299 2020-08-18T11:17:26 Z MrTEK Restore Array (RMI19_restore) Java 11
0 / 100
600 ms 48488 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+1)));
    	}
 		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();
    	}
    }



}
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 11772 KB Output is correct
2 Correct 125 ms 11624 KB Output is correct
3 Incorrect 197 ms 15036 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 48488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 48488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 11772 KB Output is correct
2 Correct 125 ms 11624 KB Output is correct
3 Incorrect 197 ms 15036 KB Output isn't correct
4 Halted 0 ms 0 KB -