結果
| 問題 |
No.602 隠されていたゲーム2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-02 00:40:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 687 bytes |
| コンパイル時間 | 626 ms |
| コンパイル使用メモリ | 58,736 KB |
| 最終ジャッジ日時 | 2025-01-05 04:37:33 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
7 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:10:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d", &d[i]);
| ~~~~~^~~~~~~~~~~~~
main.cpp:12:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <vector>
#include <algorithm>
int main() {
int n, x, y;
scanf("%d", &n);
std::vector<int> d(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &d[i]);
}
scanf("%d%d", &x, &y);
std::sort(d.begin(), d.end());
int ret = -1, target = std::abs(x) + std::abs(y);
int odd = 0, even = 0;
if (!target) ret = 0;
for (int i = 0; i < n && target; ++i) {
if (target == d[i]) {
ret = 1;
break;
}
if (d[i] & 1) odd = d[i];
else even = d[i];
int rest = std::abs(target - d[i]);
if (rest & 1) {
if (rest <= odd) ret = 2;
} else {
if (rest <= even) ret = 2;
}
}
printf("%d\n", ret);
return 0;
}