結果

問題 No.643 Two Operations No.2
ユーザー t98slidert98slider
提出日時 2023-05-09 23:46:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,025 bytes
コンパイル時間 1,519 ms
コンパイル使用メモリ 174,392 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 11:56:24
合計ジャッジ時間 2,197 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
}
0