結果

問題 No.602 隠されていたゲーム2
ユーザー ミドリムシミドリムシ
提出日時 2017-12-02 07:07:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,066 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 78,892 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 00:27:30
合計ジャッジ時間 2,117 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int n;
    cin >> n;
    long move_mass[n];
    vector<long> even_odd[2];
    long number_max = 0;
    for(int i = 0; i < n; i++){
        cin >> move_mass[i];
        number_max = max(number_max, move_mass[i]);
        even_odd[move_mass[i] % 2].push_back(move_mass[i]);
    }
    int x, y;
    cin >> x >> y;
    long distance = abs(x) + abs(y);
    if(!distance){
        cout << 0 << endl;
        return 0;
    }
    sort(move_mass, move_mass + n);
    sort(even_odd[0].begin(), even_odd[0].end());
    sort(even_odd[1].begin(), even_odd[1].end());
    for(int i = 0; i < n; i++){
        if(move_mass[i] == distance){
            cout << 1 << endl;
            return 0;
        }
    }
    long min_difference = 0;
    int look_not_odd = 0;
    int look_odd = 0;
    int odd_break_point[even_odd[0].size()];
    for(int i = 0; i < even_odd[0].size(); i++){
        odd_break_point[i] = int(even_odd[1].size()) - 1;
    }
    while(look_not_odd != even_odd[0].size() && look_odd != even_odd[1].size()){
        min_difference = min(min_difference, abs(even_odd[0][look_not_odd] - even_odd[1][look_odd]));
        if(even_odd[0][look_not_odd] > even_odd[1][look_odd]){
            odd_break_point[look_odd] = look_not_odd;
            look_odd++;
        }else{
            look_not_odd++;
        }
    }
    if(distance % 2 == 0){
        if(number_max * 2 >= distance){
            cout << 2 << endl;
        }else{
            cout << -1 << endl;
        }
    }else if(even_odd[0].size() && even_odd[1].size()){
        for(int i = 0; i < even_odd[0].size(); i++){
            if(upper_bound(even_odd[1].begin() + odd_break_point[i], even_odd[1].end(), distance + even_odd[0][i]) -
               lower_bound(even_odd[1].begin() + odd_break_point[i], even_odd[1].end(), distance - even_odd[0][i])){
                cout << 2 << endl;
                return 0;
            }
        }
        cout << -1 << endl;
    }else{
        cout << -1 << endl;
    }
}
0