結果
問題 | No.643 Two Operations No.2 |
ユーザー |
![]() |
提出日時 | 2018-02-02 21:41:47 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,403 bytes |
コンパイル時間 | 986 ms |
コンパイル使用メモリ | 95,088 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-31 07:19:38 |
合計ジャッジ時間 | 1,537 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 |
ソースコード
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #include <iomanip> using namespace std; typedef long long ll; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(ll i=(a);i<(b);++i) #define per(i,a,b) for(ll i=(b-1);i>=(a);--i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define ctos(c) string(1,c) #define print(x) cout<<#x<<" = "<<x<<endl; #define MOD 1000000007 ll dp[510][510]; int main() { ll x,y; cin>>x>>y; clr(dp,-1); queue<ll> q1; queue<ll> q2; queue<ll> q3; q1.push(x+200); q2.push(y+200); q3.push(0); while(!q1.empty()){ ll a = q1.front()-200;q1.pop(); ll b = q2.front()-200;q2.pop(); ll c = q3.front();q3.pop(); if(a+200>500)continue; if(a+200<0)continue; if(b+200>500)continue; if(b+200<0)continue; if(dp[a+200][b+200]!=-1)continue; dp[a+200][b+200] = c; if(a==b){ cout << c << endl; return 0; } q1.push(b+200); q2.push(a+200); q3.push(c+1); q1.push(a+b+200); q2.push(a-b+200); q3.push(c+1); } cout << -1 << endl; return 0; }