結果
| 問題 |
No.643 Two Operations No.2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-02-02 22:31:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,189 bytes |
| コンパイル時間 | 1,146 ms |
| コンパイル使用メモリ | 82,684 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-31 07:52:25 |
| 合計ジャッジ時間 | 1,833 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 3 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using PII = pair<int, int>;
const int wide = 1000;
vector<vector<bool>> check_dat;
bool check(int x, int y) {
return check_dat[x + wide][y + wide];
}
void checked(int x, int y, bool val) {
check_dat[x + wide][y + wide] = val;
}
int main() {
int x, y, x2, y2;
cin >> x >> y;
if (x == y) {
cout << 0 << endl;
return 0;
}
if (abs(x - y) % 2 == 1) {
cout << -1 << endl;
return 0;
}
check_dat.assign(2 * wide + 1, vector<bool>(2 * wide + 1, false));
checked(x, y, true);
vector<PII> v1, v2;
v1.emplace_back(make_pair(x, y));
int ans = 0;
while (!v1.empty()) {
v2.clear();
ans++;
for (auto p : v1) {
x = p.first;
y = p.second;
x2 = y;
y2 = x;
if (!check(x2, y2)) {
checked(x, y, true);
v2.emplace_back(make_pair(x2, y2));
}
x2 = x + y;
y2 = x - y;
if (x2 == y2) {
cout << ans << endl;
return 0;
}
if (abs(x2) > wide || abs(y2) > wide) {
continue;
}
if (!check(x2, y2)) {
checked(x, y, true);
v2.emplace_back(make_pair(x2, y2));
}
}
v1 = v2;
}
cout << -1 << endl;
return 0;
}