提出 #214546


ソースコード 拡げる

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int d = sc.nextInt();
		int[] a = new int[m];
		for(int i=0;i<m;i++) {
			a[i] = sc.nextInt()-1;
		}
		int[] f = new int[n];
		for(int i=0;i<n;i++) {
			f[i] = i;
		}
		for(int i=m-1;i>=0;i--) {
			int temp = f[a[i]];
			f[a[i]] = f[a[i]+1];
			f[a[i]+1] = temp;
		}
		//System.out.println(Arrays.toString(f));
		int[] ans = new int[n];
		boolean[] used = new boolean[n];
		int[] t = new int[n];
		Arrays.fill(t, -1);
		for(int i=0;i<n;i++) {
			if (used[i]) {
				continue;
			}
			ArrayList<Integer> path = new ArrayList<>();
			int now = i;
			int cycle = -1;
			for(int time=0;time<=n;time++) {
				if (t[now] != -1) {
					cycle = time-t[now];
					break;
				}else{
					path.add(now);
					used[now] = true;
					t[now] = time;
				}
				now = f[now];
			}
			//System.out.println(path);
			//System.out.println(cycle);
			for(int j=0;j<path.size();j++) {
				if (j + d >= path.size()) {
					ans[path.get(j)] = path.get((j+d)%cycle);
				}else{
					ans[path.get(j)] = path.get(j+d);
				}
			}
		}
		for(int i=0;i<n;i++) {
			System.out.println(ans[i]+1);
		}
	}

}

提出情報

提出日時
問題 D - 阿弥陀
ユーザ piroz95
言語 Java (OpenJDK 1.7.0)
得点 100
コード長 1370 Byte
結果 AC
実行時間 2165 ms
メモリ 41464 KB

ジャッジ結果

セット名 Subtask1 Subtask2 Subtask3 Subtask4
得点 / 配点 10 / 10 20 / 20 20 / 20 50 / 50
結果
AC × 9
AC × 18
AC × 18
AC × 29
セット名 テストケース
Subtask1 sample_1.txt, 01_i.txt, 01_random01.txt, 01_random02.txt, 01_random03.txt, 01_random04.txt, 01_random05.txt, 01_random06.txt, 01_random07.txt
Subtask2 sample_1.txt, sample_2.txt, sample_3.txt, 02_i.txt, 02_p.txt, 02_random01.txt, 02_random02.txt, 02_random03.txt, 02_random04.txt, 02_random05.txt, 02_random06.txt, 02_random07.txt, 02_random08.txt, 02_rp01.txt, 02_rp02.txt, 02_rp03.txt, 02_rp04.txt, 02_rp05.txt
Subtask3 sample_1.txt, sample_2.txt, 03_i.txt, 03_random01.txt, 03_random02.txt, 03_random03.txt, 03_random04.txt, 03_random05.txt, 03_random06.txt, 03_random07.txt, 03_random08.txt, 03_random09.txt, 03_random10.txt, 03_random11.txt, 03_random12.txt, 03_random13.txt, 03_random14.txt, 03_random15.txt
Subtask4 sample_1.txt, sample_2.txt, sample_3.txt, 04_i.txt, 04_p1.txt, 04_p2.txt, 04_random01.txt, 04_random02.txt, 04_random03.txt, 04_random04.txt, 04_random05.txt, 04_random06.txt, 04_random07.txt, 04_random08.txt, 04_random09.txt, 04_random10.txt, 04_random11.txt, 04_random12.txt, 04_random13.txt, 04_rp01.txt, 04_rp02.txt, 04_rp03.txt, 04_rp04.txt, 04_rp05.txt, 04_rp06.txt, 04_rp07.txt, 04_rp08.txt, 04_rp09.txt, 04_rp10.txt
ケース名 結果 実行時間 メモリ
01_i.txt AC 2121 ms 41136 KB
01_random01.txt AC 565 ms 23356 KB
01_random02.txt AC 444 ms 23348 KB
01_random03.txt AC 449 ms 23344 KB
01_random04.txt AC 779 ms 36328 KB
01_random05.txt AC 1974 ms 39796 KB
01_random06.txt AC 2064 ms 39532 KB
01_random07.txt AC 2165 ms 41068 KB
02_i.txt AC 577 ms 26036 KB
02_p.txt AC 542 ms 24628 KB
02_random01.txt AC 449 ms 23344 KB
02_random02.txt AC 458 ms 23296 KB
02_random03.txt AC 603 ms 28564 KB
02_random04.txt AC 493 ms 23476 KB
02_random05.txt AC 734 ms 38688 KB
02_random06.txt AC 835 ms 38104 KB
02_random07.txt AC 969 ms 38808 KB
02_random08.txt AC 939 ms 38744 KB
02_rp01.txt AC 546 ms 24752 KB
02_rp02.txt AC 544 ms 24756 KB
02_rp03.txt AC 543 ms 24752 KB
02_rp04.txt AC 547 ms 24756 KB
02_rp05.txt AC 548 ms 24756 KB
03_i.txt AC 443 ms 23348 KB
03_random01.txt AC 693 ms 33924 KB
03_random02.txt AC 881 ms 37960 KB
03_random03.txt AC 855 ms 37888 KB
03_random04.txt AC 876 ms 38360 KB
03_random05.txt AC 735 ms 37648 KB
03_random06.txt AC 740 ms 37132 KB
03_random07.txt AC 771 ms 37348 KB
03_random08.txt AC 544 ms 26516 KB
03_random09.txt AC 767 ms 36976 KB
03_random10.txt AC 803 ms 37164 KB
03_random11.txt AC 896 ms 37664 KB
03_random12.txt AC 945 ms 38424 KB
03_random13.txt AC 850 ms 38072 KB
03_random14.txt AC 821 ms 38172 KB
03_random15.txt AC 759 ms 37328 KB
04_i.txt AC 2129 ms 41464 KB
04_p1.txt AC 1982 ms 39548 KB
04_p2.txt AC 1779 ms 39552 KB
04_random01.txt AC 1588 ms 37148 KB
04_random02.txt AC 1409 ms 37908 KB
04_random03.txt AC 1140 ms 36972 KB
04_random04.txt AC 1169 ms 38908 KB
04_random05.txt AC 1200 ms 38900 KB
04_random06.txt AC 1627 ms 37760 KB
04_random07.txt AC 1485 ms 39024 KB
04_random08.txt AC 1411 ms 38752 KB
04_random09.txt AC 1311 ms 39072 KB
04_random10.txt AC 1669 ms 38868 KB
04_random11.txt AC 2090 ms 40072 KB
04_random12.txt AC 2133 ms 40504 KB
04_random13.txt AC 2097 ms 40548 KB
04_rp01.txt AC 1992 ms 40104 KB
04_rp02.txt AC 1972 ms 39944 KB
04_rp03.txt AC 1979 ms 39648 KB
04_rp04.txt AC 1976 ms 39268 KB
04_rp05.txt AC 2005 ms 40400 KB
04_rp06.txt AC 1949 ms 40164 KB
04_rp07.txt AC 1961 ms 40344 KB
04_rp08.txt AC 2026 ms 38872 KB
04_rp09.txt AC 2030 ms 40148 KB
04_rp10.txt AC 1978 ms 39408 KB
sample_1.txt AC 444 ms 23348 KB
sample_2.txt AC 446 ms 23380 KB
sample_3.txt AC 448 ms 23348 KB