Submission #15302

# Submission time Handle Problem Language Result Execution time Memory
15302 2015-07-12T05:31:50 Z gs13068 로봇 심판의 님 게임 (kriii3_F) C++
79 / 79
694 ms 2124 KB
#include<cstdio>
#include<algorithm>

long long a[22],b[22],c[22],d[66666],s[66666];
int p[22],q[22],pn,qn;

long long gcd(long long a,long long b)
{
    return a?gcd(b%a,a):b;
}

long long lcm(long long a,long long b)
{
    long long g = gcd(a,b);
    if(std::min(a,b)/g>1000000)return 1e12+1;
    a*=b/g;
    return a<1e12+1?a:1e12+1;
}

long long togrundy(long long x)
{
    int i;
    long long r=0;
    for(i=0;i<(1<<(pn+qn));i++)if(i&((1<<qn)-1))
    {
        if(s[i]%2)r+=x/d[i];
        else r-=x/d[i];
    }
    return r;
}

long long tonumber(long long x)
{
    long long l=0,r=1e12,mid;
    while(l<r)
    {
        mid=(l+r)/2;
        if(togrundy(mid)<x)l=mid+1;
        else r=mid;
    }
    return l;
}

long long tonumber2(long long x)
{
    long long l=0,r=1e12,mid;
    while(l<r)
    {
        mid=(l+r)/2;
        if(mid-togrundy(mid)<x)l=mid+1;
        else r=mid;
    }
    return l;
}

int main()
{
    long long xo=0;
    int i,j,k,l,n;
    scanf("%d%d%d",&pn,&qn,&n);
    for(i=0;i<pn;i++)scanf("%d",&p[i]);
    for(i=0;i<qn;i++)scanf("%d",&q[i]);
    for(i=0;i<(1<<pn);i++)for(j=1;j<(1<<qn);j++)
    {
        d[(i<<qn)|j]=1;
        s[(i<<qn)|j]=0;
        for(k=0;k<pn;k++)if((i>>k)&1)
        {
            s[(i<<qn)|j]++;
            d[(i<<qn)|j]=lcm(d[(i<<qn)|j],p[k]);
        }
        for(l=0;l<qn;l++)if((j>>l)&1)
        {
            s[(i<<qn)|j]++;
            d[(i<<qn)|j]=lcm(d[(i<<qn)|j],q[l]);
        }
    }
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        for(j=0;j<pn;j++)if(a[i]%p[j]==0)break;
        if(j<pn)
        {
            a[i]=0;
            continue;
        }
        for(k=0;k<qn;k++)if(a[i]%q[k]==0)break;
        if(k==qn)
        {
            a[i]=0;
            continue;
        }
        b[i]=togrundy(a[i]);
        xo^=b[i];
    }
    for(i=0;i<n;i++)
    {
        if((b[i]^xo)<b[i])
        {
            if(b[i]^xo)
            {
                c[i]=tonumber(b[i]^xo);
                printf("1 %lld\n",a[i]-c[i]);
            }
            else
            {
                c[i]=tonumber2(a[i]-b[i]);
                printf("%lld %lld\n",a[i]-b[i]+1,a[i]-c[i]);
            }
        }
        else puts("0 0");
    }
}
# Verdict Execution time Memory Grader output
1 Correct 597 ms 2124 KB Output is correct
2 Correct 687 ms 2124 KB Output is correct
3 Correct 533 ms 2124 KB Output is correct
4 Correct 526 ms 2124 KB Output is correct
5 Correct 512 ms 2124 KB Output is correct
6 Correct 499 ms 2124 KB Output is correct
7 Correct 375 ms 2124 KB Output is correct
8 Correct 377 ms 2124 KB Output is correct
9 Correct 538 ms 2124 KB Output is correct
10 Correct 446 ms 2124 KB Output is correct
11 Correct 59 ms 2124 KB Output is correct
12 Correct 309 ms 2124 KB Output is correct
13 Correct 317 ms 2124 KB Output is correct
14 Correct 272 ms 2124 KB Output is correct
15 Correct 296 ms 2124 KB Output is correct
16 Correct 383 ms 2124 KB Output is correct
17 Correct 256 ms 2124 KB Output is correct
18 Correct 394 ms 2124 KB Output is correct
19 Correct 447 ms 2124 KB Output is correct
20 Correct 595 ms 2124 KB Output is correct
21 Correct 361 ms 2124 KB Output is correct
22 Correct 363 ms 2124 KB Output is correct
23 Correct 368 ms 2124 KB Output is correct
24 Correct 415 ms 2124 KB Output is correct
25 Correct 572 ms 2124 KB Output is correct
26 Correct 140 ms 2124 KB Output is correct
27 Correct 694 ms 2124 KB Output is correct
28 Correct 392 ms 2124 KB Output is correct
29 Correct 542 ms 2124 KB Output is correct
30 Correct 310 ms 2124 KB Output is correct
31 Correct 0 ms 2124 KB Output is correct
32 Correct 0 ms 2124 KB Output is correct
33 Correct 0 ms 2124 KB Output is correct
34 Correct 0 ms 2124 KB Output is correct
35 Correct 0 ms 2124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2124 KB Output is correct
2 Correct 0 ms 2124 KB Output is correct
3 Correct 31 ms 2124 KB Output is correct
4 Correct 522 ms 2124 KB Output is correct
5 Correct 417 ms 2124 KB Output is correct
6 Correct 378 ms 2124 KB Output is correct
7 Correct 539 ms 2124 KB Output is correct
8 Correct 309 ms 2124 KB Output is correct
9 Correct 306 ms 2124 KB Output is correct
10 Correct 274 ms 2124 KB Output is correct