답안 #149539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149539 2019-09-01T06:41:39 Z From The Sky(#3630, WhipppedCream, top34051, zoomswk) 갈라파고스 여행 (FXCUP4_island) C++17
0 / 100
5000 ms 15052 KB
//subtask K <= 1000
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include "island.h"
#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 5;
const int maxk = 1000 + 5;
const int inf = 1e8;

int n, m, k;
int a[maxn];
vector<int> have[maxk];
int head[maxn];
vector<pair<int,int>> way[maxn];
int dis[maxn];
int ans[maxk][maxk];

int q[maxn*5];

int findhead(int x) {
	if(head[x]==x) return x;
	return head[x] = findhead(head[x]);
}

void bfs(int ban) {
	int l = 1, r = 0;
	for(int u=0;u<n;u++) {
		dis[u] = 0;
		if(a[u] == ban) {
			dis[u] = m;
			q[++r] = u;
		}
	}
	while(l<=r) {
		int u = q[l++];
		ans[ban][a[u]] = max(ans[ban][a[u]], dis[u]);
		for(auto tmp : way[u]) {
			int v = tmp.first, val = tmp.second;
			if(dis[v] >= min(dis[u], val) || a[v] == ban) continue;
			dis[v] = min(dis[u], val);
			q[++r] = v;
		}
	}
}

void Init(int K, vector<int> F, vector<int> S, vector<int> E){
	n = F.size(); m = S.size(); k = K;
	for(int i=0;i<n;i++) {
		a[i] = F[i];
		have[a[i]].push_back(i);
	}
	for(int i=0;i<n;i++) head[i] = i;
	for(int i=m-1;i>=0;i--) {
		if(findhead(S[i])!=findhead(E[i])) {
			head[findhead(S[i])] = findhead(E[i]);
			way[S[i]].push_back({E[i], i});
			way[E[i]].push_back({S[i], i});
			//printf("edge %d %d\n",S[i],E[i]);
		}
	}
	for(int x=0;x<k;x++) bfs(x);
}

int Separate(int A, int B){
	return ans[A][B] + 1;
	//if((int)have[A].size() >= wow) return ans[A][B] + 1;
	//if((int)have[B].size() >= wow) return ans[B][A] + 1;
}

/*

#include <stdio.h>
#include <stdlib.h>

static void my_assert(int TF, const char* message){
	if(!TF){ puts(message); exit(0); }
}

int main(){
	int N, M, K, Q;
	std::vector<int> F, S, E;

	my_assert(scanf("%d%d%d%d", &N, &M, &K, &Q) == 4, "Error: Invalid Input");
	my_assert(1 <= K && K <= N && N <= 300000, "Error: Invalid Input");
	my_assert(N - 1 <= M && M <= 1000000, "Error: Invalid Input");
	my_assert(1 <= Q && Q <= 300000, "Error: Invalid Input");

	for(int i = 0; i < N; i++){
		int a;
		my_assert(scanf("%d", &a) == 1, "Error: Invalid Input");
		my_assert(0 <= a && a < K, "Error: Invalid Input");
		F.push_back(a);
	}
	for(int i = 0; i < M; i++){
		int a, b;
		my_assert(scanf("%d%d", &a, &b) == 2, "Error: Invalid Input");
		my_assert(0 <= a && a < N && 0 <= b && b < N && a != b, "Error: Invalid Input");
		S.push_back(a), E.push_back(b);
	}
	Init(K, F, S, E);

	for(int i = 0; i < Q; i++){
		int a, b;
		my_assert(scanf("%d%d", &a, &b) == 2, "Error: Invalid Input");
		my_assert(0 <= a && a < K && 0 <= b && b < K && a != b, "Error: Invalid Input");
		printf("%d\n", Separate(a, b));
	}
	return 0;
}

*/

Compilation message

island.cpp:2:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/stack:200000000")
# 결과 실행 시간 메모리 Grader output
1 Runtime error 131 ms 8804 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2816 KB Output is correct
2 Correct 7 ms 2816 KB Output is correct
3 Correct 221 ms 13920 KB Output is correct
4 Correct 498 ms 14176 KB Output is correct
5 Correct 762 ms 14052 KB Output is correct
6 Correct 1375 ms 14244 KB Output is correct
7 Correct 3111 ms 14576 KB Output is correct
8 Execution timed out 5096 ms 15052 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2816 KB Output is correct
2 Correct 7 ms 2816 KB Output is correct
3 Runtime error 131 ms 8804 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -