結果
問題 |
No.602 隠されていたゲーム2
|
ユーザー |
![]() |
提出日時 | 2018-10-13 16:13:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 730 bytes |
コンパイル時間 | 557 ms |
コンパイル使用メモリ | 70,836 KB |
実行使用メモリ | 14,112 KB |
最終ジャッジ日時 | 2024-10-12 18:05:03 |
合計ジャッジ時間 | 4,230 ms |
ジャッジサーバーID (参考情報) |
judge / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 WA * 9 TLE * 1 -- * 5 |
ソースコード
#include<iostream> #include<algorithm> using namespace std; const int size=1e5+10; int n; int d[size]; int x,y; int dist; int ans; bool dfs(int i,int sum,int c) { //cout << i << endl; if(c>2)return false; if(sum>dist)return false; if(i>n)return false; if(sum==dist) { ans=min(ans,sum); return true; } if(dfs(i+1,sum,c))return true; if(dfs(i+1,sum+d[i],c+1))return true; return false; } int main() { cin >> n; for(int i=0;i<n;i++)cin >> d[i]; cin >> x >> y; dist=abs(x)+abs(y); //1 ans=1; for(int i=0;i<n;i++) { if(dist==d[i]) { cout << ans << endl; return 0; } } //2 ans=2; sort(d,d+n,greater<int>()); if(dfs(0,0,0))cout << ans << endl; else cout << -1 << endl; return 0; }