Submission #347763

# Submission time Handle Problem Language Result Execution time Memory
347763 2021-01-13T11:10:27 Z Markomafko972 Pictionary (COCI18_pictionary) C++14
140 / 140
523 ms 12080 KB
#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
using namespace std;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int OFF = (1 << 20);

int n, m, q;
pii p[100005];
vector< pair<pii, int> > gdje[100005];
vector< pair<pii, int> > slj[100005];
int sol[100005];
int prt[100005];

int find(int x) {
	if (prt[x] == x) return x;
	return prt[x] = find(prt[x]);
}

void unija(int x, int y) {
	x = find(x);
	y = find(y);
	if (x != y) {
		prt[x] = y;
	}
}

int main () {

	cin >> n >> m >> q;
	for (int i = 0; i < q; i++) {
		cin >> p[i].X >> p[i].Y;	
		gdje[(1+m)/2].push_back({{1, m}, i});
	}
	
	int kol = q;
	while (kol > 0) {
		for (int i = 1; i <= n; i++) prt[i] = i;
		
		for (int i = 1; i <= m; i++) {
			for (int j = 2*(m-i+1); j <= n; j += m-i+1) {
				unija(m-i+1, j);
			}
			
			for (int j = 0; j < gdje[i].size(); j++) {
				int p1 = find(p[gdje[i][j].Y].X);
				int p2 = find(p[gdje[i][j].Y].Y);
				
				if (p1 == p2) {
					if (gdje[i][j].X.X == gdje[i][j].X.Y) {
						sol[gdje[i][j].Y] = i;
						kol--;
					}
					else slj[(gdje[i][j].X.X+i)/2].push_back({{gdje[i][j].X.X, i}, gdje[i][j].Y});
				}
				else {
					slj[(i+1+gdje[i][j].X.Y)/2].push_back({{i+1, gdje[i][j].X.Y}, gdje[i][j].Y});
				}
			}
		}
		
		for (int i = 1; i <= m; i++) {
			gdje[i].clear();
			gdje[i].shrink_to_fit();
			
			gdje[i] = slj[i];
			
			slj[i].clear();
			slj[i].shrink_to_fit();
		}
	}
	
	for (int i = 0; i < q; i++) cout << sol[i] << "\n";

	return 0;
}

Compilation message

pictionary.cpp: In function 'int main()':
pictionary.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |    for (int j = 0; j < gdje[i].size(); j++) {
      |                    ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 6132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 9404 KB Output is correct
2 Correct 63 ms 9648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 11024 KB Output is correct
2 Correct 88 ms 10860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 8048 KB Output is correct
2 Correct 121 ms 8096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 8472 KB Output is correct
2 Correct 140 ms 8464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 247 ms 9792 KB Output is correct
2 Correct 205 ms 8252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 10856 KB Output is correct
2 Correct 342 ms 10636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 397 ms 11408 KB Output is correct
2 Correct 412 ms 11336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 523 ms 12080 KB Output is correct
2 Correct 471 ms 11804 KB Output is correct