結果
問題 |
No.643 Two Operations No.2
|
ユーザー |
|
提出日時 | 2020-05-02 00:38:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 907 bytes |
コンパイル時間 | 1,623 ms |
コンパイル使用メモリ | 171,148 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-25 18:43:01 |
合計ジャッジ時間 | 2,264 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 |
ソースコード
#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)); } } }