#include<bits/stdc++.h>
using namespace std ;
#define maxn 200009
#define ll long long
#define pb push_back
#define fi first
#define se second
#define left id<<1
#define right id<<1|1
#define re exit(0);
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1
#define TIME ( 1.0*clock() / CLOCKS_PER_SEC )
const int mod = 1e9+7 ;
const int INF = 1e9 ;
typedef vector<int> vi ;
typedef pair<int,int> pii ;
typedef vector<pii> vii ;
template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; }
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; }
void add ( int &a , int b )
{
a += b ;
if ( a >= mod ) a -= mod ;
if ( a < 0 ) a += mod ;
}
void rf ()
{
freopen ("bai1.inp","r",stdin) ;
}
mt19937 rng (time(0)) ;
int _pow ( int a , int n )
{
if ( n == 0 ) return 1 ;
int res = _pow (a,n/2) ;
if ( n % 2 ) return 1ll*res*res%mod*a%mod ;
else return 1ll*res*res%mod ;
}
#include "chameleon.h"
bool bad ( vi v , int x )
{
v . pb (x) ;
return Query (v) != v.size () ;
}
void Solve ( int n )
{
vi adj [2*n+5] ;
for ( int cr = 1 ; cr <= 2*n ; cr ++ )
{
vi colour (cr) , inset [2] ;
function<void(int,int)> dfs = [&] ( int nw , int cl )
{
if ( colour [nw] ) return ;
colour [nw] = cl ;
for ( auto nx : adj [nw] ) dfs (nx,3-cl) ;
};
for ( int i = 1 ; i < cr ; i ++ )
{
if ( !colour [i] ) dfs (i,1) ;
inset [colour[i]-1] . pb (i) ;
}
for ( int i = 0 ; i < 2 ; i ++ )
{
while ( bad(inset[i],cr) )
{
int lf = 1 , rg = inset[i].size () ;
for ( int md ; lf < rg ; )
{
md = (lf+rg)/2 ;
if ( bad(vi(inset[i].begin(),inset[i].begin()+md),cr)) rg = md ;
else lf = md+1 ;
}
adj [cr] . pb (inset[i][lf-1]) ;
adj [inset[i][lf-1]] . pb (cr) ;
inset [i] = vi (inset[i].begin()+lf,inset[i].end()) ;
}
}
}
vi same (2*n+5) , n1 (2*n+5) , n2 (2*n+5) ;
for ( int i = 1 ; i <= 2*n ; i ++ )
{
if ( adj [i].size () == 1 ) same [i] = adj [i][0] ;
else
{
while ( Query ({i,adj[i][0],adj[i][1]}) != 1 )
{
rotate (adj[i].begin(),adj[i].begin()+1,adj[i].end()) ;
}
n1 [i] = adj [i][2] ;
n2 [adj[i][2]] = i ;
}
}
for ( int i = 1 ; i <= 2*n ; i ++ )
{
if ( !same[i] )
{
same [i] = adj [i][0] + adj [i][1] + adj [i][2] - n1 [i] - n2 [i] ;
}
if ( i > same [i] ) Answer (same[i],i) ;
}
return ;
}
//int main ()
//{
// ios_base::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
//// rf () ;
//
//}
Compilation message
chameleon.cpp: In function 'bool bad(vi, int)':
chameleon.cpp:49:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | return Query (v) != v.size () ;
| ~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp: In function 'void rf()':
chameleon.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen ("bai1.inp","r",stdin) ;
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
19 ms |
560 KB |
Output is correct |
4 |
Correct |
22 ms |
344 KB |
Output is correct |
5 |
Correct |
23 ms |
344 KB |
Output is correct |
6 |
Correct |
19 ms |
348 KB |
Output is correct |
7 |
Correct |
19 ms |
352 KB |
Output is correct |
8 |
Correct |
19 ms |
344 KB |
Output is correct |
9 |
Correct |
19 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
516 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
516 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
33 ms |
560 KB |
Output is correct |
4 |
Correct |
34 ms |
600 KB |
Output is correct |
5 |
Correct |
33 ms |
600 KB |
Output is correct |
6 |
Correct |
34 ms |
600 KB |
Output is correct |
7 |
Correct |
34 ms |
616 KB |
Output is correct |
8 |
Correct |
34 ms |
600 KB |
Output is correct |
9 |
Correct |
34 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
19 ms |
560 KB |
Output is correct |
4 |
Correct |
22 ms |
344 KB |
Output is correct |
5 |
Correct |
23 ms |
344 KB |
Output is correct |
6 |
Correct |
19 ms |
348 KB |
Output is correct |
7 |
Correct |
19 ms |
352 KB |
Output is correct |
8 |
Correct |
19 ms |
344 KB |
Output is correct |
9 |
Correct |
19 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
516 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
504 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
352 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
33 ms |
560 KB |
Output is correct |
31 |
Correct |
34 ms |
600 KB |
Output is correct |
32 |
Correct |
33 ms |
600 KB |
Output is correct |
33 |
Correct |
34 ms |
600 KB |
Output is correct |
34 |
Correct |
34 ms |
616 KB |
Output is correct |
35 |
Correct |
34 ms |
600 KB |
Output is correct |
36 |
Correct |
34 ms |
600 KB |
Output is correct |
37 |
Correct |
42 ms |
576 KB |
Output is correct |
38 |
Correct |
22 ms |
564 KB |
Output is correct |
39 |
Correct |
33 ms |
612 KB |
Output is correct |
40 |
Correct |
34 ms |
528 KB |
Output is correct |
41 |
Correct |
34 ms |
600 KB |
Output is correct |
42 |
Correct |
19 ms |
504 KB |
Output is correct |
43 |
Correct |
43 ms |
592 KB |
Output is correct |
44 |
Correct |
42 ms |
604 KB |
Output is correct |
45 |
Correct |
50 ms |
600 KB |
Output is correct |