답안 #913925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
913925 2024-01-20T13:54:58 Z pragmatist Stranded Far From Home (BOI22_island) C++17
0 / 100
599 ms 55752 KB
/*
JUDGE_ID : 331438IX
*/
 
#include<iostream>
#include<cassert>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<map>
 
using namespace std;
 
const int N = (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int MOD = (int)998244353;
const long long INF = (long long)1e18 + 7; 
 
int mult(int x, int y) {
	return 1ll*x*y%MOD;
}
 
int sum(int x, int y) {
	x += y;
	if(x >= MOD) {
		x -= MOD;
	}
	return x;
}
 
int sub(int x, int y) {
	x -= y;
	if(x < 0) {
		x += MOD;
	}
	return x;
}
 
bool is_prime(int x) {
	if(x == 1) {
		return 0;
	}
	for(int i = 2; i * i <= x; ++i) {
		if(x % i == 0) {
			return 0;
		}
	}
	return 1;
}
 
int n, m, a[N], p[N];
vector<int> pos[N];
set<int> need[N];
bool ans[N];
 
long long s[N];

void comb(int u, int v) {
	int l = p[u];
	int r = p[v];
	if(l == r) {
		return;
	}
	if((int)pos[l].size() > (int)pos[r].size()) {
		for(auto x : pos[r]) {
			p[x] = l;
			pos[l].push_back(x);
		}	
	    for(auto x : need[r]) {
	    	need[l].insert(x);
	    }
		pos[r].clear();
		need[r].clear();
		s[l] += s[r];
	} else {
		for(auto x : pos[l]) {
			p[x] = r;
			pos[r].push_back(x);
		}	
		for(auto x : need[l]) {
			need[r].insert(x);
		}
		pos[l].clear();
		need[l].clear();
		s[r] += s[l];
	}
}
 
long long val[N];
 
int b[N]; 
 
bool cmp2(int i, int j) {
	return a[i] < a[j];
}
 
vector<int> g[N];

int main() {	
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);         
	cin >> n >> m;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		p[i] = i;
		b[i] = i;
		s[i] = a[i];
		pos[i].push_back(i);
		need[i].insert(i);
	}
	for(int i = 1; i <= n; ++i) {
		ans[i] = 1;
	}    
	for(int i = 1; i <= m; ++i) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}    
	sort(b+1, b+1+n, cmp2);
	for(int i = 1; i <= n; ++i) {
		if(a[b[i]] == a[b[n]]) {
			break;
		}
		int r = i;
		while(r<n && a[b[r]] == a[b[r+1]]) {
			r++;
		}
		for(int k = i; k <= r; ++k) {
			for(auto u : g[b[k]]) {
				if(a[u] <= a[b[k]]) {
					comb(u, b[k]);
				}
			}
		}
		for(int k = i; k <= r; ++k) {
			long long cur = s[p[b[k]]];
			if(cur < a[b[r+1]]) {
				for(auto x : need[p[b[k]]]) {
					ans[x] = 0;
				}
				need[p[b[k]]].clear();
			}
		}
		for(int k = i; k <= r; ++k) {
			for(auto u : g[b[k]]) {
				long long cur = s[p[b[k]]];
				if(cur >= a[u]) {
					comb(u, b[k]);
				}
			}
		}  
		i = r;
	}
	for(int i = 1; i <= n; ++i) {
		cout << ans[i];
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 23132 KB Output is correct
2 Correct 6 ms 23132 KB Output is correct
3 Correct 6 ms 23132 KB Output is correct
4 Incorrect 8 ms 23388 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 23132 KB Output is correct
2 Correct 7 ms 23132 KB Output is correct
3 Correct 210 ms 47836 KB Output is correct
4 Correct 255 ms 55752 KB Output is correct
5 Incorrect 456 ms 54676 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 23132 KB Output is correct
2 Incorrect 599 ms 53068 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 23132 KB Output is correct
2 Incorrect 426 ms 48600 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 23132 KB Output is correct
2 Correct 6 ms 23132 KB Output is correct
3 Correct 6 ms 23132 KB Output is correct
4 Incorrect 8 ms 23388 KB Output isn't correct
5 Halted 0 ms 0 KB -