QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#630203 | #8783. Cherry Picking | qianchen06# | WA | 1ms | 3640kb | C++20 | 1.5kb | 2024-10-11 17:02:56 | 2024-10-11 17:02:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, k, rating[N], cnt[N];
vector<int> pos[N];
set<int> zero, valid;
string result;
void solve()
{
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> rating[i];
cin >> result;
result = "0" + result + "0";
zero.insert(n + 1);
for (int i = n; i >= 1; i--)
{
pos[rating[i]].push_back(i);
if (result[i] == '0')
{
zero.insert(i);
}
else
{
int nxt = *zero.lower_bound(i);
cnt[nxt]++;
if (cnt[nxt] >= k)
valid.insert(nxt);
}
}
int x = 0;
for (int i = 1; i <= 100000; i++)
{
for (int p : pos[i])
{
int nxt = *zero.upper_bound(p);
if (result[p] == '0')
{
zero.erase(p);
valid.erase(p);
cnt[nxt] += cnt[p];
if (cnt[*zero.lower_bound(p)] >= k)
valid.insert(*zero.lower_bound(p));
}
else
{
cnt[nxt]--;
if (cnt[nxt] < k)
valid.erase(nxt);
}
}
if (valid.size())
x = i + 1;
}
cout << x << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3576kb
input:
5 2 1 2 3 4 5 01101
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3640kb
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: 3572kb
input:
1 1 1 1
output:
0
result:
wrong answer expected '1', found '0'