Submission #605808

# Submission time Handle Problem Language Result Execution time Memory
605808 2022-07-26T02:32:52 Z maximath_1 ICC (CEOI16_icc) C++11
90 / 100
779 ms 540 KB
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
 
const int MX = 105;
 
int par[MX];
int find(int nw){
	return par[nw] = (par[nw] == nw ? nw : find(par[nw]));
}
mt19937 rng(time(NULL));
int ban[MX][MX];
void run(int N){
	for(int i = 1; i <= N; i ++)
		par[i] = i;
	for(int times = 1; times < N; times ++){
      	memset(ban, 0, sizeof(ban));
		vector<int> color(N + 1, -1), lf, rg;
		set<vector<int> > cc;
		int gt = 0;
		do{
          	int mx = 0;
          	for(int _ = 0; _ < 200; _ ++){
            	for(int i = 1; i <= N; i ++) if(find(i) == i)
					color[i] = rng() % 2;
            	for(int i = 1; i <= N; i ++) color[i] = color[find(i)];
            	vector<int> nlf, nrg;
            	for(int i = 1; i <= N; i ++)
            		if(color[i]) nrg.push_back(i);
            		else nlf.push_back(i);
            	int cnt = 0;
            	for(int i : nlf) for(int j : nrg) cnt += !ban[i][j];
            		if(mx < cnt){
            		mx = cnt; lf = nlf; rg = nrg;
				}
            }
			int xl[lf.size()], xr[rg.size()];
			for(int i = 0; i < lf.size(); i ++) xl[i] = lf[i];
			for(int i = 0; i < rg.size(); i ++) xr[i] = rg[i];
			if(lf.empty() || rg.empty()) continue;
			gt = query(lf.size(), rg.size(), xl, xr);
          	if(gt == 0){
              for(int i : lf) for(int j : rg) ban[i][j] = ban[j][i] = 1;
			}
		}while(gt == 0);
 
		int l = 0, r = rg.size() - 1, rs = r + 1;
		for(int md; l <= r;){
			md = (l + r) / 2;
			vector<int> nrg;
			for(int j = 0; j <= md; j ++) nrg.push_back(rg[j]);
			int xl[lf.size()], xr[nrg.size()];
			for(int i = 0; i < lf.size(); i ++) xl[i] = lf[i];
			for(int i = 0; i < nrg.size(); i ++) xr[i] = nrg[i];
			gt = query(lf.size(), nrg.size(), xl, xr);
			if(gt){
				rs = md; r = md - 1;
			}else{
				l = md + 1;
			}
		}
 
		int u = rg[rs]; rg.clear(); rg.push_back(u);
		swap(lf, rg);
 
		l = 0, r = rg.size() - 1, rs = r + 1;
		for(int md; l <= r;){
			md = (l + r) / 2;
			vector<int> nrg;
			for(int j = 0; j <= md; j ++) nrg.push_back(rg[j]);
			int xl[lf.size()], xr[nrg.size()];
			for(int i = 0; i < lf.size(); i ++) xl[i] = lf[i];
			for(int i = 0; i < nrg.size(); i ++) xr[i] = nrg[i];
			gt = query(lf.size(), nrg.size(), xl, xr);
			if(gt){
				rs = md; r = md - 1;
			}else{
				l = md + 1;
			}
		}
 
		int v = rg[rs];
 
		setRoad(u, v);
		u = find(u); v = find(v);
		par[u] = v;
	}
}

Compilation message

icc.cpp: In function 'void run(int)':
icc.cpp:38:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |    for(int i = 0; i < lf.size(); i ++) xl[i] = lf[i];
      |                   ~~^~~~~~~~~~~
icc.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |    for(int i = 0; i < rg.size(); i ++) xr[i] = rg[i];
      |                   ~~^~~~~~~~~~~
icc.cpp:53:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |    for(int i = 0; i < lf.size(); i ++) xl[i] = lf[i];
      |                   ~~^~~~~~~~~~~
icc.cpp:54:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |    for(int i = 0; i < nrg.size(); i ++) xr[i] = nrg[i];
      |                   ~~^~~~~~~~~~~~
icc.cpp:72:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |    for(int i = 0; i < lf.size(); i ++) xl[i] = lf[i];
      |                   ~~^~~~~~~~~~~
icc.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |    for(int i = 0; i < nrg.size(); i ++) xr[i] = nrg[i];
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 468 KB Ok! 105 queries used.
2 Correct 7 ms 536 KB Ok! 100 queries used.
# Verdict Execution time Memory Grader output
1 Correct 53 ms 520 KB Ok! 535 queries used.
2 Correct 128 ms 528 KB Ok! 714 queries used.
3 Correct 131 ms 520 KB Ok! 703 queries used.
# Verdict Execution time Memory Grader output
1 Correct 322 ms 536 KB Ok! 1322 queries used.
2 Correct 779 ms 528 KB Ok! 1798 queries used.
3 Correct 366 ms 540 KB Ok! 1362 queries used.
4 Correct 486 ms 532 KB Ok! 1530 queries used.
# Verdict Execution time Memory Grader output
1 Correct 375 ms 532 KB Ok! 1415 queries used.
2 Correct 397 ms 524 KB Ok! 1464 queries used.
3 Correct 720 ms 536 KB Ok! 1685 queries used.
4 Correct 251 ms 536 KB Ok! 1317 queries used.
# Verdict Execution time Memory Grader output
1 Correct 717 ms 524 KB Ok! 1692 queries used.
2 Correct 673 ms 532 KB Ok! 1704 queries used.
3 Correct 727 ms 532 KB Ok! 1706 queries used.
4 Correct 732 ms 532 KB Ok! 1639 queries used.
5 Correct 412 ms 536 KB Ok! 1435 queries used.
6 Correct 550 ms 536 KB Ok! 1610 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 738 ms 528 KB Too many queries! 1708 out of 1625
2 Halted 0 ms 0 KB -