結果

問題 No.338 アンケート機能
ユーザー haruteruharuteru
提出日時 2016-02-03 13:19:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,007 bytes
コンパイル時間 475 ms
コンパイル使用メモリ 60,392 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 18:49:05
合計ジャッジ時間 4,827 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
4,348 KB
testcase_01 AC 89 ms
4,348 KB
testcase_02 AC 101 ms
4,348 KB
testcase_03 AC 115 ms
4,348 KB
testcase_04 AC 58 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 64 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 97 ms
4,348 KB
testcase_09 WA -
testcase_10 AC 105 ms
4,348 KB
testcase_11 AC 115 ms
4,348 KB
testcase_12 AC 105 ms
4,348 KB
testcase_13 AC 108 ms
4,348 KB
testcase_14 AC 113 ms
4,348 KB
testcase_15 AC 97 ms
4,348 KB
testcase_16 AC 125 ms
4,348 KB
testcase_17 AC 100 ms
4,348 KB
testcase_18 AC 127 ms
4,348 KB
testcase_19 AC 114 ms
4,348 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 128 ms
4,348 KB
testcase_24 AC 118 ms
4,348 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 139 ms
4,348 KB
testcase_29 AC 116 ms
4,348 KB
testcase_30 AC 119 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

#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 = A + B;
    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