-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOneLine.java
More file actions
61 lines (54 loc) · 1.69 KB
/
Copy pathOneLine.java
File metadata and controls
61 lines (54 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package algorithm.baek.etc;
import algorithm.TestCase;
import java.io.*;
import java.text.ParseException;
import java.util.StringTokenizer;
/**
* https://www.acmicpc.net/problem/1138
* 한 줄로 서기
*/
public class OneLine implements TestCase {
static int remain;
@Override
public void test() throws ParseException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int n = Integer.parseInt(br.readLine());
remain = n;
int[] arr = new int[n];
st = new StringTokenizer(br.readLine());
int startIdx = Integer.MAX_VALUE;
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
if (arr[i] == 0) {
startIdx = Math.min(startIdx, i);
}
}
bw.write(startIdx + 1 + " ");
decrease(arr, startIdx);
while (true) {
lining(n, arr, bw);
if (remain == 0) break;
}
bw.flush();
bw.close();
}
private static void lining(int n, int[] arr, BufferedWriter bw) throws IOException {
for (int i = 0; i < n; i++) {
if (arr[i] == 0) {
bw.write(i + 1 + " ");
decrease(arr, i);
break;
}
}
}
public static void decrease(int[] arr, int startIdx) {
for (int i = 0; i < startIdx; i++) {
if (arr[i] >= 0)
arr[i]--;
}
remain--;
arr[startIdx] = -1;
}
}