QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#630203#8783. Cherry Pickingqianchen06#WA 1ms3640kbC++201.5kb2024-10-11 17:02:562024-10-11 17:02:57

Judging History

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

  • [2024-10-11 17:02:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3640kb
  • [2024-10-11 17:02:56]
  • 提交

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'