結果

問題 No.643 Two Operations No.2
ユーザー phsplsphspls
提出日時 2020-05-02 00:38:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 907 bytes
コンパイル時間 2,949 ms
コンパイル使用メモリ 168,872 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-26 18:27:41
合計ジャッジ時間 2,354 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,500 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 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 && x != 0 && y != 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));
            cands.push_back(make_pair(cand.first+cand.second, cand.first-cand.second));
        }
    }
}
0