結果
問題 |
No.643 Two Operations No.2
|
ユーザー |
|
提出日時 | 2023-05-09 23:46:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,025 bytes |
コンパイル時間 | 1,605 ms |
コンパイル使用メモリ | 178,072 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-26 08:23:33 |
合計ジャッジ時間 | 2,141 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int r = 200, x, y; vector<vector<int>> dp(2 * r + 1, vector<int>(2 * r + 1, 1 << 30)); queue<pair<int,int>> nxt; cin >> x >> y; dp[x + r][y + r] = 0; nxt.emplace(x + r, y + r); while(!nxt.empty()){ tie(x, y) = nxt.front(); nxt.pop(); x -= r, y -= r; if(dp[x + r][y + r] + 1 < dp[y + r][x + r]){ dp[y + r][x + r] = dp[x + r][y + r] + 1; nxt.emplace(y + r, x + r); } int v1 = x + y + r, v2 = x - y + r; if(v1 >= 0 && v2 >= 0 && v1 < dp.size() && v2 < dp.size() && dp[x + r][y + r] + 1 < dp[x + y + r][x - y + r]){ dp[x + y + r][x - y + r] = dp[x + r][y + r] + 1; nxt.emplace(x + y + r, x - y + r); } } int ans = 1 << 30; for(int i = 0; i < dp.size(); i++) ans = min(ans, dp[i][i]); cout << (ans >> 30 & 1 ? -1 : ans) << '\n'; }