QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#505946#6429. Let's Play CurlingAbclWA 0ms3696kbC++141.2kb2024-08-05 13:57:452024-08-05 13:57:46

Judging History

你现在查看的是最新测评结果

  • [2024-08-05 13:57:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3696kb
  • [2024-08-05 13:57:45]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005;
int n,m;
int a[100005],b[100005];
void solve(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=m;i++)cin>>b[i];
	sort(a+1,a+1+n);sort(b+1,b+1+m);
	/*	for(int i=1;i<=n;i++)cout<<a[i]<<" ";
	cout<<endl;
	for(int i=1;i<=m;i++)cout<<b[i]<<" ";
	cout<<endl;*/
	int ans=0;
	for(int i=1;i<=n;i++){
	
		int pos2=upper_bound(b+1,b+1+m,a[i])-b;//找到 b中第一个大于a【i】的
		if(pos2==m+1)pos2--;
		if(b[pos2]==a[i])continue;
		int pos1=pos2;
		while(b[pos1]>a[i]&&pos1>=2)pos1--;
		if(b[pos1]==a[i])continue;
	//	cout<<"i :"<<i<<" ";	
	//	cout<<"pos1 "<<pos1<<" pos2 "<<pos2<<endl;
		
		int k1=upper_bound(a+1,a+1+n,b[pos1])-a;
		k1--;
		if(k1>=i){
			ans=max(ans,k1);continue;
		}
		int k2=i;
		while(a[k2]<b[pos2]&&k2<=n)k2++;
		k2--;
	//	cout<<pos2<<" "<<pos1<<" "<<k2<<" "<<k1<<endl;
		ans=max(ans,abs(k2-k1)+1);
	//	cout<<ans<<endl;
		
	}
	if(ans==0)cout<<"Impossible"<<endl;
	else	cout<<ans<<endl;
	return;
}
signed main() {
	//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3696kb

input:

3
2 2
2 3
1 4
6 5
2 5 3 7 1 7
3 4 3 1 10
1 1
7
7

output:

3
4
Impossible

result:

wrong answer 1st lines differ - expected: '2', found: '3'