結果
| 問題 |
No.326 あみだますたー
|
| ユーザー |
|
| 提出日時 | 2016-05-02 21:10:41 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,237 bytes |
| コンパイル時間 | 2,082 ms |
| コンパイル使用メモリ | 83,364 KB |
| 実行使用メモリ | 61,520 KB |
| 最終ジャッジ日時 | 2024-10-05 02:26:22 |
| 合計ジャッジ時間 | 12,403 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 |
| other | AC * 7 WA * 19 |
ソースコード
package yukicoder;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;
public class Main{
public static void main(String[] args)throws Exception{
new Main().solve();
}
void solve(){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int[] d=new int[n];
for(int i=0;i<n;i++){
d[i]=i;
}
for(int i=0;i<k;i++){
int x=sc.nextInt()-1;
int y=sc.nextInt()-1;
d=Arrays.copyOf(swap(d,x,y), d.length);
}
Queue<Pair> q=new ArrayDeque<Pair>();
for(int i=0;i<n;i++){
int a=sc.nextInt()-1;
if(d[i]==a)continue;
for(int j=i+1;j<n;j++){
if(d[j]==a){
a=j;
break;
}
}
for(int j=a;j>i;j--){
d=Arrays.copyOf(swap(d,j,j-1), d.length);
q.add(new Pair(j-1,j));
}
}
System.out.println(q.size());
while(!q.isEmpty()){
Pair p=q.poll();
System.out.println((p.a+1)+" "+(p.b+1));
}
}
class Pair{
//a<bとする
int a;
int b;
Pair(int a,int b){
if(a>b){
int d=a;
a=b;
b=d;
}
this.a=a;
this.b=b;
}
}
int[] swap(int[] d,int a,int b){
int dumy=d[a];
d[a]=d[b];
d[b]=dumy;
return d;
}
void tr(Object...o){System.out.println(Arrays.deepToString(o));}
}