結果
| 問題 |
No.438 Cwwプログラミング入門
|
| コンテスト | |
| ユーザー |
uafr_cs
|
| 提出日時 | 2016-10-28 23:18:17 |
| 言語 | Java (openjdk 23) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,658 bytes |
| コンパイル時間 | 4,938 ms |
| コンパイル使用メモリ | 88,232 KB |
| 実行使用メモリ | 670,804 KB |
| 最終ジャッジ日時 | 2024-11-24 19:49:19 |
| 合計ジャッジ時間 | 63,722 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 WA * 19 RE * 23 MLE * 5 OLE * 8 |
ソースコード
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{
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(x_size != 0 && y_size != 0){
if(b.getValue() >= 0){
answer.append('C');
}else{
answer.append('W');
}
}
}else{
answer.append(x_sum);
answer.append(y_sum);
if(x_size != 0 && y_size != 0){
answer.append('W');
}
}
//System.out.println(exec(x, y, answer.toString().toCharArray()));
System.out.println(answer);
}
}
}
uafr_cs