Submission #974255

# Submission time Handle Problem Language Result Execution time Memory
974255 2024-05-03T06:53:35 Z sleepntsheep Bitwise (BOI06_bitwise) C
100 / 100
1 ms 348 KB
#include<stdio.h>

#define N 10000
int lena[N],n,p,k[N],at[N+1];long long z,l[N],r[N];

int main()
{
    scanf("%d%d",&n,&p);
    for(int i=0;i<p;++i)
        scanf("%d",k+i);
    for(int i=0,len=0;i<p;++i)
    {
        at[i]=len;
        at[i+1]=len+=k[i];
        for(int j=at[i];j<at[i+1];++j)
            scanf("%lld%lld",l+j,r+j);
    }

    for(long long b=30;b>=0;--b)
    {
        long long set=1ll<<b;
        int ok=1;
        for(int i=0;i<p;++i)
        {
            if(lena[i])continue;
            int can=0;
            for(int j=at[i];j<at[i+1];++j) can+=(set<=r[j]);
            if(can==0) ok=0;
        }
        for(int i=0;i<p;++i)
        {
            int tuna=0,salmon=0;
            for(int j=at[i];j<at[i+1];++j)
            {
                salmon+=r[j]>=set;
                tuna+=r[j]>=set&&l[j]<set;
            }

            if(tuna&&(!ok||salmon>1))
            {
                lena[i]=1;
                continue;
            }

            for(int j=at[i];j<at[i+1];++j)
                if(r[j]>=set)
                {
                    r[j]-=set;
                    l[j]-=set;
                }
        }

        if(ok)
            z|=set;

        //printf(" After bit %d\n",b); for(int j=0;j<n;++j)printf(" [%lld %lld]\n",l[j],r[j]);
    }
    printf("%lld",z);
}

Compilation message

bitwise.c: In function 'main':
bitwise.c:8:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     scanf("%d%d",&n,&p);
      |     ^~~~~~~~~~~~~~~~~~~
bitwise.c:10:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         scanf("%d",k+i);
      |         ^~~~~~~~~~~~~~~
bitwise.c:16:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |             scanf("%lld%lld",l+j,r+j);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct