QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#622915 | #8783. Cherry Picking | ucup-team2526 | WA | 1ms | 5864kb | C++20 | 1.5kb | 2024-10-09 08:30:08 | 2024-10-09 08:30:08 |
Judging History
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'