結果

問題 No.438 Cwwプログラミング入門
ユーザー GrenacheGrenache
提出日時 2016-11-01 20:20:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 5,766 bytes
コンパイル時間 5,045 ms
コンパイル使用メモリ 86,460 KB
実行使用メモリ 37,400 KB
最終ジャッジ日時 2024-05-05 21:07:39
合計ジャッジ時間 13,309 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
37,096 KB
testcase_01 AC 62 ms
37,312 KB
testcase_02 AC 53 ms
36,936 KB
testcase_03 AC 54 ms
36,664 KB
testcase_04 AC 53 ms
37,040 KB
testcase_05 AC 53 ms
36,788 KB
testcase_06 AC 57 ms
36,968 KB
testcase_07 AC 53 ms
36,824 KB
testcase_08 AC 57 ms
37,224 KB
testcase_09 AC 57 ms
37,236 KB
testcase_10 AC 57 ms
36,968 KB
testcase_11 AC 59 ms
37,228 KB
testcase_12 AC 60 ms
37,096 KB
testcase_13 AC 53 ms
36,928 KB
testcase_14 AC 58 ms
37,256 KB
testcase_15 AC 53 ms
36,936 KB
testcase_16 AC 57 ms
37,208 KB
testcase_17 AC 58 ms
36,820 KB
testcase_18 AC 54 ms
37,060 KB
testcase_19 AC 54 ms
36,992 KB
testcase_20 AC 57 ms
37,372 KB
testcase_21 AC 58 ms
37,088 KB
testcase_22 AC 57 ms
36,988 KB
testcase_23 AC 57 ms
37,036 KB
testcase_24 AC 55 ms
36,736 KB
testcase_25 AC 58 ms
37,164 KB
testcase_26 AC 59 ms
36,988 KB
testcase_27 AC 53 ms
36,968 KB
testcase_28 AC 57 ms
36,996 KB
testcase_29 AC 58 ms
37,384 KB
testcase_30 AC 58 ms
36,968 KB
testcase_31 AC 62 ms
36,968 KB
testcase_32 AC 63 ms
36,860 KB
testcase_33 AC 62 ms
37,240 KB
testcase_34 AC 54 ms
37,116 KB
testcase_35 AC 58 ms
36,912 KB
testcase_36 AC 58 ms
37,392 KB
testcase_37 AC 57 ms
37,164 KB
testcase_38 AC 53 ms
36,700 KB
testcase_39 AC 58 ms
36,988 KB
testcase_40 AC 53 ms
36,792 KB
testcase_41 AC 56 ms
36,900 KB
testcase_42 AC 57 ms
36,916 KB
testcase_43 AC 53 ms
36,788 KB
testcase_44 AC 58 ms
37,384 KB
testcase_45 AC 58 ms
37,332 KB
testcase_46 AC 58 ms
37,224 KB
testcase_47 AC 59 ms
37,316 KB
testcase_48 AC 59 ms
37,300 KB
testcase_49 AC 58 ms
37,200 KB
testcase_50 AC 55 ms
37,116 KB
testcase_51 AC 53 ms
37,288 KB
testcase_52 AC 59 ms
37,296 KB
testcase_53 AC 57 ms
37,116 KB
testcase_54 AC 54 ms
36,792 KB
testcase_55 AC 59 ms
37,224 KB
testcase_56 AC 59 ms
36,980 KB
testcase_57 AC 57 ms
37,184 KB
testcase_58 AC 53 ms
36,712 KB
testcase_59 AC 58 ms
37,256 KB
testcase_60 AC 59 ms
37,260 KB
testcase_61 AC 57 ms
36,880 KB
testcase_62 AC 53 ms
36,772 KB
testcase_63 AC 58 ms
37,388 KB
testcase_64 AC 58 ms
37,224 KB
testcase_65 AC 52 ms
36,780 KB
testcase_66 AC 57 ms
36,916 KB
testcase_67 AC 53 ms
36,992 KB
testcase_68 AC 53 ms
37,056 KB
testcase_69 AC 56 ms
36,916 KB
testcase_70 AC 58 ms
37,192 KB
testcase_71 AC 58 ms
36,912 KB
testcase_72 AC 60 ms
37,260 KB
testcase_73 AC 57 ms
37,164 KB
testcase_74 AC 57 ms
36,916 KB
testcase_75 AC 57 ms
37,096 KB
testcase_76 AC 52 ms
36,952 KB
testcase_77 AC 57 ms
37,156 KB
testcase_78 AC 52 ms
36,920 KB
testcase_79 AC 54 ms
36,788 KB
testcase_80 AC 54 ms
36,732 KB
testcase_81 AC 53 ms
36,716 KB
testcase_82 AC 52 ms
36,968 KB
testcase_83 AC 53 ms
37,128 KB
testcase_84 AC 54 ms
36,896 KB
testcase_85 AC 54 ms
36,532 KB
testcase_86 AC 53 ms
36,944 KB
testcase_87 AC 52 ms
37,112 KB
testcase_88 AC 57 ms
37,176 KB
testcase_89 AC 58 ms
37,176 KB
testcase_90 AC 53 ms
37,116 KB
testcase_91 AC 57 ms
37,220 KB
testcase_92 AC 57 ms
36,656 KB
testcase_93 AC 53 ms
36,788 KB
testcase_94 AC 52 ms
37,052 KB
testcase_95 AC 58 ms
37,280 KB
testcase_96 AC 55 ms
37,044 KB
testcase_97 AC 61 ms
37,400 KB
testcase_98 AC 53 ms
36,992 KB
testcase_99 AC 53 ms
36,972 KB
testcase_100 AC 58 ms
37,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder438 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		long x = sc.nextInt();
		long y = sc.nextInt();
		long z = sc.nextInt();

		if (z == 0) {
			pr.println("ccW");
			return;
		}

		long[] ab = new long[2];
		long gcd = extgcd(x, y, ab);
		if ((x == 0 && y == 0) || z % gcd != 0) {
			pr.println("mourennaihasimasenn");
			return;
		}

		long mul = z / gcd;
		ab[0] *= mul;
		ab[1] *= mul;
		x /= gcd;
		y /= gcd;

        // 整数の三分探索
        long l = -1_000_000_000;
        long r = 1_000_000_000;
		while (r - l > 1) {
			long mid = l + (r - l) / 2;
			long f1 = Math.abs(y * (mid + 1) + ab[0]) + Math.abs(- x * (mid + 1) + ab[1]);
			long f2 = Math.abs(y * (mid) + ab[0]) + Math.abs(- x * (mid) + ab[1]);
			if (f1 - f2 >= 0) {
				r = mid;
			} else {
				l = mid;
			}
		}

		ab[0] = y * r + ab[0];
		ab[1] = -x * r + ab[1];
		if (Math.abs(ab[0]) + Math.abs(ab[1]) > 5000) {
			pr.println("mourennaihasimasenn");
			return;
		}

		StringBuilder ret = new StringBuilder();
		if (ab[0] < 0) {
			append(ret, 'c', -ab[0]);
			append(ret, 'w', ab[1]);
			append(ret, 'C', ab[1] - 1);
			append(ret, 'W', -ab[0]);
		} else if (ab[1] < 0) {
			append(ret, 'w', -ab[1]);
			append(ret, 'c', ab[0]);
			append(ret, 'C', ab[0] - 1);
			append(ret, 'W', -ab[1]);
		} else {
			append(ret, 'c', ab[0]);
			append(ret, 'w', ab[1]);
			append(ret, 'C', ab[0] + ab[1] - 1);
		}

		if (ret.length() > 10000) {
			pr.println("mourennaihasimasenn");
		} else {
			pr.println(ret);
		}
	}

	private static void append(StringBuilder ret, char c, long n) {
		String s = Character.toString(c);

		while (n > 0) {
			if (n % 2 == 1) {
				ret.append(s);
			}
			n /= 2;
			s = s + s;
		}

		return;
	}

	private static long extgcd(long n, long m, long[] xy) {
		if (m == 0) {
			xy[0] = 1;
			xy[1] = 0;

			return n;
		} else {
			long ret = extgcd(m, n % m, xy);

			long tmp = xy[1];
			xy[1] = xy[0] - n / m * tmp;
			xy[0] = tmp;

			return ret;
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		private boolean isPrintable(int ch) {
			return ch >= '!' && ch <= '~';
		}

		private boolean isCRLF(int ch) {
			return ch == '\n' || ch == '\r' || ch == -1;
		}

		private int nextPrintable() {
			try {
				int ch;
				while (!isPrintable(ch = br.read())) {
					if (ch == -1) {
						throw new NoSuchElementException();
					}
				}

				return ch;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		String next() {
			try {
				int ch = nextPrintable();
				StringBuilder sb = new StringBuilder();
				do {
					sb.appendCodePoint(ch);
				} while (isPrintable(ch = br.read()));

				return sb.toString();
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		int nextInt() {
			try {
				// parseInt from Integer.parseInt()
				boolean negative = false;
				int res = 0;
				int limit = -Integer.MAX_VALUE;
				int radix = 10;

				int fc = nextPrintable();
				if (fc < '0') {
					if (fc == '-') {
						negative = true;
						limit = Integer.MIN_VALUE;
					} else if (fc != '+') {
						throw new NumberFormatException();
					}
					fc = br.read();
				}
				int multmin = limit / radix;

				int ch = fc;
				do {
					int digit = ch - '0';
					if (digit < 0 || digit >= radix) {
						throw new NumberFormatException();
					}
					if (res < multmin) {
						throw new NumberFormatException();
					}
					res *= radix;
					if (res < limit + digit) {
						throw new NumberFormatException();
					}
					res -= digit;

				} while (isPrintable(ch = br.read()));

				return negative ? res : -res;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		long nextLong() {
			try {
				// parseLong from Long.parseLong()
				boolean negative = false;
				long res = 0;
				long limit = -Long.MAX_VALUE;
				int radix = 10;

				int fc = nextPrintable();
				if (fc < '0') {
					if (fc == '-') {
						negative = true;
						limit = Long.MIN_VALUE;
					} else if (fc != '+') {
						throw new NumberFormatException();
					}
					fc = br.read();
				}
				long multmin = limit / radix;

				int ch = fc;
				do {
					int digit = ch - '0';
					if (digit < 0 || digit >= radix) {
						throw new NumberFormatException();
					}
					if (res < multmin) {
						throw new NumberFormatException();
					}
					res *= radix;
					if (res < limit + digit) {
						throw new NumberFormatException();
					}
					res -= digit;

				} while (isPrintable(ch = br.read()));

				return negative ? res : -res;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		float nextFloat() {
			return Float.parseFloat(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			try {
				int ch;
				while (isCRLF(ch = br.read())) {
					if (ch == -1) {
						throw new NoSuchElementException();
					}
				}
				StringBuilder sb = new StringBuilder();
				do {
					sb.appendCodePoint(ch);
				} while (!isCRLF(ch = br.read()));

				return sb.toString();
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new NoSuchElementException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0