結果

問題 No.1149 色塗りゲーム
ユーザー freecss00freecss00
提出日時 2020-08-12 23:41:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 3,725 bytes
コンパイル時間 1,642 ms
コンパイル使用メモリ 177,196 KB
実行使用メモリ 24,348 KB
平均クエリ数 19.38
最終ジャッジ日時 2023-09-24 05:30:55
合計ジャッジ時間 7,742 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
23,508 KB
testcase_01 AC 41 ms
24,024 KB
testcase_02 AC 41 ms
23,964 KB
testcase_03 AC 41 ms
24,036 KB
testcase_04 AC 41 ms
23,988 KB
testcase_05 AC 42 ms
23,640 KB
testcase_06 AC 41 ms
24,024 KB
testcase_07 AC 42 ms
24,228 KB
testcase_08 AC 44 ms
23,364 KB
testcase_09 AC 41 ms
23,496 KB
testcase_10 AC 43 ms
23,604 KB
testcase_11 AC 43 ms
24,024 KB
testcase_12 AC 44 ms
23,376 KB
testcase_13 AC 44 ms
23,652 KB
testcase_14 AC 44 ms
24,348 KB
testcase_15 AC 43 ms
23,988 KB
testcase_16 AC 44 ms
23,976 KB
testcase_17 AC 44 ms
23,496 KB
testcase_18 AC 43 ms
23,772 KB
testcase_19 AC 44 ms
24,228 KB
testcase_20 AC 45 ms
23,760 KB
testcase_21 AC 44 ms
23,988 KB
testcase_22 AC 44 ms
23,820 KB
testcase_23 AC 45 ms
24,228 KB
testcase_24 AC 46 ms
23,592 KB
testcase_25 AC 46 ms
23,628 KB
testcase_26 AC 45 ms
23,760 KB
testcase_27 AC 46 ms
23,376 KB
testcase_28 AC 46 ms
24,240 KB
testcase_29 AC 47 ms
23,496 KB
testcase_30 AC 85 ms
23,412 KB
testcase_31 AC 82 ms
24,348 KB
testcase_32 AC 80 ms
23,364 KB
testcase_33 AC 85 ms
24,252 KB
testcase_34 AC 87 ms
24,048 KB
testcase_35 AC 87 ms
24,216 KB
testcase_36 AC 90 ms
24,024 KB
testcase_37 AC 94 ms
23,820 KB
testcase_38 AC 91 ms
24,216 KB
testcase_39 AC 95 ms
23,496 KB
testcase_40 AC 96 ms
23,976 KB
testcase_41 AC 100 ms
23,400 KB
testcase_42 AC 99 ms
23,664 KB
testcase_43 AC 104 ms
24,036 KB
testcase_44 AC 100 ms
23,352 KB
testcase_45 AC 101 ms
24,240 KB
testcase_46 AC 107 ms
24,240 KB
testcase_47 AC 106 ms
23,364 KB
testcase_48 AC 111 ms
23,520 KB
testcase_49 AC 112 ms
23,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    vi grundy(110);
    REP(i,1,110){
        set<int> tmp;
        if(i >= 1) tmp.insert(grundy[i-1]);
        if(i >= 2) tmp.insert(grundy[i-2]);
        REP(j,1,i-1){
            tmp.insert(grundy[j]^grundy[i-j-1]);
            tmp.insert(grundy[j]^grundy[i-j-2]);
        }
        rep(j,100){
            if(!tmp.count(j)){
                grundy[i] = j;
                break;
            }
        }
    }

    int n; cin >> n;
    vi color(n+1);
    color[n] = 1;
    while(1){
        int now = 0;
        vector<pii> stat;
        rep(i,n){
            if(!color[i]) REP(j,i+1,n+1){
                if(color[j]){
                    stat.emplace_back(i,j);
                    int m = j - i;
                    now ^= grundy[m];
                    i = j;
                    break;
                }
            }
        }

        int k=-1, x=-1;
        for(auto s : stat){
            int m = s.se - s.fi;
            if(m >= 1) if(grundy[m-1] == (now^grundy[m])){
                k = 1, x = s.fi;
                color[x] = 1;
                goto next;
            }
            if(m >= 2) if(grundy[m-2] == (now^grundy[m])){
                k = 2, x = s.fi;
                color[x] = 1; color[x+1] = 1;
                goto next;
            }
            REP(j,1,m-1){
                if((grundy[j]^grundy[m-j-1]) == (now^grundy[m])){
                    k = 1, x = s.fi+j;
                    color[x] = 1;
                    goto next;
                }
            }
            REP(j,1,m-2){
                if((grundy[j]^grundy[m-j-2]) == (now^grundy[m])){
                    k = 2, x = s.fi+j;
                    color[x] = 1; color[x+1] = 1;
                    goto next;
                }
            }
        }
        next:
        cout << k << " " << x+1 << endl;

        int t; cin >> t;
        if(t != 3) break;
        int tk,tx;
        cin >> tk >> tx;
        if(tk == 1){
            color[tx-1] = 1;
        }else{
            color[tx-1] = 1; color[tx] = 1;
        }
    }
    return 0;
}
0