社区讨论

P8708求条

学术版参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@m61jkre9
此快照首次捕获于
2025/01/18 10:00
去年
此快照最后确认于
2025/11/04 11:24
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
bool cmp(string a,string b){
	if(a.size()>b.size()){
		return true;
	}else{
		if(a.size()==b.size()){
			return a>=b;
		}else{
			return false;
		}
	}
}
int n;
string a[100005];
string k;
int main(){
	ios_base::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	int l=1,r=n,cnt=0;
	string s,t;
	while(l<r){
		s=a[l]+a[r];
		//cout<<s<<'\n';
		if(cmp(k,s)){
			cnt+=r-l;
			l++;
		}else{
			r--;
		}
	}
	//cout<<cnt<<'\n';
	sort(a+1,a+n+1,cmp);
	l=1,r=n;
	while(l<r){
		t=a[l]+a[r];
		//cout<<t<<'\n';
		if(cmp(k,t)){
		    cnt+=r-l;
			r--;
		}else{
			l++;
		}
	}
	cout<<cnt;
}
过样例,全Wa

回复

2 条回复,欢迎继续交流。

正在加载回复...