結果
問題 | No.602 隠されていたゲーム2 |
ユーザー |
|
提出日時 | 2017-12-02 02:34:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 65 ms / 2,000 ms |
コード長 | 1,628 bytes |
コンパイル時間 | 2,201 ms |
コンパイル使用メモリ | 199,448 KB |
最終ジャッジ日時 | 2025-01-05 04:42:27 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>#define VARNAME(x) #x#define show(x) cerr << #x << " = " << x << endlusing namespace std;using ll = long long;template <typename T>ostream& operator<<(ostream& os, const vector<T>& v){os << "sz:" << v.size() << "\n[";for (const auto& p : v) {os << p << ",";}os << "]\n";return os;}template <typename S, typename T>ostream& operator<<(ostream& os, const pair<S, T>& p){os << "(" << p.first << "," << p.second<< ")";return os;}constexpr ll MOD = (ll)1e9 + 7LL;template <typename T>constexpr T INF = numeric_limits<T>::max() / 64;int main(){int N;cin >> N;vector<ll> d(N);vector<ll> odd;vector<ll> even;for (int i = 0; i < N; i++) {cin >> d[i];(d[i] % 2 == 0 ? even : odd).push_back(d[i]);}ll x, y;cin >> x >> y;const ll dist = abs(x) + abs(y);sort(d.begin(), d.end());sort(odd.begin(), odd.end());sort(even.begin(), even.end());if (dist == 0) {cout << 0 << endl;return 0;}for (int i = 0; i < N; i++) {if (d[i] == dist) {cout << 1 << endl;return 0;}}if (dist > 2 * d.back()) {cout << -1 << endl;return 0;} else if (dist % 2 == 0) {cout << 2 << endl;return 0;}for (const ll e : even) {if (upper_bound(odd.begin(), odd.end(), dist + e) - lower_bound(odd.begin(), odd.end(), abs(dist - e))) {cout << 2 << endl;return 0;}}cout << -1 << endl;return 0;}