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] = Integer.MAX_VALUE;
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 |
131 ms |
12424 KB |
Output is correct |
2 |
Correct |
125 ms |
11524 KB |
Output is correct |
3 |
Incorrect |
174 ms |
14816 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1008 ms |
47836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1008 ms |
47836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
12424 KB |
Output is correct |
2 |
Correct |
125 ms |
11524 KB |
Output is correct |
3 |
Incorrect |
174 ms |
14816 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |