結果
問題 | No.1650 Moving Coins |
ユーザー | tenten |
提出日時 | 2021-08-23 14:40:09 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 515 ms / 2,000 ms |
コード長 | 2,011 bytes |
コンパイル時間 | 2,240 ms |
コンパイル使用メモリ | 78,624 KB |
実行使用メモリ | 57,472 KB |
最終ジャッジ日時 | 2024-04-25 06:49:44 |
合計ジャッジ時間 | 14,819 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
37,160 KB |
testcase_01 | AC | 52 ms
36,908 KB |
testcase_02 | AC | 51 ms
36,800 KB |
testcase_03 | AC | 141 ms
43,092 KB |
testcase_04 | AC | 114 ms
40,216 KB |
testcase_05 | AC | 138 ms
41,976 KB |
testcase_06 | AC | 141 ms
42,368 KB |
testcase_07 | AC | 136 ms
43,284 KB |
testcase_08 | AC | 373 ms
51,040 KB |
testcase_09 | AC | 382 ms
52,444 KB |
testcase_10 | AC | 380 ms
51,428 KB |
testcase_11 | AC | 367 ms
53,968 KB |
testcase_12 | AC | 322 ms
49,016 KB |
testcase_13 | AC | 312 ms
49,804 KB |
testcase_14 | AC | 341 ms
51,708 KB |
testcase_15 | AC | 311 ms
48,664 KB |
testcase_16 | AC | 404 ms
54,440 KB |
testcase_17 | AC | 366 ms
51,972 KB |
testcase_18 | AC | 394 ms
53,576 KB |
testcase_19 | AC | 515 ms
57,472 KB |
testcase_20 | AC | 410 ms
53,532 KB |
testcase_21 | AC | 455 ms
54,996 KB |
testcase_22 | AC | 436 ms
54,108 KB |
testcase_23 | AC | 508 ms
56,340 KB |
testcase_24 | AC | 138 ms
41,776 KB |
testcase_25 | AC | 139 ms
41,736 KB |
testcase_26 | AC | 324 ms
52,200 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] org = new int[n]; for (int i = 0; i < n; i++) { org[i] = sc.nextInt(); } int[] next = new int[n]; int count = 0; for (int i = 0; i < n; i++) { next[i] = sc.nextInt(); count += Math.abs(org[i] - next[i]); } StringBuilder sb = new StringBuilder(); ArrayDeque<Integer> stack = new ArrayDeque<>(); for (int i = 0; i < n; i++) { if (org[i] < next[i] && i < n - 1 && org[i + 1] <= next[i]) { stack.push(i); } else { move(i + 1, org[i], next[i], sb); while (stack.size() > 0) { int idx = stack.pop(); move(idx + 1, org[idx], next[idx], sb); } } } System.out.println(count); System.out.print(sb); } static void move(int stone, int from, int to, StringBuilder sb) { if (from > to) { for (int i = 0; i < from - to; i++) { sb.append(stone).append(" L\n"); } } else { for (int i = 0; i < to - from; i++) { sb.append(stone).append(" R\n"); } } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }