結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー GrenacheGrenache
提出日時 2016-05-18 21:18:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 216 ms / 5,000 ms
コード長 1,430 bytes
コンパイル時間 3,808 ms
コンパイル使用メモリ 79,544 KB
実行使用メモリ 43,856 KB
最終ジャッジ日時 2024-04-15 22:58:29
合計ジャッジ時間 12,537 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
41,856 KB
testcase_01 AC 203 ms
43,632 KB
testcase_02 AC 201 ms
43,620 KB
testcase_03 AC 156 ms
41,748 KB
testcase_04 AC 146 ms
42,032 KB
testcase_05 AC 205 ms
43,144 KB
testcase_06 AC 161 ms
41,716 KB
testcase_07 AC 189 ms
43,120 KB
testcase_08 AC 191 ms
42,952 KB
testcase_09 AC 185 ms
42,156 KB
testcase_10 AC 190 ms
42,368 KB
testcase_11 AC 192 ms
42,976 KB
testcase_12 AC 192 ms
42,704 KB
testcase_13 AC 210 ms
43,636 KB
testcase_14 AC 197 ms
42,668 KB
testcase_15 AC 195 ms
42,872 KB
testcase_16 AC 204 ms
43,452 KB
testcase_17 AC 202 ms
43,168 KB
testcase_18 AC 197 ms
42,652 KB
testcase_19 AC 201 ms
43,408 KB
testcase_20 AC 191 ms
42,732 KB
testcase_21 AC 190 ms
43,104 KB
testcase_22 AC 194 ms
42,508 KB
testcase_23 AC 204 ms
43,532 KB
testcase_24 AC 188 ms
42,516 KB
testcase_25 AC 207 ms
43,856 KB
testcase_26 AC 211 ms
43,852 KB
testcase_27 AC 216 ms
43,580 KB
testcase_28 AC 200 ms
42,764 KB
testcase_29 AC 209 ms
43,088 KB
testcase_30 AC 203 ms
43,448 KB
testcase_31 AC 204 ms
43,528 KB
testcase_32 AC 200 ms
42,852 KB
testcase_33 AC 207 ms
43,676 KB
testcase_34 AC 130 ms
41,516 KB
testcase_35 AC 132 ms
41,408 KB
testcase_36 AC 136 ms
41,224 KB
testcase_37 AC 151 ms
42,096 KB
testcase_38 AC 156 ms
42,068 KB
testcase_39 AC 155 ms
41,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;


public class Main_yukicoder101 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();

        List<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
        	a.add(i);
        }

        int[] x = new int[k];
        int[] y = new int[k];
        for (int i = 0; i < k; i++) {
        	x[i] = sc.nextInt() - 1;
        	y[i] = sc.nextInt() - 1;

        	int tmp = a.get(x[i]);
        	a.set(x[i], a.get(y[i]));
        	a.set(y[i], tmp);
        }

        List<Integer> b = new ArrayList<>(a);
        for (int i = 0; i < n; i++) {
        	b.set(a.get(i), i);
        }
        long cnt = 1;
        long ret = 1;
        int check = 0;

        for (; true; ) {
        	int j = check;
        	for (; j < n; j++) {
        		if (a.get(j) != j) {
        			break;
        		}
        	}

        	if (j == n) {
        		System.out.println(ret);
        		break;
        	} else if (j > check) {
        		cnt = ret;
                for (int i = 0; i < n; i++) {
                	b.set(a.get(i), i);
                }
                check = j;
        	}

        	List<Integer> c = new ArrayList<>(a);
            for (int i = 0; i < n; i++) {
            	c.set(b.get(i), a.get(i));
            }
            a = c;
            ret += cnt;
        }

        sc.close();
    }
}
0