結果

問題 No.141 魔法少女コバ
ユーザー tutuztutuz
提出日時 2018-09-14 21:55:25
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 3,380 bytes
コンパイル時間 2,318 ms
コンパイル使用メモリ 75,072 KB
実行使用メモリ 776,020 KB
最終ジャッジ日時 2023-09-20 14:58:34
合計ジャッジ時間 27,454 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,808 KB
testcase_01 MLE -
testcase_02 MLE -
testcase_03 AC 46 ms
49,268 KB
testcase_04 AC 46 ms
49,312 KB
testcase_05 AC 45 ms
49,336 KB
testcase_06 AC 45 ms
49,320 KB
testcase_07 AC 46 ms
49,312 KB
testcase_08 AC 45 ms
49,320 KB
testcase_09 AC 45 ms
49,312 KB
testcase_10 AC 44 ms
49,272 KB
testcase_11 AC 45 ms
49,280 KB
testcase_12 AC 46 ms
49,504 KB
testcase_13 AC 45 ms
49,316 KB
testcase_14 AC 45 ms
49,392 KB
testcase_15 AC 46 ms
49,552 KB
testcase_16 AC 45 ms
49,356 KB
testcase_17 AC 45 ms
49,412 KB
testcase_18 AC 44 ms
49,616 KB
testcase_19 AC 45 ms
49,336 KB
testcase_20 AC 45 ms
49,384 KB
testcase_21 AC 45 ms
49,360 KB
testcase_22 AC 46 ms
49,368 KB
testcase_23 AC 45 ms
49,404 KB
testcase_24 AC 45 ms
49,396 KB
testcase_25 AC 46 ms
49,756 KB
testcase_26 AC 44 ms
49,272 KB
testcase_27 AC 45 ms
49,428 KB
testcase_28 AC 46 ms
49,332 KB
testcase_29 AC 45 ms
49,316 KB
testcase_30 AC 46 ms
49,300 KB
testcase_31 AC 46 ms
49,428 KB
testcase_32 AC 45 ms
49,272 KB
testcase_33 AC 47 ms
49,508 KB
testcase_34 AC 46 ms
49,720 KB
testcase_35 AC 45 ms
49,448 KB
testcase_36 AC 44 ms
49,460 KB
testcase_37 AC 45 ms
49,456 KB
testcase_38 AC 46 ms
49,412 KB
testcase_39 AC 47 ms
49,416 KB
testcase_40 AC 47 ms
49,432 KB
testcase_41 AC 47 ms
49,600 KB
testcase_42 AC 47 ms
49,404 KB
testcase_43 AC 46 ms
49,420 KB
testcase_44 AC 46 ms
49,368 KB
testcase_45 AC 45 ms
49,420 KB
testcase_46 AC 46 ms
49,816 KB
testcase_47 AC 46 ms
49,604 KB
testcase_48 AC 46 ms
49,324 KB
testcase_49 AC 45 ms
49,300 KB
testcase_50 AC 46 ms
49,436 KB
testcase_51 AC 46 ms
49,320 KB
testcase_52 AC 46 ms
49,324 KB
testcase_53 AC 46 ms
49,464 KB
testcase_54 AC 45 ms
49,360 KB
testcase_55 AC 45 ms
49,308 KB
testcase_56 AC 46 ms
47,388 KB
testcase_57 AC 46 ms
49,744 KB
testcase_58 AC 44 ms
49,332 KB
testcase_59 AC 45 ms
49,316 KB
testcase_60 AC 45 ms
49,276 KB
testcase_61 AC 45 ms
49,420 KB
testcase_62 AC 45 ms
49,428 KB
testcase_63 AC 44 ms
49,328 KB
testcase_64 AC 45 ms
49,492 KB
testcase_65 AC 45 ms
49,432 KB
testcase_66 AC 44 ms
49,320 KB
testcase_67 AC 45 ms
49,324 KB
testcase_68 AC 44 ms
49,412 KB
testcase_69 AC 45 ms
49,312 KB
testcase_70 AC 45 ms
49,380 KB
testcase_71 AC 45 ms
49,892 KB
testcase_72 AC 45 ms
49,452 KB
testcase_73 AC 45 ms
49,380 KB
testcase_74 AC 45 ms
49,324 KB
testcase_75 AC 45 ms
49,332 KB
testcase_76 AC 46 ms
49,320 KB
testcase_77 AC 45 ms
49,460 KB
testcase_78 AC 46 ms
49,600 KB
testcase_79 AC 46 ms
49,748 KB
testcase_80 AC 46 ms
49,432 KB
testcase_81 AC 45 ms
49,320 KB
testcase_82 AC 45 ms
49,268 KB
testcase-evil-0.txt MLE -
testcase-evil-1.txt MLE -
testcase-evil-2.txt MLE -
testcase-evil-3.txt MLE -
testcase-evil-4.txt MLE -
testcase-evil-5.txt MLE -
testcase-evil-6.txt MLE -
testcase-evil-7.txt MLE -
testcase-evil-8.txt MLE -
testcase-evil-9.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long m = in.nextLong(), n = in.nextLong();
			long g = gcd(n, m);
			m /= g;
			n /= g;

			long ans = f(m, n, 0, false);
			out.println(ans);

		}

		long f(long bs, long bb, long cnt, boolean isSwap) {

			long ret = 0;
			if (bb == bs) {
				return cnt;
			}

			if (bs <= 0) {
				return 0;
			}

			if (isSwap) {
				ret += f(bs-bb, bb, cnt+1, false);
			} else {
				if (bs - bb > 0) {
					ret += Math.max(f(bs-bb, bb, cnt+1, false), f(bb, bs, cnt+1, true));
				} else {
					ret += f(bb, bs, cnt+1, true);
				}
			}

			return ret;
		}
	}

	public static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}
0