File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 118
118
- <a href =" https://www.acmicpc.net/problem/18225 " >18225. 당구공을 넣자</a >
119
119
- <a href =" https://www.acmicpc.net/problem/2142 " >2142. 정돈된 배열</a >
120
120
- <a href =" https://www.acmicpc.net/problem/22964 " >22964. conv1d</a >
121
+ - <a href =" https://www.acmicpc.net/problem/14864 " >14864. 줄서기</a >
121
122
</pre >
122
123
</div >
123
124
</details >
Original file line number Diff line number Diff line change
1
+ package math .n14864 ;
2
+
3
+ import java .io .*;
4
+ import java .util .*;
5
+
6
+ public class Main {
7
+ static BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
8
+ static StringTokenizer st ;
9
+ static int N , M ;
10
+
11
+ public static void main (String [] args ) throws Exception {
12
+ st = new StringTokenizer (br .readLine ());
13
+ N = Integer .parseInt (st .nextToken ());
14
+ M = Integer .parseInt (st .nextToken ());
15
+
16
+
17
+ int [] arr = new int [N + 1 ];
18
+ for (int i = 1 ; i <= N ; i ++) arr [i ] = i ;
19
+
20
+ int x , y ;
21
+ for (int i = 0 ; i < M ; i ++) {
22
+ st = new StringTokenizer (br .readLine ());
23
+ x = Integer .parseInt (st .nextToken ());
24
+ y = Integer .parseInt (st .nextToken ());
25
+ arr [x ]++;
26
+ arr [y ]--;
27
+ }
28
+
29
+ boolean [] visited = new boolean [N + 1 ];
30
+ for (int i = 1 ; i <= N ; i ++) {
31
+ if (visited [arr [i ]]) {
32
+ System .out .println (-1 );
33
+ return ;
34
+ }
35
+ visited [arr [i ]] = true ;
36
+ }
37
+
38
+ StringBuilder sb = new StringBuilder ();
39
+ for (int i = 1 ; i <= N ; i ++) sb .append (arr [i ]).append (" " );
40
+
41
+ System .out .println (sb );
42
+ }
43
+ }
You can’t perform that action at this time.
0 commit comments