結果
| 問題 |
No.326 あみだますたー
|
| コンテスト | |
| ユーザー |
ぴろず
|
| 提出日時 | 2015-12-20 21:26:33 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 387 ms / 2,000 ms |
| コード長 | 950 bytes |
| コンパイル時間 | 2,489 ms |
| コンパイル使用メモリ | 82,248 KB |
| 実行使用メモリ | 48,712 KB |
| 最終ジャッジ日時 | 2024-11-07 23:23:23 |
| 合計ジャッジ時間 | 11,353 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 26 |
ソースコード
package no326;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] p = new int[n];
for(int i=0;i<n;i++) {
p[i] = i + 1;
}
for(int i=0;i<k;i++) {
int x = sc.nextInt() - 1;
int y = sc.nextInt() - 1;
int temp = p[x];
p[x] = p[y];
p[y] = temp;
}
int[] a = new int[n];
for(int i=0;i<n;i++) {
a[i] = sc.nextInt();
}
for(int i=0;i<n;i++) {
p[i] = a[p[i]-1];
}
// System.out.println(Arrays.toString(p));
ArrayList<Integer> ans = new ArrayList<>();
//insertion sort
for(int i=1;i<n;i++) {
for(int j=i-1;j>=0;j--) {
if (p[j] > p[j+1]) {
int temp = p[j];
p[j] = p[j+1];
p[j+1] = temp;
ans.add(j);
}
}
}
System.out.println(ans.size());
for(int x:ans) {
System.out.println((x + 1) + " " + (x + 2));
}
}
}
ぴろず