답안 #640587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640587 2022-09-15T02:04:31 Z CattlemansRanch Stranded Far From Home (BOI22_island) C++14
0 / 100
53 ms 8028 KB
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int MAXN=1000005;
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=i-kiri,R=i+kanan;
		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 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Incorrect 31 ms 8028 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 48 ms 7240 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Incorrect 53 ms 7148 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -