CF2157B Expansion Plan 2
发现操作\(4\)和操作\(8\)可以交换,考虑把操作序列变成形如\(888\dots 444\dots\) \((\)一些\(8\)加一些\(4\)\()\)的形式。设有\(a\)个\(4\),\(b\)个\(8\)。如果存在点\((x',y')\)满足\(|x'-x|+|y'-y|\le b\&\&\max(|x'|,|y'|)\le a\)答案为\(YES\)否则答案为\(NO\)
代码
#include<bits/stdc++.h>
using namespace std;
namespace IO{
template<typename T>
inline void read(T&x){
x=0;char c=getchar();bool f=0;
while(!isdigit(c)) c=='-'?f=1:0,c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
f?x=-x:0;
}
template<typename T>
inline void write(T x){
if(x==0){putchar('0');return ;}
x<0?x=-x,putchar('-'):0;short st[50],top=0;
while(x) st[++top]=x%10,x/=10;
while(top) putchar(st[top--]+'0');
}
inline void read(char&c){c=getchar();while(isspace(c)) c=getchar();}
inline void write(char c){putchar(c);}
inline void read(string&s){s.clear();char c;read(c);while(!isspace(c)&&~c) s+=c,c=getchar();}
inline void write(string s){for(int i=0,len=s.size();i<len;i++) putchar(s[i]);}
template<typename T>inline void write(T*x){while(*x) putchar(*(x++));}
template<typename T,typename...T2> inline void read(T&x,T2&...y){read(x),read(y...);}
template<typename T,typename...T2> inline void write(const T x,const T2...y){write(x),putchar(' '),write(y...),sizeof...(y)==1?putchar('\n'):0;}
}using namespace IO;
void solve(){
string s;int n,x,y,g1=0,g2=0;read(n,x,y,s);x=max(x,-x),y=max(y,-y);
for(int i=0;i<n;i++) if(s[i]=='4') g1++;else g2++;
while(g1--) if(x>y) x--;else y--;
if(max(x,y)<=g2) write("YES\n");
else write("NO\n");
}
signed main(){
int T;read(T);
while(T--) solve();
return 0;
}

浙公网安备 33010602011771号