結果
| 問題 |
No.602 隠されていたゲーム2
|
| コンテスト | |
| ユーザー |
creep04
|
| 提出日時 | 2017-12-02 04:52:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 2,000 ms |
| コード長 | 1,262 bytes |
| コンパイル時間 | 1,426 ms |
| コンパイル使用メモリ | 165,104 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-16 00:02:34 |
| 合計ジャッジ時間 | 2,420 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int n, x, y, t;
long long D;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
vector<long long> even, odd;
for (int i = 0; i < n; ++i) {
cin >> t;
if (t%2==0) even.push_back(t);
else odd.push_back(t);
}
sort(even.begin(), even.end());
sort(odd.begin(), odd.end());
cin >> x >> y;
D = abs(x) + abs(y);
if (D==0) {
cout << 0 << "\n";
return 0;
}
if (binary_search(even.begin(), even.end(), D)
|| binary_search(odd.begin(), odd.end(), D)) {
cout << 1 << "\n";
return 0;
}
for (auto itr: even) {
long long fr = abs(itr-D), to = itr + D;
if ((to%2==0 && lower_bound(even.begin(), even.end(), to)
- lower_bound(even.begin(),even.end(), fr) > 0) ||
(to%2==1 && lower_bound(odd.begin(), odd.end(), to)
- lower_bound(odd.begin(),odd.end(), fr) > 0)) {
cout << 2 << "\n";
return 0;
}
}
for (auto itr: odd) {
long long fr = abs(itr-D), to = itr + D;
if ((to%2==0 && lower_bound(even.begin(), even.end(), to)
- lower_bound(even.begin(),even.end(), fr) > 0) ||
(to%2==1 && lower_bound(odd.begin(), odd.end(), to)
- lower_bound(odd.begin(),odd.end(), fr) > 0)) {
cout << 2 << "\n";
return 0;
}
}
cout << -1 << "\n";
}
creep04