QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#487960 | #6642. (1, 2) Nim | ucup-team052# | TL | 0ms | 0kb | C++23 | 2.6kb | 2024-07-23 14:13:52 | 2024-07-23 14:13:52 |
answer
#include<bits/stdc++.h>
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ "="),debug_helper::debug(__VA_ARGS__),D("\n")
#include"/home/xay5421/debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define each(x,v) for(auto&x:v)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
template<class T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<class T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
using namespace std;
using LL=long long;
using ULL=unsigned long long;
const int P=1e9+7;
int ad(int k1,int k2){return k1+k2>=P?k1+k2-P:k1+k2;}
int su(int k1,int k2){return k1-k2<0?k1-k2+P:k1-k2;}
int mu(int k1,int k2){return 1ULL*k1*k2%P;}
void uad(int&k1,int k2){(k1+=k2)>=P&&(k1-=P);}
void usu(int&k1,int k2){(k1-=k2)<0&&(k1+=P);}
template<class... T>int ad(int k1,T... k2){return ad(k1,ad(k2...));}
template<class... T>int su(int k1,T... k2){return su(k1,ad(k2...));}
template<class... T>int mu(int k1,T... k2){return mu(k1,mu(k2...));}
template<class... T>void uad(int&k1,T... k2){return uad(k1,ad(k2...));}
template<class... T>void usu(int&k1,T... k2){return usu(k1,ad(k2...));}
int po(int k1,int k2){
int k3=1;
for(;k2;k2>>=1,k1=mu(k1,k1))if(k2&1)k3=mu(k3,k1);
return k3;
}
const int N=1000005;
int T,n,m,K,a[N],dp[N],val[N],suf[N];
bool check(int mid){
rep(i,1,n){
if(mid==0){
val[i]=dp[a[i]+1];
}else{
val[i]=dp[(a[i]+mid-1)/mid];
}
}
nth_element(val+1,val+(n+1)/2,val+n+1);
LL cur=0;
rep(i,1,(n+1)/2){
cur+=val[i];
if(cur>K)return 0;
}
return 1;
}
int main(){
#ifdef xay5421
freopen("a.in","r",stdin);
#endif
rd(T);
while(T--){
rd(n),rd(m),rd(K);
rep(i,1,n)rd(a[i]);
rep(i,1,m)rd(dp[i]);
dp[m+1]=2e9;
per(i,m,1){
dp[i]=min(dp[i],dp[i+1]);
}
rep(i,1,m+1){
rep(j,1,(m+1)/i){
dp[i*j]=min(dp[i*j],dp[i]+dp[j]);
}
}
suf[m+1]=dp[m+1];
per(i,m+1,1){
suf[i]=min(suf[i+1],dp[i]);
}
int w=2e9;
rep(i,1,m+1){
w=min(w,dp[i]+dp[(m+i)/i]);
}
per(i,m+1,1){
dp[i]=min(dp[i],w);
}
per(i,m,1){
dp[i]=min(dp[i],dp[i+1]);
}
rep(i,1,m+1)D("%d ",dp[i]);
D("\n");
int l=0,r=m,ans=m;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)){
r=mid-1;
ans=mid;
}else{
l=mid+1;
}
}
printf("%d\n",ans);
}
return 0;
}
/*
2 2 4 4 6 6
5
2 2 4 4 6 6
5
2 2 4 4 6 6
1
*/
详细
Test #1:
score: 0
Time Limit Exceeded
input:
3 2 1 2 1 5 4 1 7 2 9