Submission #62096

# Submission time Handle Problem Language Result Execution time Memory
62096 2018-07-27T12:48:26 Z bazsi700 ICC (CEOI16_icc) C++14
54 / 100
294 ms 1184 KB
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL

//13:22

int root[105];

int findroot(int x) {
	if(root[x] != x) {
		root[x] = findroot(root[x]);
	}
	return root[x];
}

void join(int a, int b) {
	if(rand()%2) {
		root[findroot(a)] = findroot(b);
	} else {
		root[findroot(b)] = findroot(a);
	}
}

void run(int n) {
	srand(42);
	for(int i = 1; i <= n; i++) {
		root[i] = i;
	}
	for(int i = 1; i < n; i++) {
		set<int> roots;
		vii inroot(n+1,vi());
		for(int i = 1; i <= n; i++) {
			roots.insert(findroot(i));
			inroot[root[i]].push_back(i);
		}
		int x,y;
		x = -1;
		y = -1;
		vector<int> root1;
		vector<int> root1gr;
		vector<int> root2;
		vector<int> root2gr;
		while(true) {
			root1.clear();
			root2.clear();
			root1gr.clear();
			root2gr.clear();
			int s1 = 0;
			int s2 = 0;
			for(int rt : roots) {
				if(rand()%2) {
					root1.push_back(rt);
					s1+= inroot[rt].size();
				} else {
					root2.push_back(rt);
					s2+= inroot[rt].size();
				}
			}
			if(root2.empty()) {
				root2.push_back(root1[n-1]);
				root1.pop_back();
				s1-= inroot[root2[0]].size();
				s2+= inroot[root2[0]].size();
			}
			if(root1.empty()) {
				root1.push_back(root2[n-1]);
				root2.pop_back();
				s1+= inroot[root1[0]].size();
				s2-= inroot[root1[0]].size();
			}
			for(int rt : root1) {
				for(int el : inroot[rt]) {
					root1gr.push_back(el);
				}
			}
			for(int rt : root2) {
				for(int el : inroot[rt]) {
					root2gr.push_back(el);
				}
			}
			int a[root1gr.size()];
			int b[root2gr.size()];
			int ind = 0;
			for(int el : root1gr) {
				a[ind++] = el;
			}
			ind = 0;
			for(int el : root2gr) {
				b[ind++] = el;
			}
			int an = query(root1gr.size(),root2gr.size(),a,b);
			if(an == 1) {
				break;
			}
		}
		int ind = 0;
		int b[root2gr.size()];
		for(int el : root2gr) {
			b[ind++] = el;
		}
		vector<int> gr1;
		vector<int> gr2;
		ind = 0;
		for(int el : root1gr) {
			if(ind*2 < root1gr.size()) {
				gr1.push_back(el);
			} else {
				gr2.push_back(el);
			}
			ind++;
		}
		while(gr1.size() > 0 && gr2.size() > 0) {
			int a[gr1.size()];
			ind = 0;
			for(int el : gr1) {
				a[ind++] = el;
			}
			int an = query(gr1.size(),root2gr.size(),a,b);
			if(an) {
				gr2.clear();
				int ind = 0;
				for(int el : gr1) {
					if(ind*2 >= gr1.size()) {
						gr2.push_back(el);
					}
					ind++;
				}
				for(int tim = 0; tim < gr2.size(); tim++) {
					gr1.pop_back();
				}
			} else {
				gr1.clear();
				int ind = 0;
				for(int el : gr2) {
					if(ind*2 >= gr2.size()) {
						gr1.push_back(el);
					}
					ind++;
				}
				for(int tim = 0; tim < gr1.size(); tim++) {
					gr2.pop_back();
				}
			}
		}
		if(gr1.empty()) {
			x = gr2[0];
		} else {
			x = gr1[0];
		}
		gr1.clear();
		gr2.clear();
		ind = 0;
		for(int el : root2gr) {
			if(ind*2 < root2gr.size()) {
				gr1.push_back(el);
			} else {
				gr2.push_back(el);
			}
			ind++;
		}
		while(gr1.size() > 0 && gr2.size() > 0) {
			int bb[gr1.size()];
			int a[1];
			a[0] = x;
			ind = 0;
			for(int el : gr1) {
				bb[ind++] = el;
			}
			int an = query(1,gr1.size(),a,bb);
			if(an) {
				gr2.clear();
				int ind = 0;
				for(int el : gr1) {
					if(ind*2 >= gr1.size()) {
						gr2.push_back(el);
					}
					ind++;
				}
				for(int tim = 0; tim < gr2.size(); tim++) {
					gr1.pop_back();
				}
			} else {
				gr1.clear();
				int ind = 0;
				for(int el : gr2) {
					if(ind*2 >= gr2.size()) {
						gr1.push_back(el);
					}
					ind++;
				}
				for(int tim = 0; tim < gr1.size(); tim++) {
					gr2.pop_back();
				}
			}
		}
		if(gr1.empty()) {
			y = gr2[0];
		} else {
			y = gr1[0];
		}
		join(x,y);
		setRoad(x,y);
	}
}

Compilation message

icc.cpp: In function 'void run(int)':
icc.cpp:112:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(ind*2 < root1gr.size()) {
       ~~~~~~^~~~~~~~~~~~~~~~
icc.cpp:130:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      if(ind*2 >= gr1.size()) {
         ~~~~~~^~~~~~~~~~~~~
icc.cpp:135:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int tim = 0; tim < gr2.size(); tim++) {
                      ~~~~^~~~~~~~~~~~
icc.cpp:142:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      if(ind*2 >= gr2.size()) {
         ~~~~~~^~~~~~~~~~~~~
icc.cpp:147:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int tim = 0; tim < gr1.size(); tim++) {
                      ~~~~^~~~~~~~~~~~
icc.cpp:161:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(ind*2 < root2gr.size()) {
       ~~~~~~^~~~~~~~~~~~~~~~
icc.cpp:181:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      if(ind*2 >= gr1.size()) {
         ~~~~~~^~~~~~~~~~~~~
icc.cpp:186:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int tim = 0; tim < gr2.size(); tim++) {
                      ~~~~^~~~~~~~~~~~
icc.cpp:193:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      if(ind*2 >= gr2.size()) {
         ~~~~~~^~~~~~~~~~~~~
icc.cpp:198:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int tim = 0; tim < gr1.size(); tim++) {
                      ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 760 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 Correct 48 ms 1064 KB Ok! 554 queries used.
2 Correct 86 ms 1064 KB Ok! 878 queries used.
3 Correct 84 ms 1064 KB Ok! 832 queries used.
# Verdict Execution time Memory Grader output
1 Correct 174 ms 1080 KB Ok! 1588 queries used.
2 Correct 294 ms 1080 KB Ok! 2150 queries used.
3 Correct 173 ms 1080 KB Ok! 1737 queries used.
4 Correct 234 ms 1080 KB Ok! 1740 queries used.
# Verdict Execution time Memory Grader output
1 Correct 201 ms 1128 KB Ok! 1658 queries used.
2 Correct 183 ms 1128 KB Ok! 1729 queries used.
3 Correct 225 ms 1132 KB Ok! 1861 queries used.
4 Correct 180 ms 1132 KB Ok! 1622 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 231 ms 1184 KB Too many queries! 1939 out of 1775
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 255 ms 1184 KB Too many queries! 1883 out of 1625
2 Halted 0 ms 0 KB -