Submission #175250


Source Code Expand

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int K = stdIn.nextInt();
		String Ab =stdIn.next();
		String Ac = Ab;
		String Ad;
		char[] A = new char[N];
		for(int i = 0; i < N; i++) {
			A[i] = Ab.charAt(i);
		}
		String ANS;
		String[] jisyozyun = new String[]{"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
		int jisyozyunlowest = 0;
		for(int k = 0; k < N; k++) {
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < jisyozyun.length; j++) {
				int lastidou = 0;
				jisyozyunlowest = Ab.indexOf(jisyozyun[j],i);
				if (jisyozyunlowest == -1) {}
				else break;
			}
				char tmp = A[i];
				A[i] = A[jisyozyunlowest];
				A[jisyozyunlowest] = tmp;
				Ad = new String(A);
				
				if(wrongcheck(Ac,Ad) <= K) {
					Ab = Ad;
				}
				else {
					tmp = A[i];
					A[i] = A[jisyozyunlowest];
					A[jisyozyunlowest] = tmp;
				}
		}
		}
		for(int i = N-1; i >= 0; i--) {
			for(int j = jisyozyun.length-1; j >= 0; j--) {
				int lastidou = 0;
				jisyozyunlowest = Ab.indexOf(jisyozyun[j],i);
				if (jisyozyunlowest == -1) {}
				else break;
			}
				char tmp = A[i];
				A[i] = A[jisyozyunlowest];
				A[jisyozyunlowest] = tmp;
				Ad = new String(A);
				
				if(wrongcheck(Ac,Ad) <= K) {
					Ab = Ad;
				}
				else {
					tmp = A[i];
					A[i] = A[jisyozyunlowest];
					A[jisyozyunlowest] = tmp;
				}
		}
		

		System.out.println(Ab);
		
	}
	
	static int wrongcheck(String i,String k){
		int wrong = 0;
		for(int j = 0; j < i.length(); j++) {
			if(i.charAt(j) != k.charAt(j)) {
				wrong++;
			}
		}
		return wrong;
	}

}

Submission Info

Submission Time
Task C - 辞書式順序ふたたび
User XzA_2123
Language Java (OpenJDK 1.7.0)
Score 0
Code Size 1788 Byte
Status WA
Exec Time 631 ms
Memory 27356 KB

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 15
WA × 39
Set Name Test Cases
All hand_1_0.txt, hand_1_1.txt, hand_1_2.txt, hand_1_3.txt, hand_1_4.txt, hand_1_5.txt, hand_1_6.txt, hand_1_7.txt, hand_1_8.txt, hand_2_0.txt, hand_2_1.txt, hand_2_10.txt, hand_2_2.txt, hand_2_3.txt, hand_2_4.txt, hand_2_5.txt, hand_2_6.txt, hand_2_7.txt, hand_2_8.txt, hand_2_9.txt, hand_3_2.txt, hand_3_3.txt, hand_3_4.txt, hand_3_5.txt, hand_3_6.txt, hand_4_2.txt, hand_4_3.txt, hand_4_4.txt, hand_4_5.txt, hand_4_6.txt, random_1.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, small_1.txt, small_2.txt, small_3.txt, small_4.txt, small_5.txt, small_6.txt, small_7.txt, small_8.txt, small_9.txt
Case Name Status Exec Time Memory
hand_1_0.txt AC 492 ms 23216 KB
hand_1_1.txt AC 466 ms 23188 KB
hand_1_2.txt WA 462 ms 23216 KB
hand_1_3.txt WA 463 ms 23216 KB
hand_1_4.txt WA 465 ms 23184 KB
hand_1_5.txt WA 460 ms 23212 KB
hand_1_6.txt WA 467 ms 23084 KB
hand_1_7.txt WA 469 ms 23088 KB
hand_1_8.txt WA 463 ms 23212 KB
hand_2_0.txt AC 475 ms 23220 KB
hand_2_1.txt AC 470 ms 23220 KB
hand_2_10.txt WA 470 ms 23216 KB
hand_2_2.txt WA 463 ms 23212 KB
hand_2_3.txt WA 492 ms 23188 KB
hand_2_4.txt WA 499 ms 23176 KB
hand_2_5.txt WA 497 ms 23088 KB
hand_2_6.txt WA 482 ms 23220 KB
hand_2_7.txt WA 490 ms 23096 KB
hand_2_8.txt WA 497 ms 23220 KB
hand_2_9.txt WA 502 ms 23220 KB
hand_3_2.txt AC 501 ms 23216 KB
hand_3_3.txt WA 515 ms 23608 KB
hand_3_4.txt WA 507 ms 23336 KB
hand_3_5.txt WA 493 ms 23220 KB
hand_3_6.txt WA 512 ms 23392 KB
hand_4_2.txt AC 515 ms 23732 KB
hand_4_3.txt WA 529 ms 23732 KB
hand_4_4.txt WA 511 ms 23608 KB
hand_4_5.txt WA 523 ms 23600 KB
hand_4_6.txt WA 534 ms 23720 KB
random_1.txt AC 500 ms 23916 KB
random_10.txt WA 530 ms 27284 KB
random_11.txt WA 545 ms 26788 KB
random_12.txt WA 518 ms 27240 KB
random_13.txt WA 555 ms 27128 KB
random_14.txt WA 542 ms 27356 KB
random_15.txt WA 542 ms 26872 KB
random_2.txt WA 544 ms 23860 KB
random_3.txt WA 530 ms 24756 KB
random_4.txt WA 520 ms 24628 KB
random_5.txt WA 631 ms 25304 KB
random_6.txt WA 522 ms 25944 KB
random_7.txt AC 521 ms 25908 KB
random_8.txt AC 523 ms 26160 KB
random_9.txt WA 540 ms 26968 KB
sample_1.txt WA 477 ms 23212 KB
sample_2.txt WA 490 ms 23220 KB
sample_3.txt WA 496 ms 23092 KB
sample_4.txt AC 499 ms 23220 KB
small_1.txt AC 497 ms 23216 KB
small_2.txt AC 489 ms 23096 KB
small_3.txt AC 510 ms 23216 KB
small_4.txt AC 506 ms 23216 KB
small_5.txt WA 495 ms 23220 KB
small_6.txt AC 504 ms 23092 KB
small_7.txt AC 503 ms 23136 KB
small_8.txt WA 496 ms 23092 KB
small_9.txt WA 507 ms 23220 KB