Submission #347964

# Submission time Handle Problem Language Result Execution time Memory
347964 2021-01-13T23:13:43 Z lovro_nidogon1 Pictionary (COCI18_pictionary) C++14
56 / 140
415 ms 10120 KB
#include<bits/stdc++.h>
#define breturn return
using namespace std;
int n, m, q, a, b, par[100001], ans[100001];
vector<pair<int, pair<int, int> > > mid[100001];  
vector<pair<int, int> > quer;
bool done;

int gp(int x) {
	if(x == par[x]) breturn x;
	else breturn par[x] = gp(par[x]);
}

void con(int x, int y) {
	int xx = gp(x), yy = gp(y);
	if(xx == yy) breturn;	
//	cout << "connecting " << x << " and " << y << '\n';
	par[xx] = yy;
}


int main() {
	cin >> n >> m >> q;
	for(int i = 0; i < q; i++) cin >> a >> b, quer.push_back({a, b}), mid[m/2].push_back({i, {0, m}});
	while(!done) {
		done = true;
		for(int i = 1; i <= n; i++) par[i] = i;		
		for(int i = 0; i <= m; i++) {
			int ad = m - i + 1;
			int las = ad;
			int gc = las + ad;
			while(gc <= n) {
				con(las, gc);
				las = gc;
				gc += ad;
			}
			for(int j = 0; j < mid[i].size(); j++) {
				int y = mid[i][j].first;
				int l = mid[i][j].second.first;
				int r = mid[i][j].second.second;				
				int midl = (l + r)/2;
		/*		cout << y << "  " <<  l << " " << r << " " << midl << '\n';
				cout << quer[y].first << " < - > " << quer[y].second << '\n';
				cout << gp(quer[y].first) << " . . . " << gp(quer[y].second) << '\n';
*/
				if(gp(quer[y].first) != gp(quer[y].second)) {
					l = midl + 1;				
				} else {
					r = midl;
				}
				midl = (l + r)/2;
				if(l == r) ans[mid[i][j].first] = midl;
				else {
					done = false;	
					mid[midl].push_back({mid[i][j].first, {l, r}});
				}
			}	
			mid[i].clear();
			mid[i].shrink_to_fit();						
		}		
	}
	for(int i = 0; i < q; i++) cout << ans[i] << '\n';
}

Compilation message

pictionary.cpp: In function 'int main()':
pictionary.cpp:37:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |    for(int j = 0; j < mid[i].size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 3140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 7348 KB Output is correct
2 Incorrect 64 ms 7460 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 99 ms 8792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 107 ms 5852 KB Output is correct
2 Correct 102 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 6108 KB Output is correct
2 Incorrect 124 ms 6052 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 200 ms 7888 KB Output is correct
2 Correct 170 ms 5712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 162 ms 7808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 328 ms 9264 KB Output is correct
2 Correct 345 ms 8916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 415 ms 10120 KB Output is correct
2 Incorrect 390 ms 9132 KB Output isn't correct