結果

問題 No.438 Cwwプログラミング入門
ユーザー uafr_csuafr_cs
提出日時 2016-10-28 23:56:05
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,380 bytes
コンパイル時間 3,812 ms
コンパイル使用メモリ 81,984 KB
実行使用メモリ 41,756 KB
最終ジャッジ日時 2024-05-03 18:02:04
合計ジャッジ時間 18,948 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
41,000 KB
testcase_01 AC 108 ms
39,900 KB
testcase_02 AC 104 ms
40,048 KB
testcase_03 AC 116 ms
41,336 KB
testcase_04 AC 119 ms
41,176 KB
testcase_05 AC 112 ms
40,304 KB
testcase_06 AC 105 ms
40,296 KB
testcase_07 AC 103 ms
40,160 KB
testcase_08 AC 116 ms
41,160 KB
testcase_09 AC 120 ms
41,600 KB
testcase_10 AC 125 ms
41,264 KB
testcase_11 AC 110 ms
40,104 KB
testcase_12 AC 108 ms
40,184 KB
testcase_13 AC 122 ms
40,908 KB
testcase_14 AC 121 ms
41,368 KB
testcase_15 AC 113 ms
41,008 KB
testcase_16 AC 103 ms
39,796 KB
testcase_17 AC 108 ms
40,348 KB
testcase_18 AC 105 ms
40,528 KB
testcase_19 AC 106 ms
39,672 KB
testcase_20 AC 119 ms
41,188 KB
testcase_21 AC 103 ms
40,064 KB
testcase_22 AC 120 ms
41,068 KB
testcase_23 AC 108 ms
40,112 KB
testcase_24 AC 108 ms
39,992 KB
testcase_25 AC 104 ms
40,120 KB
testcase_26 AC 120 ms
41,224 KB
testcase_27 AC 110 ms
41,296 KB
testcase_28 AC 121 ms
41,108 KB
testcase_29 AC 111 ms
39,820 KB
testcase_30 AC 103 ms
39,992 KB
testcase_31 AC 107 ms
40,016 KB
testcase_32 AC 121 ms
41,188 KB
testcase_33 AC 108 ms
39,824 KB
testcase_34 WA -
testcase_35 AC 116 ms
40,952 KB
testcase_36 AC 110 ms
40,136 KB
testcase_37 AC 108 ms
40,400 KB
testcase_38 AC 108 ms
39,884 KB
testcase_39 AC 117 ms
40,528 KB
testcase_40 AC 113 ms
40,848 KB
testcase_41 AC 114 ms
41,276 KB
testcase_42 AC 107 ms
40,244 KB
testcase_43 AC 112 ms
41,072 KB
testcase_44 AC 115 ms
40,924 KB
testcase_45 AC 107 ms
40,296 KB
testcase_46 AC 114 ms
40,808 KB
testcase_47 AC 119 ms
41,000 KB
testcase_48 WA -
testcase_49 AC 119 ms
41,188 KB
testcase_50 AC 113 ms
41,024 KB
testcase_51 AC 113 ms
40,584 KB
testcase_52 WA -
testcase_53 AC 125 ms
40,604 KB
testcase_54 AC 117 ms
41,196 KB
testcase_55 AC 130 ms
41,548 KB
testcase_56 AC 116 ms
40,472 KB
testcase_57 AC 125 ms
41,012 KB
testcase_58 AC 116 ms
41,092 KB
testcase_59 AC 109 ms
39,768 KB
testcase_60 AC 108 ms
40,124 KB
testcase_61 AC 119 ms
41,512 KB
testcase_62 AC 107 ms
40,820 KB
testcase_63 AC 126 ms
41,196 KB
testcase_64 AC 126 ms
40,208 KB
testcase_65 AC 120 ms
41,216 KB
testcase_66 AC 121 ms
41,328 KB
testcase_67 AC 116 ms
41,068 KB
testcase_68 WA -
testcase_69 AC 109 ms
40,188 KB
testcase_70 AC 121 ms
41,132 KB
testcase_71 AC 108 ms
40,124 KB
testcase_72 AC 118 ms
40,928 KB
testcase_73 AC 106 ms
40,028 KB
testcase_74 AC 108 ms
40,460 KB
testcase_75 AC 114 ms
41,264 KB
testcase_76 WA -
testcase_77 AC 112 ms
40,052 KB
testcase_78 AC 121 ms
41,204 KB
testcase_79 AC 113 ms
40,908 KB
testcase_80 AC 116 ms
41,276 KB
testcase_81 AC 101 ms
39,820 KB
testcase_82 AC 106 ms
39,932 KB
testcase_83 AC 120 ms
41,304 KB
testcase_84 AC 112 ms
40,936 KB
testcase_85 AC 108 ms
41,188 KB
testcase_86 AC 117 ms
41,460 KB
testcase_87 AC 109 ms
40,204 KB
testcase_88 AC 109 ms
40,220 KB
testcase_89 AC 123 ms
40,416 KB
testcase_90 AC 110 ms
40,412 KB
testcase_91 AC 126 ms
40,540 KB
testcase_92 AC 114 ms
40,704 KB
testcase_93 RE -
testcase_94 RE -
testcase_95 WA -
testcase_96 AC 107 ms
40,404 KB
testcase_97 AC 127 ms
41,212 KB
testcase_98 AC 113 ms
41,188 KB
testcase_99 AC 107 ms
40,404 KB
testcase_100 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	
	public static long exec(long x, long y, char[] program){
		LinkedList<Long> stack = new LinkedList<Long>();
		
		for(final char ch : program){
			switch(ch){
			case 'c': stack.addFirst(x); break;
			case 'w': stack.addFirst(y); break;
			case 'C': 
				final long a_c = stack.poll();
				final long b_c = stack.poll();
				stack.addFirst(a_c + b_c);
				break;
			case 'W': 
				final long a_w = stack.poll();
				final long b_w = stack.poll();
				stack.addFirst(a_w - b_w);
				break;
			}
		}
		
		return stack.poll();
	}
	
	public static class Ref<T> {
		T value;
		
		public void setValue(T value){
			this.value = value;
		}
		
		public T getValue(){
			return value;
		}
	}
	
	public static long gcd(long a, long b){
		return b == 0 ? a : gcd(b, a % b);
	}
	
	public static long extcdf(long a, long b, Ref<Long> x, Ref<Long> y){
		long g = a;
		x.setValue(1l);
		y.setValue(0l);
		
		if(b != 0){
			g = extcdf(b, a % b, y, x);
			y.setValue(y.getValue() - (a / b) * x.getValue());
		}
		
		return g;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final long x = sc.nextLong();
		final long y = sc.nextLong();
		final long z = sc.nextLong();
		
		final long gcd = gcd(x, y);
		if(z % gcd != 0){
			System.out.println("mourennaihasimasenn");
		}else{
			LinkedList<Character> answer_list = new LinkedList<>();
			long curr_value = 0;
			while(curr_value != z && answer_list.size() <= 10000){
				if(curr_value < z){
					final long diff = z - curr_value;
					
					if(x > y){
						//if(diff > y){
							answer_list.addLast('c');
							if(answer_list.size() != 1){ answer_list.addLast('C'); }
							curr_value += x;
						/*}else{
							answer_list.addLast('w');
							if(answer_list.size() != 1){ answer_list.addLast('C'); }
							curr_value += y;
						}*/
					}else{
						//if(diff > x){
							answer_list.addLast('w');
							if(answer_list.size() != 1){ answer_list.addLast('C'); }
							curr_value += y;
						/*}else{
							answer_list.addLast('c');
							if(answer_list.size() != 1){ answer_list.addLast('C'); }
							curr_value += x;
						}*/
					}
				}else{
					final long diff = curr_value - z;
					
					if(x > y){
						/*if(diff > y){
							answer_list.addFirst('c');
							if(answer_list.size() != 1){ answer_list.addLast('W'); }
							curr_value -= x;
						}else{*/
							answer_list.addFirst('w');
							if(answer_list.size() != 1){ answer_list.addLast('W'); }
							curr_value -= y;
						//}
					}else{
						/*if(diff > x){
							answer_list.addFirst('w');
							if(answer_list.size() != 1){ answer_list.addLast('W'); }
							curr_value -= y;
						}else{*/
							answer_list.addFirst('c');
							if(answer_list.size() != 1){ answer_list.addLast('W'); }
							curr_value -= x;
						//}
					}
				}
			}
			
			//System.out.println(answer_list);
			
			if(curr_value == z && answer_list.size() <= 10000){
				StringBuilder sb = new StringBuilder();
				for(final char ch : answer_list){
					sb.append(ch);
				}
				System.out.println(sb);
			}else{
				System.out.println("mourennaihasimasenn");
			}
		}
	}
}
0