首先是都用了的快读快写
inline int read(){
char ch=getchar();int s=0,w=1;
while(ch<48||ch>57){if(ch=='-')w=-1;ch=getchar();}
while(ch>=48&&ch<=57){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}
return s*w;
}
inline void write(int x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
}
CF1644A Doors and Keys
主要就是对应的小写字母要在大写字母前面
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
int t;
t=read();
while(t--){
cin>>s;
bool check=true;
for(int i=0;i<6;i++)
if(isupper(s[i]))for(int j=i+1;j<6;j++)
if(s[i]-s[j]=='A'-'a'){check=false;break;}
if(check)printf("YES\n");
else printf("NO\n");
}
}
CF1644B Anti-Fibonacci Permutation
运用prev_permutation,注意如果用next_permutation会超时
#include<bits/stdc++.h>
using namespace std;
int a[52],t,n,cnt;bool check;
int main(){
t=read();
while(t--){
n=read();
for(int i=0;i<n;i++)a[i]=n-i;
while(prev_permutation(a,a+n) && cnt<n){
check=true;
for(int i=2;i<n;i++)if(a[i]==a[i-1]+a[i-2]){check=false;break;}
if(check){
for(int i=0;i<n;i++){printf("%d ",a[i]);}
putchar('\n'); cnt++;
}
}
}
}
CF1644C Increase Subarray Sums
首先用sub[i]记录长度为i的连续区间的最大区间和
然后开始放置x,每次给sub[k]-----sub[n]加x,区间长小于k的是没办法加x的
因为加x的位置要求不同
#include<bits/stdc++.h>
using namespace std;
int a[5010],t,n,x,b,sub[5010];
int main(){
t=read();
while(t--){
n=read(),x=read();
for(int i=0;i<n;i++){a[i]=read();}
for(int i=1;i<=n;i++){//i表示区间长度
int sum=0;
for(int j=0;j<i;j++){sum+=a[j];}
int maxn=sum;
for(int j=i;j<n;j++){
sum+=a[j]-a[j-i];
maxn=max(sum,maxn);
}
sub[i]=maxn;
}
//注意到sub[i]的区间最多加2i
int maxn=sub[0];
for(int p=1;p<=n;p++)
maxn=max(maxn,sub[p]);
write(maxn); putchar(' ');
for(int k=1;k<=n;k++){
for(int p=k;p<=n;p++){sub[p]+=x;}
for(int p=k;p<=n;p++)
maxn=max(maxn,sub[p]);
write(maxn);putchar(' ');
}
putchar('\n');
}
}
CF1644D Cross Coloring
由于题目后面会涂色会覆盖前面,那么不妨从后考虑
如果一次有效涂色对结果的影响是×颜色种类数(因为那次涂色有k种颜色可以选)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll p=998244353;
int main(){
int t;
scanf("%d",&t);
while(t--){
ll ans=1,n,m,k,q;
set<ll> is_x,is_y;//记录涂色的行列
scanf("%lld%lld%lld%lld",&n,&m,&k,&q);
vector<ll> x(q),y(q);
for(int i=0;i<q;i++){scanf("%lld%lld",&x[i],&y[i]);}
//注意这里判断涂满了的情况
for(int i=q-1;i>=0;i--){
bool check=0;
if(!is_x.count(x[i])) is_x.insert(x[i]),check=1;
if(!is_y.count(y[i])) is_y.insert(y[i]),check=1;
if(check)ans=ans*k%p;
if(is_x.size()==n || is_y.size()==m)break;
}
printf("%lld\n",ans);
}
}