結果
| 問題 |
No.602 隠されていたゲーム2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-17 18:02:11 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 1,349 bytes |
| コンパイル時間 | 691 ms |
| コンパイル使用メモリ | 70,112 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-16 00:07:20 |
| 合計ジャッジ時間 | 1,744 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:16:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:20:14: 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:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
#define PRINT(x) { std::cout << #x << ": " << x << std::endl; }
//#define PRINT(x)
int main(int argc, char *argv[])
{
int n;
scanf("%d", &n);
vector<int> d(n);
for (int i = 0; i < n; ++i)
{
scanf("%d", &d[i]);
}
int x, y;
scanf("%d %d", &x, &y);
if (x == 0 && y == 0)
{
puts("0");
return 0;
}
int D = abs(x) + abs(y);
vector<int>::iterator match_D = find(d.begin(),
d.end(),
D);
if (match_D != d.end())
{
puts("1");
return 0;
}
if (D % 2 == 0)
{
int max_d = *max_element(d.begin(), d.end());
puts((2 * max_d >= D) ? "2" : "-1");
return 0;
}
else
{
sort(d.begin(), d.end());
int odd = -1, even = -1;
for (int i = 0; i < n; ++i)
{
if (d[i] % 2 == 0) odd = d[i];
else even = d[i];
if (odd == -1 || even == -1) continue;
if (abs(odd - even) <= D && D <= odd + even)
{
puts("2");
return 0;
}
}
}
puts("-1");
return 0;
}