QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#558133 | #8783. Cherry Picking | WendyChen | WA | 0ms | 3788kb | C++20 | 1.5kb | 2024-09-11 14:23:11 | 2024-09-11 14:23:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define int long long
const int mod = 1e9 + 7;
const int N = 1e6 + 50;
int x[N];
void solve()
{
int n, k;
cin >> n >> k;
int mi = inf, mx = 0;
for (int i = 0; i < n; i++)
{
cin >> x[i];
mi = min(mi, x[i]);
}
string s;
cin >> s;
int min1 = inf, min2 = 0;
int num = 0;
if (s[n - 1] == '1')
{
mx = x[n - 1];
}
for (int i = 0; i < n - 1; i++)
{
if (s[i] == '1')
{
mx = max(mx, x[i]);
}
if (s[i] == '1' && s[i + 1] == '1')
{
if (num == 0)
{
num = 2;
}
else
{
num++;
}
min1 = min(min1, x[i]);
min1 = min(min1, x[i + 1]);
}
else
{
if (num >= k)
{
min2 = max(min2, min1);
min1 = inf;
num = 0;
}
}
}
if (num != 0)
{
min2 = max(min2, min1);
}
if (k == 1 && n != 1)
{
cout << mx;
}
else if (min2 == mi)
{
cout << 0;
}
else
{
cout << min2;
}
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3516kb
input:
5 2 1 2 3 4 5 01101
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3428kb
input:
5 2 3 4 5 2 1 10101
output:
0
result:
ok answer is '0'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3788kb
input:
1 1 1 1
output:
0
result:
wrong answer expected '1', found '0'