結果
| 問題 | No.602 隠されていたゲーム2 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-12-02 00:38:35 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 689 bytes | 
| コンパイル時間 | 541 ms | 
| コンパイル使用メモリ | 58,216 KB | 
| 最終ジャッジ日時 | 2025-01-05 04:37:08 | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 WA * 5 | 
コンパイルメッセージ
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;
  for (int i = 0; i < n; ++i) {
    if (d[i] & 1) odd = d[i];
    else even = d[i];
  }
  for (int i = 0; i < n; ++i) {
    if (target == d[i]) {
      ret = 1;
      break;
    }
    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;
}
            
            
            
        