結果
| 問題 | 
                            No.643 Two Operations No.2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-05-02 00:24:35 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 891 bytes | 
| コンパイル時間 | 2,100 ms | 
| コンパイル使用メモリ | 171,076 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-25 17:43:30 | 
| 合計ジャッジ時間 | 3,178 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 WA * 3 | 
ソースコード
#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));
            cands.push_back(make_pair(cand.first+cand.second, cand.first - cand.second));
        }
    }
}