結果

問題 No.2521 Don't be Same
ユーザー milanis48663220milanis48663220
提出日時 2023-10-27 23:23:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 3,433 bytes
コンパイル時間 1,186 ms
コンパイル使用メモリ 121,640 KB
実行使用メモリ 24,588 KB
平均クエリ数 9.32
最終ジャッジ日時 2023-10-27 23:23:20
合計ジャッジ時間 5,053 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
24,576 KB
testcase_01 AC 65 ms
24,588 KB
testcase_02 AC 66 ms
24,588 KB
testcase_03 AC 65 ms
24,588 KB
testcase_04 AC 64 ms
24,588 KB
testcase_05 AC 66 ms
24,588 KB
testcase_06 AC 66 ms
24,588 KB
testcase_07 AC 66 ms
24,588 KB
testcase_08 AC 66 ms
24,588 KB
testcase_09 AC 70 ms
24,588 KB
testcase_10 AC 64 ms
24,588 KB
testcase_11 AC 64 ms
24,588 KB
testcase_12 AC 64 ms
24,588 KB
testcase_13 AC 64 ms
24,588 KB
testcase_14 AC 64 ms
24,588 KB
testcase_15 AC 64 ms
24,588 KB
testcase_16 AC 64 ms
24,588 KB
testcase_17 AC 62 ms
24,588 KB
testcase_18 AC 66 ms
24,588 KB
testcase_19 AC 64 ms
24,588 KB
testcase_20 AC 65 ms
24,588 KB
testcase_21 AC 65 ms
24,588 KB
testcase_22 AC 66 ms
24,588 KB
testcase_23 AC 66 ms
24,588 KB
testcase_24 AC 70 ms
24,588 KB
testcase_25 AC 67 ms
24,588 KB
testcase_26 AC 66 ms
24,588 KB
testcase_27 AC 69 ms
24,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

bool solve(int x, int y){
    static bool seen[1000][1000];
    static bool win[1000][1000];
    if(seen[x][y]) return win[x][y];
    if(x == y) return true;
    if(x == 0 || y == 0) return true;
    bool ans = false;
    for(int xx = 0; xx < x && !ans; xx++){
        if(!solve(xx, y)) {
            ans = true;
        }
    }
    for(int yy = 0; yy < y && !ans; yy++){
        if(!solve(x, yy)) {
            ans = true;
        }
    }

    seen[x][y] = true;
    win[x][y] = ans;
    return ans;
}

void test(){
    for(int x = 1; x <= 100; x++){
        for(int y = 1; y <= 100; y++){
            if(!solve(x, y)) cout << "lose:" << x << ' ' << y << endl;
        }
    }
    cout << "Done" << endl;
}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    vector<int> v(2);
    for(int i = 0; i < 2; i++) cin >> v[i];
    auto do_next = [&](){
        if(v[0] == v[1]){
            cout << "B" << endl;
            return;
        }
        if(v[0] == 0){
            cout << "A " << 2 << ' ' << v[1] << endl;
            return;
        }
        if(v[1] == 0){
            cout << "A " << 1 << ' ' << v[0] << endl;
            return;
        }
        int small_idx = v[0] < v[1] ? 0 : 1;
        int large_idx = small_idx^1;
        if(v[small_idx]%2 == 1){
            cout << "A " << large_idx+1 << ' ' << v[large_idx]-v[small_idx]-1 << endl;
            v[large_idx] = v[small_idx]+1;
        }else{
            cout << "A " << large_idx+1 << ' ' << v[large_idx]-v[small_idx]+1 << endl;
            v[large_idx] = v[small_idx]-1;
        }
    };
    auto do_opponent = [&](){
        string s; cin >> s;
        if(s == "A"){
            int i, x; cin >> i >> x; i--;
            v[i] -= x;
        }else if(s == "B"){
            v[0] = 0;
            v[1] = 0;
        }else{
            exit(0);
        }
    };
    bool first = true;
    if(abs(v[0]-v[1]) == 1){
        int mn = min(v[0], v[1]);
        if(mn%2 == 1){
            first = false;
        }
    }
    if(first) cout << "First" << endl;
    else{
        cout << "Second" << endl;
        do_opponent();
    }
    while(true){
        do_next();
        do_opponent();
        // cout << "v:"; print_vector(v);
    }
}
0