QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#321483#4207. Uplifting ExcursionZaunese0 0ms0kbC++141.8kb2024-02-04 20:26:552024-02-04 20:26:57

Judging History

你现在查看的是最新测评结果

  • [2024-02-04 20:26:57]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-02-04 20:26:55]
  • 提交

answer

#include <cstdio>
#include <vector>
#include <iostream>
using namespace std;
const int M = 605;
#define int long long
const int N = 150000;
const int inf = 1e18;
#define pb push_back
int read()
{
	int x=0,f=1;char c;
	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
int n,m,a[M],dp[2][2*N+5];vector<int> v[M];
signed main()
{
    freopen("goods.in","r",stdin);
    freopen("goods.out","w",stdout);
    n=read();m=read();
    for(int i=0;i<=(n<<1);i++)
    {
        a[i]=read();
        if(i==n) continue;
        for(int j=0;j<=40;j++) if((1ll<<j)<=a[i])
            v[j].pb(i-n),a[i]-=(1ll<<j);
        for(int j=40;j>=0;j--) if((1ll<<j)<=a[i])
            v[j].pb(i-n),a[i]-=(1ll<<j);
    }
    int e=0,t=1,L=N,R=N;dp[0][N]=inf;
    //都增加inf,这样0就相当于-inf
    for(int i=0;i<=40;i++)
    {
        for(int d:v[i])
        {
            e^=1;t^=1;
            int tl=min(L,max(0ll,L+d));
            int tr=max(R,min(2*N,R+d));
            for(int j=L;j<=R;j++) dp[e][j]=dp[t][j];
            for(int j=tl;j<L;j++) dp[e][j]=0;
            for(int j=R+1;j<=tr;j++) dp[e][j]=0;
            for(int j=L,k;j<=R;j++) if((k=j+d)>=0 && k<=2*N)
                dp[e][k]=max(dp[e][k],dp[t][j]+(1ll<<i));
            L=tl;R=tr;
        }
        e^=1;t^=1;
        for(int j=L;j<=R;j++) dp[e][j]=0;
        int tl=N,tr=N;
        for(int j=L,k;j<=R;j++) if((j&1)==(m>>i&1))
        {
            k=N+(j-N>>1);
            dp[e][k]=max(dp[e][k],dp[t][j]);
            tl=min(tl,k);tr=max(tr,k);
        }
        L=tl;R=tr;
    }
    if((m>>41)+N<L || (m>>41)+M>R || dp[e][(m>>41)+N]<inf)
        {puts("impossible");return 0;}
    printf("%lld\n",dp[e][(m>>41)+N]-inf+a[n]);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Dangerous Syscalls

Test #1:

score: 0
Dangerous Syscalls

input:

1 5
0 0 6

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Dangerous Syscalls

Test #19:

score: 0
Dangerous Syscalls

input:

30 38887954194235
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 444113827766 26 511237030935 22 696666627923 315938808146 20 952560827478 924020644151 850666790939 23 587888300072 23 797812801251 911390834853 677171102320 4 2 22 950650764450 278888113729 23 15 15 13 9 637120041802 20 1...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #5:

0%

Subtask #8:

score: 0
Skipped

Dependency #6:

0%

Subtask #9:

score: 0
Skipped

Dependency #7:

0%

Subtask #10:

score: 0
Skipped

Dependency #1:

0%