結果

問題 No.438 Cwwプログラミング入門
ユーザー uafr_cs
提出日時 2016-10-28 23:10:47
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,965 bytes
コンパイル時間 2,569 ms
コンパイル使用メモリ 81,328 KB
実行使用メモリ 672,120 KB
最終ジャッジ日時 2024-11-24 18:45:37
合計ジャッジ時間 62,432 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 29 WA * 33 RE * 22 MLE * 6 OLE * 8
権限があれば一括ダウンロードができます

ソースコード

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 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{
			Ref<Long> a = new Ref<Long>();
			Ref<Long> b = new Ref<Long>();
			
			extcdf(x, y, a, b);
			
			final long x_size = Math.abs(a.getValue()) * (z / gcd);
			final long y_size = Math.abs(b.getValue()) * (z / gcd);
			
			final StringBuilder x_sum = new StringBuilder();
			final StringBuilder y_sum = new StringBuilder();
			
			for(long i = 0; i < x_size; i++){
				x_sum.append('c');
				if(i != 0){
					x_sum.append('C');
				}
			}
			
			for(long i = 0; i < y_size; i++){
				y_sum.append('w');
				if(i != 0){
					y_sum.append('C');
				}
			}
			
			final StringBuilder answer = new StringBuilder();
			if(a.getValue() >= 0){
				answer.append(y_sum);
				answer.append(x_sum);
				
				if(b.getValue() >= 0){
					answer.append('C');
				}else{
					answer.append('W');
				}
			}else{
				answer.append(y_sum);
				answer.append(x_sum);
				
				answer.append('W');
			}
			
			System.out.println(answer);
		}
	}
}
0