結果

問題 No.397 NO MORE KADOMATSU
ユーザー 37zigen37zigen
提出日時 2016-07-15 23:16:35
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,321 bytes
コンパイル時間 2,750 ms
コンパイル使用メモリ 79,796 KB
実行使用メモリ 87,896 KB
最終ジャッジ日時 2023-09-24 00:16:49
合計ジャッジ時間 8,710 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package No300台;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solver();
	}

	static int[] A;
	static ArrayList<Swap> s = new ArrayList<>();

	static void solver() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		A = new int[n];
		for (int i = 0; i < n; i++) {
			A[i] = sc.nextInt();
		}
		quicksort(0, A.length - 1);

		int dummy = sc.nextInt();
		System.out.println(s.size());
		for (int i = 0; i < s.size(); i++) {
			Swap d = s.get(i);
			System.out.println(d.x + " " + d.y);
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	static int partition(int p, int r) {
		int x = A[r];
		int i = p - 1;
		for (int j = p; j < r; j++) {
			if (A[j] <= x) {
				i++;
				int d = A[i];
				A[i] = A[j];
				A[j] = d;
				if (i != j) {
					s.add(new Swap(i, j));
				}
			}
		}
		int d = A[i + 1];
		A[i + 1] = A[r];
		A[r] = d;
		if (i + 1 != r) {
			s.add(new Swap(i + 1, r));
		}
		return i + 1;
	}

	static void quicksort(int p, int r) {
		int q = partition(p, r);
		if (p < q - 1)
			quicksort(p, q - 1);
		if (q + 1 < r)
			quicksort(q + 1, r);
	}

	static class Swap {
		int x;
		int y;

		Swap(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}
}
0