結果

問題 No.338 アンケート機能
ユーザー haruteruharuteru
提出日時 2016-02-03 13:25:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,029 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 60,912 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 15:53:24
合計ジャッジ時間 4,518 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
6,816 KB
testcase_01 AC 88 ms
6,940 KB
testcase_02 AC 91 ms
6,944 KB
testcase_03 AC 109 ms
6,944 KB
testcase_04 AC 55 ms
6,944 KB
testcase_05 AC 85 ms
6,944 KB
testcase_06 AC 59 ms
6,944 KB
testcase_07 AC 75 ms
6,940 KB
testcase_08 AC 91 ms
6,940 KB
testcase_09 AC 81 ms
6,940 KB
testcase_10 AC 101 ms
6,944 KB
testcase_11 AC 107 ms
6,940 KB
testcase_12 AC 99 ms
6,940 KB
testcase_13 AC 101 ms
6,940 KB
testcase_14 AC 105 ms
6,944 KB
testcase_15 AC 90 ms
6,940 KB
testcase_16 AC 117 ms
6,940 KB
testcase_17 AC 93 ms
6,940 KB
testcase_18 AC 123 ms
6,944 KB
testcase_19 AC 109 ms
6,940 KB
testcase_20 AC 102 ms
6,944 KB
testcase_21 AC 82 ms
6,944 KB
testcase_22 AC 119 ms
6,940 KB
testcase_23 AC 119 ms
6,944 KB
testcase_24 AC 111 ms
6,944 KB
testcase_25 AC 109 ms
6,944 KB
testcase_26 AC 104 ms
6,944 KB
testcase_27 AC 104 ms
6,940 KB
testcase_28 AC 131 ms
6,944 KB
testcase_29 AC 111 ms
6,944 KB
testcase_30 AC 111 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <limits.h>

#define MIN (1000)
#define MIN5 (500)

int gcd(int a, int b)
{
    if (b == 0) return a;
    return gcd(b, a % b);
}

int f(int A, int B)
{
    int rc = INT_MAX;
    int a = (A * MIN) - MIN5;
    int b = (B * MIN) - MIN5;
    int aa = (A * MIN) + MIN5;
    int bb = (B * MIN) + MIN5;
    for (int n = a; n < aa; n++) {
        for (int m = b; m < bb; m++) {
            int r = gcd(n, m);
            if (r > 1) {
                int nn = n / r;
                int mm = m / r;
                int rr = nn + mm;
                if (rr < rc) {
                    int nnn = ((nn * 1000 / rr) + 5) / 10;
                    int mmm = ((mm * 1000 / rr) + 5) / 10;
                    if (nnn == A && mmm == B) {
                        rc = rr;
                    }
                }
            }
        }
    }
    return rc;
}

int main()
{
    int A, B;
    std::cin >> A;
    std::cin >> B;
    std::cout << f(A,B) << std::endl;
    return 0;
}
0