QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#344870#3811. Game of CardsKhNURE_KIVI#AC ✓11ms3888kbC++232.2kb2024-03-05 16:48:482024-03-05 16:48:48

Judging History

This is the latest submission verdict.

  • [2024-03-05 16:48:48]
  • Judged
  • Verdict: AC
  • Time: 11ms
  • Memory: 3888kb
  • [2024-03-05 16:48:48]
  • Submitted

answer

//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")

#include <bits/stdc++.h>

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

template<typename T>
bool umin(T &a, T b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool umax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#ifdef KIVI
#define DEBUG for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl

template<class ...Ts>
auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }

#else
#define DEBUG while (false)
#define LOG(...)
#endif

mt19937 rng(4242);

const int max_n = -1, inf = 1000111222;

int get_mex(vector<int>& a) {
    int am = len(a) + 3;
    vector<int> have(am);
    for(auto& x : a) if(x < am) have[x] = 1;
    int mex = 0;
    while(have[mex]) mex++;
    return mex;
}

void solve() {
    int p, k;
    cin >> p >> k;
    int ans = 0;
    for(int i = 0; i < p; i++) {
        int n; cin >> n;
        vector<int> c(n + 1);
        for(int j = 1; j <= n; j++) cin >> c[j];
        vector<int> state(n + 1);
        for(int j = 1; j <= n; j++) {
            vector<int> transitions;
            for(int take_top = 0; take_top <= k && take_top < j; take_top++) {
                int card = c[j - take_top];
                if(j - take_top - card >= 0) transitions.pb(state[j - take_top - card]);
            }
            state[j] = get_mex(transitions);
        }
        ans ^= state[n];
    }
    if(!ans) cout << "Bob will win.";
    else cout << "Alice can win.";
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;

//    cin >> t;

    while (t--) solve();

}

/*
KIVI
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

2 2
1 3
2 1 1

output:

Alice can win.

result:

ok single line: 'Alice can win.'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3588kb

input:

2 10
1000 10 1 5 8 10 6 4 7 2 6 2 4 7 4 4 3 2 8 5 2 5 7 10 3 2 5 8 4 6 9 5 3 7 6 9 6 6 4 5 10 3 6 10 9 5 5 1 4 8 3 1 10 6 3 4 1 10 8 6 9 3 3 10 3 7 8 9 7 3 6 9 9 3 7 10 2 5 2 9 1 5 7 10 4 9 8 10 5 6 1 9 9 1 7 2 6 4 1 8 7 5 6 2 5 5 4 9 3 7 7 10 5 2 4 8 8 7 7 2 2 4 8 1 3 2 7 9 10 1 6 7 1 5 2 3 10 7 4 ...

output:

Bob will win.

result:

ok single line: 'Bob will win.'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3824kb

input:

10 1
1000 3 5 4 3 8 4 4 4 6 8 2 8 6 2 5 1 5 10 5 10 7 8 10 4 2 3 8 7 8 2 9 8 5 7 10 2 7 8 9 8 1 1 2 3 9 10 5 7 3 4 2 3 4 1 7 5 7 2 5 8 3 4 7 1 5 8 4 5 1 10 5 6 7 5 7 3 10 6 6 4 4 2 6 6 3 3 4 3 6 7 10 5 4 8 4 7 6 2 10 9 2 4 3 10 2 7 1 4 6 6 7 1 9 1 3 4 4 3 5 2 10 3 4 2 4 4 8 5 2 2 3 1 5 4 3 9 1 8 9 9...

output:

Alice can win.

result:

ok single line: 'Alice can win.'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3568kb

input:

11 1
1000 3 5 4 3 8 4 4 4 6 8 2 8 6 2 5 1 5 10 5 10 7 8 10 4 2 3 8 7 8 2 9 8 5 7 10 2 7 8 9 8 1 1 2 3 9 10 5 7 3 4 2 3 4 1 7 5 7 2 5 8 3 4 7 1 5 8 4 5 1 10 5 6 7 5 7 3 10 6 6 4 4 2 6 6 3 3 4 3 6 7 10 5 4 8 4 7 6 2 10 9 2 4 3 10 2 7 1 4 6 6 7 1 9 1 3 4 4 3 5 2 10 3 4 2 4 4 8 5 2 2 3 1 5 4 3 9 1 8 9 9...

output:

Bob will win.

result:

ok single line: 'Bob will win.'

Test #5:

score: 0
Accepted
time: 9ms
memory: 3600kb

input:

99 10
1000 5 6 1 4 8 9 4 2 10 9 7 9 9 4 10 6 8 9 4 9 6 4 1 8 5 5 1 2 3 5 3 1 6 1 4 3 8 5 8 5 8 5 5 7 1 7 5 3 9 4 4 4 9 6 7 6 5 9 1 7 10 2 5 1 5 8 5 1 1 4 8 3 3 4 7 5 7 4 9 6 3 10 2 1 6 10 2 10 10 1 7 4 1 2 8 7 10 9 1 2 3 7 10 3 10 1 4 7 5 1 2 3 3 4 6 10 3 2 1 5 9 4 3 5 3 5 2 3 1 5 8 2 8 10 7 2 10 5 ...

output:

Alice can win.

result:

ok single line: 'Alice can win.'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

4 2
20 9 4 9 6 4 8 3 2 8 5 8 4 9 7 7 6 7 8 6 7
20 8 1 5 2 6 3 2 8 8 10 6 3 10 5 5 7 5 6 9 3
20 2 6 10 7 4 7 5 8 1 3 7 7 7 10 6 2 7 7 1 2
20 5 4 9 10 9 1 5 8 9 1 7 3 6 9 8 3 4 5 4 6

output:

Alice can win.

result:

ok single line: 'Alice can win.'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

5 2
20 9 4 9 6 4 8 3 2 8 5 8 4 9 7 7 6 7 8 6 7
20 8 1 5 2 6 3 2 8 8 10 6 3 10 5 5 7 5 6 9 3
20 2 6 10 7 4 7 5 8 1 3 7 7 7 10 6 2 7 7 1 2
20 5 4 9 10 9 1 5 8 9 1 7 3 6 9 8 3 4 5 4 6
4 4 3 2 1

output:

Bob will win.

result:

ok single line: 'Bob will win.'

Test #8:

score: 0
Accepted
time: 11ms
memory: 3548kb

input:

99 10
1000 2 9 8 3 5 5 7 8 1 1 9 5 8 1 5 8 3 10 10 1 1 6 10 4 3 5 1 3 5 5 3 3 3 5 3 1 9 6 7 2 10 9 2 4 8 8 10 5 9 7 4 6 9 9 6 6 1 3 8 5 2 6 8 7 4 5 6 8 6 4 5 1 1 8 10 6 4 2 6 10 8 6 9 3 6 10 6 5 3 6 10 1 8 9 9 8 9 6 6 5 1 9 6 2 6 5 4 4 6 7 7 5 1 3 2 6 9 8 8 9 3 9 7 1 1 1 8 3 2 7 4 1 2 6 2 3 8 5 4 5 ...

output:

Alice can win.

result:

ok single line: 'Alice can win.'

Test #9:

score: 0
Accepted
time: 7ms
memory: 3888kb

input:

100 10
1000 2 9 8 3 5 5 7 8 1 1 9 5 8 1 5 8 3 10 10 1 1 6 10 4 3 5 1 3 5 5 3 3 3 5 3 1 9 6 7 2 10 9 2 4 8 8 10 5 9 7 4 6 9 9 6 6 1 3 8 5 2 6 8 7 4 5 6 8 6 4 5 1 1 8 10 6 4 2 6 10 8 6 9 3 6 10 6 5 3 6 10 1 8 9 9 8 9 6 6 5 1 9 6 2 6 5 4 4 6 7 7 5 1 3 2 6 9 8 8 9 3 9 7 1 1 1 8 3 2 7 4 1 2 6 2 3 8 5 4 5...

output:

Bob will win.

result:

ok single line: 'Bob will win.'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

2 1
1 1
1 1

output:

Bob will win.

result:

ok single line: 'Bob will win.'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

2 2
5 3 2 1 2 1
5 5 4 3 2 1

output:

Alice can win.

result:

ok single line: 'Alice can win.'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

4 1
4 1 1 1 1
6 2 1 2 1 2 1
4 1 1 1 1
6 2 1 2 1 2 1

output:

Bob will win.

result:

ok single line: 'Bob will win.'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

2 1
3 2 1 2
3 2 1 2

output:

Bob will win.

result:

ok single line: 'Bob will win.'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

2 1
1 1
3 1 2 1

output:

Alice can win.

result:

ok single line: 'Alice can win.'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

3 2
4 4 7 1 8
4 4 8 4 6
4 10 1 6 1

output:

Alice can win.

result:

ok single line: 'Alice can win.'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

3 3
4 5 9 8 1
4 1 10 4 4
4 5 9 10 4

output:

Alice can win.

result:

ok single line: 'Alice can win.'

Test #17:

score: 0
Accepted
time: 1ms
memory: 3656kb

input:

1 10
1000 10 1 5 8 10 6 4 7 2 6 2 4 7 4 4 3 2 8 5 2 5 7 10 3 2 5 8 4 6 9 5 3 7 6 9 6 6 4 5 10 3 6 10 9 5 5 1 4 8 3 1 10 6 3 4 1 10 8 6 9 3 3 10 3 7 8 9 7 3 6 9 9 3 7 10 2 5 2 9 1 5 7 10 4 9 8 10 5 6 1 9 9 1 7 2 6 4 1 8 7 5 6 2 5 5 4 9 3 7 7 10 5 2 4 8 8 7 7 2 2 4 8 1 3 2 7 9 10 1 6 7 1 5 2 3 10 7 4 ...

output:

Alice can win.

result:

ok single line: 'Alice can win.'