QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#622964#8783. Cherry Pickingrns_ksr#WA 2ms11404kbC++141.5kb2024-10-09 09:03:102024-10-09 09:03:11

Judging History

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

  • [2024-10-09 09:03:11]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11404kb
  • [2024-10-09 09:03:10]
  • 提交

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 = 200500;
const int inf = 1e9 + 100;
const ll infll = 2e18 + 500;

vector<int> vec[N];

int rt[N], val[N], A[N], B[N];
char str[N];

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++) {
    	cin >> A[i];
    }
    cin >> str;
    for (int i = 1; i <= n; i++) {
    	if (str[i - 1] == '1') vec[A[i]].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
    	val[i] = str[i - 1] - '0';
    	rt[i] = i;
    }
    int f = 0, ans = 0;
    for (int i = N - 1; i >= 1; i--) if (!vec[i].empty()) {
    	for (auto e : vec[i]) {
    		B[e] = 1;
    		if (B[e - 1] == B[e]) {
    			int u = find_rt(e - 1), v = find_rt(e);
    			if (u == v || !u || !v) continue;
    			if (A[u] < A[v]) swap(u, v);
    			rt[v] = u;
    			val[u] += val[v];
    			if (val[u] >= m) f = 1;
    		}
    		if (B[e + 1] == B[e]) {
    			int u = find_rt(e + 1), v = find_rt(e);
    			if (u == v || !u || !v) continue;
    			if (A[u] < A[v]) swap(u, v);
    			rt[v] = u;
    			val[u] += val[v];
    			if (val[u] >= m) f = 1;
    		}
    	}
    	if (f) { ans = i; break; }
    }
    cout << ans << '\n';

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9856kb

input:

5 2
1 2 3 4 5
01101

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 9820kb

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: 11404kb

input:

1 1
1
1

output:

0

result:

wrong answer expected '1', found '0'