QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#622895 | #8783. Cherry Picking | rns_ksr# | WA | 2ms | 7724kb | C++14 | 2.0kb | 2024-10-09 08:22:12 | 2024-10-09 08:22:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __float128 ld;
#define pii pair<int, int>
#define fi first
#define se second
#define VI vector<int>
#define VII vector<vector<int> >
const int N = 100500;
const int inf = 1e9 + 100;
const ll infll = 2e18 + 500;
vector<int> vec[N];
int lft[N], rht[N], rt[N], val[N], A[N];
char str[N];
int find_lft(int u) {
if (u != lft[u]) lft[u] = find_lft(lft[u]);
return lft[u];
}
int find_rht(int u) {
if (u != rht[u]) rht[u] = find_rht(rht[u]);
return rht[u];
}
int find_rt(int u) {
if (u != rt[u]) rt[u] = find_rt(rt[u]);
return rt[u];
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
vec[a].push_back(i);
A[i] = a;
}
cin >> str;
for (int i = 1; i <= n; i++) {
lft[i] = rht[i] = rt[i] = i, val[i] = str[i - 1] - '0';
}
int ans = 0, cnt = 0;
for (int i = 1; i < n; i++) {
if (str[i - 1] == '1' && str[i] == '1') {
int u = find_rt(i), v = find_rt(i + 1);
if (A[u] < A[v]) swap(u, v);
rt[v] = u;
if (val[u] >= m) cnt--;
if (val[v] >= m) cnt--;
val[u] += val[v];
if (val[u] >= m) cnt++;
}
}
for (int tt = 0; tt <= 1e5; tt++) {
for (auto p : vec[tt]) {
if (str[p - 1] == '1') {
int u = find_rt(p);
if (val[u] == m) cnt--;
val[u]--;
}
}
for (auto p : vec[tt]) {
if (str[p - 1] == '0') {
lft[p] = p - 1, rht[p] = p + 1;
int l = find_lft(p), r = find_rht(p);
if (!l || !r || str[l - 1] == '0' || str[r - 1] == '0') continue;
int u = find_rt(l), v = find_rt(r);
if (A[u] < A[v]) swap(u, v);
rt[v] = u;
if (val[u] >= m) cnt--;
if (val[v] >= m) cnt--;
val[u] += val[v];
if (val[u] >= m) cnt++;
}
}
if (cnt) ans = tt + 1;
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6896kb
input:
5 2 1 2 3 4 5 01101
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 2ms
memory: 7724kb
input:
5 2 3 4 5 2 1 10101
output:
0
result:
ok answer is '0'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 7096kb
input:
1 1 1 1
output:
100001
result:
wrong answer expected '1', found '100001'