結果

問題 No.326 あみだますたー
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-12-03 05:12:32
言語 Java21
(openjdk 21)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,226 bytes
コンパイル時間 4,560 ms
コンパイル使用メモリ 76,776 KB
実行使用メモリ 64,892 KB
最終ジャッジ日時 2023-08-18 12:46:10
合計ジャッジ時間 11,930 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,876 KB
testcase_01 AC 159 ms
57,052 KB
testcase_02 AC 223 ms
57,504 KB
testcase_03 AC 389 ms
63,368 KB
testcase_04 AC 292 ms
57,856 KB
testcase_05 AC 134 ms
55,800 KB
testcase_06 AC 300 ms
61,612 KB
testcase_07 AC 203 ms
59,272 KB
testcase_08 AC 277 ms
57,272 KB
testcase_09 MLE -
testcase_10 AC 368 ms
61,708 KB
testcase_11 AC 176 ms
57,104 KB
testcase_12 AC 349 ms
60,992 KB
testcase_13 AC 343 ms
62,036 KB
testcase_14 AC 258 ms
61,084 KB
testcase_15 AC 278 ms
61,596 KB
testcase_16 AC 265 ms
61,252 KB
testcase_17 AC 320 ms
60,728 KB
testcase_18 AC 293 ms
61,656 KB
testcase_19 AC 303 ms
61,256 KB
testcase_20 AC 157 ms
56,696 KB
testcase_21 AC 157 ms
56,860 KB
testcase_22 AC 335 ms
61,156 KB
testcase_23 AC 361 ms
61,536 KB
testcase_24 AC 348 ms
61,696 KB
testcase_25 AC 345 ms
61,384 KB
testcase_26 AC 240 ms
60,228 KB
testcase_27 AC 342 ms
62,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] now = new int [N+1];
        for(int i=1; i<=N; i++){
            now[i]=i;
        }
        int K = sc.nextInt();
        for(int i=0; i<K; i++){
            int X = sc.nextInt();
            int Y = sc.nextInt();
            int j=1;
            int k=1;
            for(; j<=N; j++){
                if(X==now[j]){
                    break;
                }
            }
            for(;k<=N; k++){
                if(Y==now[k]){
                    break;
                }
            }
            now[j]=Y;
            now[k]=X;
        }
        
        int [] fin = new int [N+1];
        for(int i=1; i<=N; i++){
            fin[i] = sc.nextInt();
        }
        List<String> list = new ArrayList<String>();
        while(true){
            int count=0;
            for(int i=1; i<=N; i++){
                if(now[i]<fin[i]){
                    while(now[i]!=fin[i]){
                        String s = now[i]+" "+(now[i]+1);
                        list.add(s);
                        for(int j=1; j<=N; j++){
                            if(now[i]+1==now[j]){
                                now[i]++;
                                now[j]--;
                                break;
                            }
                        }
                    }
                }else if(now[i]>fin[i]){
                    while(now[i]!=fin[i]){
                        String s = (now[i]-1)+" "+now[i];
                        list.add(s);
                        for(int j=1; j<=N; j++){
                            if(now[i]-1==now[j]){
                                now[i]--;
                                now[j]++;
                                break;
                            }
                        }
                    }
                }else{
                    count++;
                }
            }
            if(count==N){break;}
        }
        
        int l=list.size();
        System.out.println(l);
        for(int i=0; i<l; i++){
            System.out.println(list.get(i));
        }
    }
}
0