結果
問題 | No.602 隠されていたゲーム2 |
ユーザー |
|
提出日時 | 2017-12-02 00:16:51 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 958 bytes |
コンパイル時間 | 1,624 ms |
コンパイル使用メモリ | 166,772 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-15 23:56:46 |
合計ジャッジ時間 | 2,771 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:20:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 20 | scanf("%d",&d[i]); | ~~~~~^~~~~~~~~~~~ main.cpp:23:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 23 | scanf("%d%d",&x,&y); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>#define MOD 1000000007LLusing namespace std;typedef long long ll;typedef pair<int,int> P;int n;int d[100001];int x,y;vector<ll> vi[2];ll labs(ll v){if(v<0LL)return -v;return v;}int main(void){scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d",&d[i]);vi[d[i]%2].push_back(d[i]);}scanf("%d%d",&x,&y);if(x==0 && y==0){printf("0\n");return 0;}sort(d,d+n);sort(vi[0].begin(),vi[0].end());sort(vi[1].begin(),vi[1].end());for(int i=0;i<n;i++){if(d[i]==(abs(x)+abs(y))){printf("1\n");return 0;}}for(int i=0;i<n;i++){ll rest=labs((ll)x)+labs((ll)y)-d[i];ll maxi=labs((ll)x)+labs((ll)y)+(ll)d[i];if(rest<0){rest=labs(rest);}if(vi[rest%2].size()==0)continue;int vo=lower_bound(vi[rest%2].begin(),vi[rest%2].end(),rest)-vi[rest%2].begin();if(vo!=vi[rest%2].size() && vi[rest%2][vo]<=maxi){printf("2\n");return 0;}}printf("-1\n");return 0;}