結果
問題 | No.326 あみだますたー |
ユーザー |
![]() |
提出日時 | 2020-01-29 11:35:46 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 142 ms / 2,000 ms |
コード長 | 1,458 bytes |
コンパイル時間 | 2,200 ms |
コンパイル使用メモリ | 77,324 KB |
実行使用メモリ | 40,664 KB |
最終ジャッジ日時 | 2024-09-16 00:50:20 |
合計ジャッジ時間 | 6,342 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 26 |
ソースコード
import java.util.*;import java.io.*;public class Main {public static void main(String[] args) throws Exception {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));int n = Integer.parseInt(br.readLine());int kk = Integer.parseInt(br.readLine());int[] current = new int[n + 1];for (int i = 1; i <= n; i++) {current[i] = i;}for (int i = 0; i < kk; i++) {String[] line = br.readLine().split(" ", 2);int a = Integer.parseInt(line[0]);int tmp = current[a];current[a] = current[a + 1];current[a + 1] = tmp;}int[] goal = new int[n + 1];String[] last = br.readLine().split(" ", n);for (int i = 1; i <= n; i++) {goal[Integer.parseInt(last[i - 1])] = i;}int count = 0;StringBuilder sb = new StringBuilder();for (int i = 1; i < n; i++) {int right = i;while (current[right] != goal[i]) {right++;}for (int j = right; j - 1 >= i; j--) {count++;int tmp = current[j - 1];current[j - 1] = current[j];current[j] = tmp;sb.append(j - 1).append(" ").append(j).append("\n");}}System.out.println(count);System.out.print(sb);}}