結果

問題 No.326 あみだますたー
ユーザー yun_appyun_app
提出日時 2016-05-10 18:50:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 1,758 bytes
コンパイル時間 2,619 ms
コンパイル使用メモリ 77,884 KB
実行使用メモリ 41,140 KB
最終ジャッジ日時 2024-04-25 12:48:16
合計ジャッジ時間 6,348 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
36,560 KB
testcase_01 AC 46 ms
37,020 KB
testcase_02 AC 49 ms
37,044 KB
testcase_03 AC 136 ms
41,140 KB
testcase_04 AC 55 ms
36,964 KB
testcase_05 AC 47 ms
36,792 KB
testcase_06 AC 117 ms
39,768 KB
testcase_07 AC 82 ms
38,196 KB
testcase_08 AC 73 ms
38,244 KB
testcase_09 AC 142 ms
40,796 KB
testcase_10 AC 136 ms
40,208 KB
testcase_11 AC 47 ms
36,540 KB
testcase_12 AC 107 ms
39,356 KB
testcase_13 AC 124 ms
40,268 KB
testcase_14 AC 59 ms
37,360 KB
testcase_15 AC 105 ms
39,428 KB
testcase_16 AC 107 ms
40,492 KB
testcase_17 AC 86 ms
38,284 KB
testcase_18 AC 90 ms
38,692 KB
testcase_19 AC 112 ms
40,364 KB
testcase_20 AC 46 ms
36,900 KB
testcase_21 AC 47 ms
36,792 KB
testcase_22 AC 111 ms
39,988 KB
testcase_23 AC 114 ms
39,332 KB
testcase_24 AC 132 ms
41,024 KB
testcase_25 AC 134 ms
40,128 KB
testcase_26 AC 66 ms
37,800 KB
testcase_27 AC 111 ms
39,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* 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;
        }
    }
}
0