QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#198040#6130. Plants vs. ZombiesHarryJCompile Error//C++231.3kb2023-10-03 00:00:462023-10-03 00:00:47

Judging History

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

  • [2023-10-03 00:00:47]
  • 评测
  • [2023-10-03 00:00:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const int INF=0x3f3f3f3f;
const int N=1e5+10;
LL a[N],b[N];
LL n,m;

int check(LL x)
{
    // for(int i=1;i<=n;i++) b[i]=(x+a[i]-1)/a[i];
    
    // LL cnt=0;
    // LL last=0;
    
    // for(int i=1;i<=n;i++)
    // {
    //     if(b[i]>0) last=i;
        
    //     cnt++;
    //     b[i]--;
        
    //     if(b[i]>0)
    //     {
    //         cnt+=b[i]*2;
    //         b[i+1]-=b[i];
    //     }
    // }
    
    // cnt-=(n-last);
    
    // if(cnt<=m) return 1;
    // return 0;
    
    LL cnt=0;
    LL need=0;
    
	for(int i=1; i<=n; ++i)
	{
		LL need2=(x+A[i]-1)/A[i];
		need2-=need+1;
		if(need2<=0) i!=n?(--m):(!need2/*还需一步到n*/&&--m), need2=0;
		else cnt+=need2*2+1;
		//if(m<0) return 0;
		need=need2;
	}
	
	
	if(cnt<=m) return 1;
    return 0;
}

void solve()
{
    cin>>n>>m;
    
    for(int i=1;i<=n;i++) cin>>a[i];
    
    LL l=0,r=1e17;
    
    while(l<r)
    {
        LL mid=(l+r+1)/2;
        
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    
    cout<<l<<endl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int tt; cin>>tt;
    
    while(tt--) solve();
    
    return 0;
}

Details

answer.code: In function ‘int check(LL)’:
answer.code:43:29: error: ‘A’ was not declared in this scope
   43 |                 LL need2=(x+A[i]-1)/A[i];
      |                             ^