QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#622915#8783. Cherry Pickingucup-team2526WA 1ms5864kbC++201.5kb2024-10-09 08:30:082024-10-09 08:30:08

Judging History

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

  • [2024-10-09 08:30:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5864kb
  • [2024-10-09 08:30:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

#define dbg(x...) \
do { \
std::cout << #x << " -> "; \
err(x); \
} while (0)

void err() {
	std::cout << std::endl;
}

template<class T, class... Ts>
void err(T arg, Ts &... args) {
	std::cout << fixed << setprecision(10) << arg << ' ';
	err(args...);
}

const int maxn = 1e5 + 5;
vector<int> p[maxn];
int f[maxn],siz[maxn];
int vis[maxn];

int find(int x) {
	return f[x] == x ? x : f[x] = find(f[x]);
}

void GENSHEN_START() {
	int n,k;cin >> n >> k;
	multiset<int>s;
	vector<int> a(n + 1);
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
		f[i] = i;
	}
	string res;cin >> res;
	for (int i = 1;i <= n;i++) {
		if (res[i - 1] == '1') {
			p[a[i]].push_back(i);
		}
	}
	for (int i = 1e5;i >= 1;i--) {
		if (p[i].size()) {
			for (int j : p[i]) {
				siz[j] = vis[j] = 1;
				if (vis[j - 1]) {
					int prej = j - 1;
					int fj = find(j);
					prej = find(prej);
					if (prej != fj) {
						f[fj] = prej;
						siz[prej] += siz[fj];
					}	
				}
				if (vis[j + 1]) {
					int sufj = j + 1;
					int fj = find(j);
					sufj = find(sufj);
					if (sufj != fj) {
						f[fj] = sufj;
						siz[sufj] += siz[fj];
					}
				}
				int fj = find(j);
				if (siz[fj] >= k) {
					cout << i << '\n';
					return ;
				}
			}
		}
	}
	cout << 0 << '\n';
	return ;
}

signed main()
{
	ios::sync_with_stdio(false);cin.tie(nullptr);
	int T = 1;
	//cin >> T;
	while (T--) GENSHEN_START();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5616kb

input:

5 2
1 2 3 4 5
01101

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 5656kb

input:

5 2
3 4 5 2 1
10101

output:

0

result:

ok answer is '0'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5580kb

input:

1 1
1
1

output:

1

result:

ok answer is '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 5624kb

input:

1 1
1
0

output:

0

result:

ok answer is '0'

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 5864kb

input:

5 3
8 3 5 2 7
10101

output:

0

result:

wrong answer expected '5', found '0'