Start:May/08/2023 20:05UTC+8
Length:02:00
这次总该上分了吧
A LuoTianyi and the Palindrome String
1 s, 256 MB x8531
都一样是-1,普通回文是size()-1
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fer(i,a,b) for(int i=a;i<b;i++)
#define cf int T;cin>>T;while(T--)
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=2e5+1,mod=1e9+7;
string s;
bool check(){
char t=s[0];
fer(i,1,s.size()){
if(s[i]!=t)return 0;
}
return 1;
}
signed main(){
IOS;
cf{
cin>>s;
int res=-1;
if(check()==1)cout<<-1<<endl;
else cout<<s.size()-1<<endl;
}
return 0;
}
B LuoTianyi and the Table
1 s, 256 MB x6141
思路是(1,1)放最小值,(1,2)放最大值,(2,1)放次大值
或者(1,1)放最大值,(1,2)放最小值,(2,1)放次小值
max1,2,3就是干这个用的,但不用真的去放
cf{
int n,m;cin>>n>>m;
int a[n*m];fer(i,0,n*m)cin>>a[i];
sort(a,a+n*m);
int max1=a[n*m-1]-a[0];
int max2=a[n*m-1]-a[1];
int max3=a[n*m-2]-a[0];
max2=max(max2,max3);
if(n>m)swap(n,m);//n<m
int res=max1*n*(m-1)+max2*(n-1);
cout<<res<<endl;
}
C LuoTianyi and the Show
2 s, 256 MB x2679
暴力是永恒的解题方法
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fer(i,a,b) for(int i=a;i<b;i++)
#define cf int T;cin>>T;while(T--)
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=1e5+1,mod=1e9+7;
int a[N],b[N+1],c[N],d[N];//b是座位从左向右的间隔,c是b的前缀和,d是后缀和
signed main(){
IOS;
cf{
int n,m;cin>>n>>m;
int left=0,right=0;
set<int> people;
fer(i,0,n){
int x;cin>>x;
if(x==-1)left++;
else if(x==-2)right++;
else{
if(people.find(x)==people.end())people.insert(x);
}
}
set<int> ::iterator it=people.begin();
int k=0;
for(it;it!=people.end();it++){
a[k++]=*it;
}
//k个普通座位法
b[0]=a[0]-1;
fer(i,1,k)b[i]=a[i]-a[i-1]-1;
b[k]=m-a[k-1];
c[0]=b[0];
fer(i,1,k+1)c[i]=c[i-1]+b[i];
d[k]=b[k];
for(int i=k-1;i>=0;i--)d[i]=d[i+1]+b[i];
//
// cout<<"测试:";
// cout<<"m="<<m<<endl;
// cout<<"left="<<left<<",right="<<right<<endl;
// cout<<"a=";
// fer(i,0,k)cout<<a[i]<<" ";
// cout<<endl<<"b=";
// fer(i,0,k+1)cout<<b[i]<<" ";
// cout<<endl<<endl;
int mx=0,cnt=0;
//right先来
cnt=min(right,m-k)+k;
mx=max(mx,cnt);
//left先来
cnt=min(left,m-k)+k;
mx=max(mx,cnt);
//普通座位先坐,遍历先坐哪个
fer(i,0,k){
cnt=k+min(c[i],left)+min(d[i+1],right);
mx=max(mx,cnt);
}
cout<<mx<<endl;
}
return 0;
}