結果

問題 No.602 隠されていたゲーム2
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-10-13 16:19:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,614 bytes
コンパイル時間 1,708 ms
コンパイル使用メモリ 171,128 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-02 19:57:03
合計ジャッジ時間 3,033 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 14 ms
4,380 KB
testcase_19 AC 18 ms
4,376 KB
testcase_20 AC 18 ms
4,376 KB
testcase_21 AC 12 ms
4,380 KB
testcase_22 AC 13 ms
4,376 KB
testcase_23 AC 13 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/





int N, D[101010], X, Y;
//---------------------------------------------------------------------------------------------------
int check(int d1, int d2, int ma, int mi) {
    int a = min(d1, d2);
    int b = max(d1, d2);

    if (a + ma < b) return 0;
    if (a + b < mi) return 0;
    return 1;
}
//---------------------------------------------------------------------------------------------------
int solve() {
    if (X == 0 and Y == 0) return 0;
    rep(i, 0, N) if (D[i] == abs(X) + abs(Y)) return 1;

    int dx = abs(X + Y);
    int dy = abs(X - Y);
    int ma = max(dx, dy);
    int mi = min(dx, dy);

    if ((X + Y) % 2 == 0) {
        rep(i, 0, N) if (ma <= D[i]) return 2;
        rep(i, 0, N) if (ma <= D[i] * 2) return 2;
    } else {
        vector<int> odd;
        rep(i, 0, N) if (D[i] % 2 == 1) odd.push_back(D[i]);
        sort(all(odd));
        rep(i, 0, N) if(D[i] % 2 == 0) {
            int j = lower_bound(all(odd), D[i] - ma) - odd.begin();
            if (j < odd.size() and check(D[i], odd[j], ma, mi)) return 2;
            if (0 <= j - 1 and check(D[i], odd[j - 1], ma, mi)) return 2;
        }
    }

    return -1;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    while (cin >> N) {
        rep(i, 0, N) cin >> D[i];
        cin >> X >> Y;

        cout << solve() << endl;
    }
}
0