結果

問題 No.602 隠されていたゲーム2
ユーザー mamekinmamekin
提出日時 2018-01-13 01:06:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,363 bytes
コンパイル時間 1,042 ms
コンパイル使用メモリ 110,036 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 15:59:07
合計ジャッジ時間 2,856 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int solve(const vector<int>& v, int dist)
{
    if(dist == 0)
        return 0;
    if(find(v.begin(), v.end(), dist) != v.end())
        return 1;

    vector<vector<int> > v2(2);
    for(int a : v)
        v2[a%2].push_back(a);
    for(int i=0; i<2; ++i)
        sort(v2[i].begin(), v2[i].end());

    for(int i=0; i<2; ++i){
        int j = (dist - i) % 2;
        int k = v2[j].size() - 1;
        for(int a : v2[i]){
            while(k >= 0 && v2[j][k] > a + dist)
                -- k;
            if(k >= 0){
                int b = v2[j][k];
                if(dist <= a + b && abs(a - b) <= dist)
                    return 2;
            }
        }
    }
    return -1;
}

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; ++i)
        cin >> v[i];

    int x, y;
    cin >> x >> y;
    int dist = abs(x) + abs(y);

    cout << solve(v, dist) << endl;

    return 0;
}
0