This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
typedef long long lld;
 
int N, M, K;
lld A[21], G[21];
vector <lld> P, Q;
vector <int> C;
 
inline lld invalid(lld n)
{
    return C[n];
}
 
inline lld get_grundy(lld n)
{
    if (!n) return 0;
    lld me = invalid(n), you = invalid(n-1);
    return me > you ? 0 : (n - me);
}
 
int main()
{
    scanf("%d%d%d", &N, &M, &K);
    for (int i=0;i<N;i++){
        lld x; scanf("%lld", &x); P.pb(x);
    }
    for (int i=0;i<M;i++){
        lld x; scanf("%lld", &x); Q.pb(x);
    }
    int V = 0;
    for (int i=1;i<=K;i++){
        scanf("%lld", A+i);
        V = max(V, (int)A[i]);
    }
    C.resize(V+1, 0);
    for (int i=1;i<=V;i++){
        C[i] = C[i-1];
        bool sw = 0;
        for (int j=0;j<N;j++){
            if (i % P[j] == 0) sw = 1;
        }
        bool sw2 = 1;
        for (int j=0;j<M;j++){
            if (i % Q[j] == 0) sw2 = 0;
        }
        if (sw || sw2) C[i]++;
    }
    lld x = 0;
    for (int i=1;i<=K;i++){
        G[i] = get_grundy(A[i]);
        x ^= G[i];
    }
    for (int i=1;i<=K;i++){
        if (!G[i]){ puts("0 0"); continue; }
        lld ox = x ^ G[i];
        lld p = 0, q = 0;
        for (int j=0;j<A[i];j++) if (get_grundy(j) == ox) p++, q = A[i] - j;
        printf("%lld %lld\n", p, q);
    }
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |