結果
問題 | No.326 あみだますたー |
ユーザー |
![]() |
提出日時 | 2016-05-10 18:50:50 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 142 ms / 2,000 ms |
コード長 | 1,758 bytes |
コンパイル時間 | 2,060 ms |
コンパイル使用メモリ | 77,828 KB |
実行使用メモリ | 41,004 KB |
最終ジャッジ日時 | 2024-11-08 00:16:49 |
合計ジャッジ時間 | 5,830 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 26 |
ソースコード
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int k = Integer.parseInt(br.readLine()); int l = Integer.parseInt(br.readLine()); String[] lines; ArrayList<Pair> pairs = new ArrayList<Pair>(); for(int i=0;i<l;i++){ lines = br.readLine().split(" "); pairs.add(new Pair(Integer.parseInt(lines[0])-1,Integer.parseInt(lines[1])-1)); } lines = br.readLine().split(" "); for(Pair pair:pairs){ String tmp = lines[pair.a]; lines[pair.a] = lines[pair.b]; lines[pair.b] = tmp; } int[] nlines = new int[k]; int i=0; for(String st:lines){ nlines[i++] = Integer.parseInt(st); } int cnt = 0; StringBuilder ans = new StringBuilder(); for(i=0;i<k-1;i++){ if(nlines[i] > nlines[i+1]){ ans.append(i+1).append(" ").append(i+2).append("\n"); int tmp = nlines[i]; nlines[i] = nlines[i+1]; nlines[i+1] = tmp; i=-1; cnt++; } } System.out.println(cnt); System.out.println(ans); } public static class Pair{ public int a; public int b; public Pair(int a,int b){ this.a = a; this.b = b; } } }