QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#622955#8783. Cherry Pickingrns_ksr#WA 4ms15236kbC++141.9kb2024-10-09 08:50:342024-10-09 08:50:34

Judging History

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

  • [2024-10-09 08:50:34]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:15236kb
  • [2024-10-09 08:50:34]
  • 提交

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];
vector<pii> adj[N];

int rt[N], val[N], A[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, j; i <= n; i++) if (str[i - 1] == '0') {
    	int mx = A[i];
    	for (j = i; j < n; j++) if (str[j] != '0') break; else mx = max(mx, A[j + 1]);
    	if (i > 1 && j < n) adj[mx].push_back(pii(i - 1, j + 1));
    	i = j + 1;
    }
    for (int i = 1; i <= n; i++) {
    	val[i] = str[i - 1] - '0', rt[i] = i;
    	if (str[i - 1] == '1') vec[A[i]].push_back(i);
    }
    int 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++;
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
    	for (auto p : vec[i]) {
    		int u = find_rt(p);
    		if (val[u] == m) cnt--;
    		val[u]--;
    	}
    	for (auto e : adj[i]) {
    		int u = e.fi, v = e.se;
    		u = find_rt(u), v = find_rt(v);
    		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 = i + 1;
    }
    cout << ans << '\n';

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 13824kb

input:

5 2
1 2 3 4 5
01101

output:

2

result:

ok answer is '2'

Test #2:

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

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

input:

1 1
1
1

output:

200500

result:

wrong answer expected '1', found '200500'