답안 #640589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640589 2022-09-15T02:17:50 Z CattlemansRanch Stranded Far From Home (BOI22_island) C++14
15 / 100
56 ms 9732 KB
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int MAXN=200005;
pii arr[MAXN];
bool ada[MAXN];
int par[MAXN],sz[MAXN],zero[MAXN],h[MAXN];
long long pref[MAXN];

int find(int x){
	if(par[x]==x)return par[x];
	return par[x]=find(par[x]);
}

void join(int u,int v){
	int repu=find(u),repv=find(v);
	par[repu]=repv;
	sz[repv]+=sz[repu];
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++){
		cin >> h[i];
		arr[i]={h[i],i};
		par[i]=i;
		sz[i]=1;
		pref[i]=pref[i-1]+h[i];
	}
	sort(arr+1,arr+n+1);
	for(int i=1;i<=n;i++){
		pii isi=arr[i];
		int kiri=0,kanan=0;
		if(ada[isi.second-1]){
			kiri=sz[find(isi.second-1)];
			join(isi.second,isi.second-1);
		}
		if(ada[isi.second+1]){
			kanan=sz[find(isi.second+1)];
			join(isi.second,isi.second+1);
		}
		ada[isi.second]=true;
		int L=isi.second-kiri,R=isi.second+kanan;
//		cout << "L " << L << " R " << R << '\n';
		if(L==1 && R==n)continue;
		long long people=pref[R]-pref[L-1];
		bool dominate=false;
		if(L-1>=1){
			if(h[L-1]<=people)dominate=true;
		}
		if(R+1<=n){
			if(h[R+1]<=people)dominate=true;
		}
		if(!dominate){
			zero[L]++;
			zero[R+1]--;
		}
	}
	for(int i=1;i<=n;i++)zero[i]+=zero[i-1];
	for(int i=1;i<=n;i++){
		if(zero[i])cout << '0';
		else cout << '1';
	}
	cout << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Incorrect 2 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 32 ms 6892 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 52 ms 6924 KB Output is correct
3 Correct 55 ms 8580 KB Output is correct
4 Correct 52 ms 8484 KB Output is correct
5 Correct 24 ms 7476 KB Output is correct
6 Correct 56 ms 9008 KB Output is correct
7 Correct 47 ms 9104 KB Output is correct
8 Correct 48 ms 9036 KB Output is correct
9 Correct 27 ms 8300 KB Output is correct
10 Correct 35 ms 9732 KB Output is correct
11 Correct 46 ms 7944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 53 ms 6892 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Incorrect 2 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -