結果

問題 No.643 Two Operations No.2
ユーザー phsplsphspls
提出日時 2020-05-02 00:37:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 927 bytes
コンパイル時間 1,442 ms
コンパイル使用メモリ 168,824 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 18:24:38
合計ジャッジ時間 2,238 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define llong long long

int main() {
    int x, y;
    cin >> x >> y;
    if((x+y) % 2 != 0) {
        cout << "-1\n";
        return 0;
    } else if(x == y) {
        cout << "0\n";
        return 0;
    }
    int times = 0;
    deque<pair<int, int>> cands;
    cands.push_back(make_pair(x, y));
    while(true) {
        times++;
        int limit = cands.size();
        rep(i, limit) {
            pair<int, int> cand = cands.front();
            cands.pop_front();
            if(cand.first+cand.second == cand.first-cand.second) {
                cout << times << "\n";
                return 0;
            }
            cands.push_back(make_pair(cand.second, cand.first));
            if(cand.second + cand.second < 1000000) cands.push_back(make_pair(cand.first+cand.second, cand.first-cand.second));
        }
    }
}
0