QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#184200#6429. Let's Play Curlingvalue0AC ✓130ms7652kbC++201.5kb2023-09-20 15:08:202023-09-20 15:08:20

Judging History

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

  • [2023-09-20 15:08:20]
  • 评测
  • 测评结果:AC
  • 用时:130ms
  • 内存:7652kb
  • [2023-09-20 15:08:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n,m;
void solve()
{
	
	scanf("%d %d",&n,&m);
	vector<int> a(n + 1),b(m + 1);
	unordered_map<int,int> q;
	for(int i = 1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		q[a[i]] ++;
	}
	for(int i = 1;i<=m;i++)
	{
		scanf("%d",&b[i]);
	}
	sort(a.begin() + 1,a.end());
	sort(b.begin() + 1,b.end());
	a.erase(unique(a.begin() + 1,a.end()),a.end());
	b.erase(unique(b.begin() + 1,b.end()),b.end());
	int i = 1;
	int j = 1;
	ll ans = 0;
	n = a.size() - 1;
	m = b.size() - 1;
//	for(int i = 1;i<=n;i++)
//	{
//		cout<<a[i]<<' ';
//	}
//	cout<<endl;
//	for(int i= 1;i<=m;i++)
//	{
//		cout<<b[i]<<' ';
//	}
//	cout<<endl;
	while(i <= n && j <= m)
	{
		ll cnt = 0;
		while(j <= m && b[j] <= a[i])
		{
			if(a[i] == b[j])
			{
				i ++;
				j ++;
			}
			else
			{
				j ++;
			}
		}
		if(j > m)
		{
			break;
		}
		while(i <= n && a[i] <= b[j])
		{
//			cout<<i<<' '<<a[i]<<endl;
			if(a[i] == b[j])
			{
				i ++;
				j ++;
				ans = max(ans,cnt);
				cnt = 0;
				continue;
			}
			else
			{
				cnt += q[a[i]];
				i ++;
				
			}
			
		}
//		cout<<i<<' '<<j<<' '<<cnt<<endl;
		ans = max(ans,cnt);
	}
	ll sum = 0;
	while(i <= n)
	{
		sum += q[a[i]];
		i ++;
	}
	ans = max(sum,ans);
	if(ans == 0)
	{
		puts("Impossible");
	}
	else
	{
		printf("%lld\n",ans);
	}
}

int main()
{
	int t = 1;
	scanf("%d",&t);
	while(t--)
	{
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3828kb

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:

2
3
Impossible

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 130ms
memory: 7652kb

input:

5553
12 19
8 8 11 18 12 9 15 38 6 32 30 30
17 28 33 2 37 20 11 38 36 18 18 30 20 33 13 31 33 37 8
12 6
7 12 14 2 19 2 17 7 4 20 1 13
7 18 23 22 1 16
8 7
5 2 4 2 4 5 8 12
13 16 6 6 5 16 11
5 7
5 13 3 8 3
11 6 9 11 13 8 11
17 19
944782509 244117333 140979583 661724696 617847780 321687699 418677763 725...

output:

1
3
4
3
4
8
11
4
2
4
5
2
4
1
11
3
2
4
2
3
5
4
1
4
9
1
3
9
2
2
1
4
5
12
2
3
4
5
4
4
11
4
5
7
3
5
4
4
5
1
3
2
4
5
5
2
6
8
3
4
3
2
2
7
2
5
3
4
1
2
5
3
6
5
1
4
1
1
2
3
4
7
9
1
2
3
16
5
5
4
3
4
3
4
3
1
2
3
3
2
2
2
5
2
7
1
1
2
4
7
2
3
7
12
1
1
1
5
3
4
1
3
2
4
3
2
3
5
4
8
10
6
2
6
2
1
6
1
3
6
2
1
9
8
1
2
3...

result:

ok 5553 lines