#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100;
int leader[MAX_N + 1];
vector<int> group[MAX_N + 1];
bool qry( vector<int> a, vector<int> b ) {
int aa[a.size()], bb[b.size()];
for ( int i = 0; i < a.size(); i++ )
aa[i] = a[i];
for ( int i = 0; i < b.size(); i++ )
bb[i] = b[i];
return query( a.size(), b.size(), aa, bb );
}
pair<int, int> solve( vector<int> a, vector<int> b ) {
if ( b.size() == 1 ) {
if ( a.size() == 1 )
return { a[0], b[0] };
vector<int> a1, a2;
for ( int i = 0; i < a.size() / 2; i++ )
a1.push_back( a[i] );
for ( int i = a.size() / 2; i < a.size(); i++ )
a2.push_back( a[i] );
if ( qry( a1, b ) )
return solve( a1, b );
return solve( a2, b );
}
vector<int> b1, b2;
for ( int i = 0; i < b.size() / 2; i++ )
b1.push_back( b[i] );
for ( int i = b.size() / 2; i < b.size(); i++ )
b2.push_back( b[i] );
if ( qry( a, b1 ) )
return solve( a, b1 );
return solve( a, b2 );
}
void run( int n ) {
for ( int v = 1; v <= n; v++ ) {
leader[v] = v;
group[v].push_back( v );
}
for ( int i = 0; i < n - 1; i++ ) {
vector<vector<int>> g;
for ( int v = 1; v <= n; v++ ) {
if ( leader[v] == v )
g.push_back( group[v] );
}
unsigned seed = chrono::system_clock::now().time_since_epoch().count() + rand();
shuffle( g.begin(), g.end(), default_random_engine( seed ) );
int perm[(int)log2( g.size() ) + 1];
for ( int j = 0; j <= log2( g.size() ); j++ )
perm[j] = j;
shuffle( perm, perm + (int)log2( g.size() ) + 1, default_random_engine( seed ) );
int p = 0;
while ( 1 ) {
vector<int> s[2];
for ( int i = 0; i < g.size(); i++ ) {
int b = (i >> perm[p]) & 1;
for ( int v: g[i] )
s[b].push_back( v );
}
if ( qry( s[0], s[1] ) ) {
auto e = solve( s[0], s[1] );
setRoad( e.first, e.second );
int x = leader[e.first], y = leader[e.second];
for ( int v: group[y] ) {
leader[v] = x;
group[x].push_back( v );
}
group[y].clear();
break;
}
p++;
}
}
}
Compilation message
icc.cpp: In function 'bool qry(std::vector<int>, std::vector<int>)':
icc.cpp:12:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for ( int i = 0; i < a.size(); i++ )
| ~~^~~~~~~~~~
icc.cpp:14:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for ( int i = 0; i < b.size(); i++ )
| ~~^~~~~~~~~~
icc.cpp: In function 'std::pair<int, int> solve(std::vector<int>, std::vector<int>)':
icc.cpp:25:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for ( int i = 0; i < a.size() / 2; i++ )
| ~~^~~~~~~~~~~~~~
icc.cpp:27:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for ( int i = a.size() / 2; i < a.size(); i++ )
| ~~^~~~~~~~~~
icc.cpp:36:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for ( int i = 0; i < b.size() / 2; i++ )
| ~~^~~~~~~~~~~~~~
icc.cpp:38:35: 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 = b.size() / 2; i < b.size(); i++ )
| ~~^~~~~~~~~~
icc.cpp: In function 'void run(int)':
icc.cpp:68:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for ( int i = 0; i < g.size(); i++ ) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
604 KB |
Ok! 105 queries used. |
2 |
Correct |
7 ms |
604 KB |
Ok! 108 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
656 KB |
Ok! 546 queries used. |
2 |
Correct |
31 ms |
600 KB |
Ok! 714 queries used. |
3 |
Correct |
33 ms |
604 KB |
Ok! 707 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
636 KB |
Ok! 1458 queries used. |
2 |
Correct |
106 ms |
600 KB |
Ok! 1739 queries used. |
3 |
Correct |
81 ms |
600 KB |
Ok! 1631 queries used. |
4 |
Correct |
79 ms |
648 KB |
Ok! 1565 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
652 KB |
Ok! 1488 queries used. |
2 |
Correct |
82 ms |
664 KB |
Ok! 1547 queries used. |
3 |
Correct |
93 ms |
652 KB |
Ok! 1705 queries used. |
4 |
Correct |
79 ms |
600 KB |
Ok! 1533 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
652 KB |
Ok! 1679 queries used. |
2 |
Correct |
100 ms |
648 KB |
Ok! 1704 queries used. |
3 |
Correct |
128 ms |
652 KB |
Ok! 1719 queries used. |
4 |
Correct |
90 ms |
652 KB |
Ok! 1681 queries used. |
5 |
Correct |
87 ms |
648 KB |
Ok! 1532 queries used. |
6 |
Correct |
89 ms |
652 KB |
Ok! 1611 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
88 ms |
652 KB |
Too many queries! 1704 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |