結果

問題 No.602 隠されていたゲーム2
ユーザー pekempeypekempey
提出日時 2017-12-02 00:44:18
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,427 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 77,772 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-15 23:57:37
合計ジャッジ時間 1,731 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
vector<int> even, odd;
for (int i = 0; i < n; i++) {
cin >> d[i];
if (d[i] % 2 == 0) {
even.push_back(d[i]);
} else {
odd.push_back(d[i]);
}
}
int x, y;
cin >> x >> y;
if (x == 0 && y == 0) {
cout << 0 << endl;
return 0;
}
int dist = abs(x) + abs(y);
for (int i = 0; i < n; i++) {
if (dist == d[i]) {
cout << 1 << endl;
return 0;
}
}
if (dist % 2 == 0) {
for (int i = 0; i < n; i++) {
if (dist <= d[i] * 2) {
cout << 2 << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
sort(even.begin(), even.end());
sort(odd.begin(), odd.end());
for (int i = 0; i < even.size(); i++) {
auto it = lower_bound(odd.begin(), odd.end(), even[i]);
if (it != odd.begin()) {
int j = it - odd.begin() - 1;
if (even[i] - odd[j] <= dist && dist <= even[i] + odd[j]) {
cout << 2 << endl;
return 0;
}
}
}
for (int i = 0; i < odd.size(); i++) {
auto it = lower_bound(even.begin(), even.end(), odd[i]);
if (it != even.begin()) {
int j = it - even.begin() - 1;
if (odd[i] - even[j] <= dist && dist <= odd[i] + even[j]) {
cout << 2 << endl;
return 0;
}
}
}
cout << -1 << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0