結果
| 問題 |
No.643 Two Operations No.2
|
| コンテスト | |
| ユーザー |
treeone
|
| 提出日時 | 2018-02-02 21:46:18 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 1,550 bytes |
| コンパイル時間 | 1,754 ms |
| コンパイル使用メモリ | 166,240 KB |
| 実行使用メモリ | 11,368 KB |
| 最終ジャッジ日時 | 2024-12-31 07:23:14 |
| 合計ジャッジ時間 | 2,488 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
const int INF = 1e12;
int d[1010][1010];
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int x, y;
cin >> x >> y;
x += 500; y += 500;
rep(i, 0, 1010) rep(j, 0, 1010) d[i][j] = INF;
d[x][y] = 0;
priority_queue<PP, vector<PP>, greater<PP> > q;
q.push(PP(0, P(x, y)));
while(!q.empty()){
PP p = q.top(); q.pop();
int nowd = p.first;
int nowx = p.second.first;
int nowy = p.second.second;
int nextx = nowy + nowx - 500;
int nexty = nowx - nowy + 500;
// cout << nowd << " " << nowx << " " << nowy << " " << nextx << " " << nexty << endl;
if(d[nowy][nowx] > nowd + 1){
d[nowy][nowx] = nowd + 1;
q.push(PP(nowd + 1, P(nowy, nowx)));
}
if(nexty < 0 || nexty > 1000 || nextx < 0 || nextx > 1000) continue;
if(d[nextx][nexty] > nowd + 1){
d[nextx][nexty] = nowd + 1;
q.push(PP(nowd + 1, P(nextx, nexty)));
}
if(nexty == nextx) break;
}
int ans = INF;
rep(i, 0, 1010) chmin(ans, d[i][i]);
if(ans == INF) ans = -1;
cout << ans << endl;
}
treeone