結果
問題 | No.326 あみだますたー |
ユーザー | kou6839 |
提出日時 | 2015-12-19 22:11:25 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 304 ms / 2,000 ms |
コード長 | 1,164 bytes |
コンパイル時間 | 2,504 ms |
コンパイル使用メモリ | 89,704 KB |
実行使用メモリ | 48,792 KB |
最終ジャッジ日時 | 2024-11-07 23:22:59 |
合計ジャッジ時間 | 10,062 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 26 |
ソースコード
import java.net.NetworkInterface; import java.util.*; public class Main { static long gcd(long a,long b){ return b == 0 ? a : gcd(b, a%b); } static long lcm(long a, long b){ return a*b/gcd(a, b); } static int[] dx = {1,0,-1,0}; static int[] dy = {0,1,0,-1}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] moto = new int[n+1]; int[] ch1 = new int[m]; int[] ch2 = new int[m]; for(int i=0;i<m;i++){ ch1[i] = sc.nextInt(); ch2[i] = sc.nextInt(); } int[] goal = new int[n+1]; for(int i=1;i<=n;i++){ goal[sc.nextInt()] = i; moto[i] = i; } for(int i=0;i<m;i++){ int tmp=moto[ch1[i]]; moto[ch1[i]]=moto[ch2[i]]; moto[ch2[i]]=tmp; } int ans = 0; StringBuilder sb = new StringBuilder(); for(int i=1;i<n;i++){ if(moto[i]==goal[i]){ continue; } int b = 0; for(int j=1;j<=n;j++)if(moto[j]==goal[i]) b = j; for(int j=b;j>i;j--){ int tmp = moto[j]; moto[j]=moto[j-1]; moto[j-1]=tmp; ans++; sb.append(j-1+" "+(j)+"\n"); } } System.out.println(ans); System.out.println(sb); } }