Submission #83306

# Submission time Handle Problem Language Result Execution time Memory
83306 2018-11-06T22:11:09 Z thiago4532 Pictionary (COCI18_pictionary) C++17
0 / 140
4 ms 1680 KB
#include <bits/stdc++.h>
#define div divisores

using namespace std;
const int maxn = 1010;
int pai[maxn], peso[maxn], ans[maxn];

int n, m, q;

int gcd(int a, int b){
	return b ? gcd(b, a%b) : a;
}

void reset(){
	for(int i=1;i<=n;i++)
		pai[i] = i, peso[i] = 0;
}

int find(int u){
	return (pai[u] == u ? u : pai[u] = find(pai[u]));
}

inline void join(int a, int b){
	a = find(a);
	b = find(b);

	if(peso[a] == peso[b]) peso[b]++;
	else if(peso[a] > peso[b]) swap(a, b);

	pai[a] = b;
}
pair<int, int> qq[maxn];
bool marcado[maxn];

int main(){
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m >> q;

	for(int i=1;i<=q;i++){
		int a, b;
		cin >> a >> b;
		qq[i] = pair<int, int>{a, b};
	}


	reset();
	for(int k=m;k>=1;k--){
		for(int i=2;i*k<=n;i++){
			if(find(k) != find(i*k)) join(k, i*k);
		}

		for(int l=1;l<=q;l++){
			if(marcado[l]) continue;
			if(find(qq[l].first) == find(qq[l].second)) ans[l] = m - k + 1, marcado[l] = true;
		}
	}	
	for(int i=1;i<=q;i++) cout << ans[i] << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 560 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 856 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1076 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1308 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1440 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1680 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -