Submission #543229

# Submission time Handle Problem Language Result Execution time Memory
543229 2022-03-29T21:09:39 Z chonka Chameleon's Love (JOI20_chameleon) C++17
100 / 100
57 ms 492 KB
#include<bits/stdc++.h>
#include "chameleon.h"
using namespace std ;

namespace {
    vector < int > v[ 1007 ] ;
    int col[ 1007 ] ;

    vector < int > w[ 3 ] ;
    vector < int > aux ;
    bool done[ 1007 ] ;
    int nxt[ 1007 ] , prv[ 1007 ] ;
}

void dfs ( int vertex , int c ) {
    col[ vertex ] = c ;
    for ( auto y : v[ vertex ] ) {
        if ( col[ y ] == 0 ) {
            dfs ( y , 3 - c ) ;
        }
    }
}

bool f ( int wh , int l , int r , int ori ) {
    if ( l > r ) { return false ; }
    aux.clear ( ) ;
    aux.emplace_back ( ori ) ;
    for ( int i = l ; i <= r ; ++ i ) {
        aux.emplace_back ( w[ wh ][ i ] ) ;
    }
    int ret = Query ( aux ) ;
    if ( ret <= r - l + 1 ) { return true ; }
    return false ;
}

void Solve ( int n ) {
    for ( int i = 1 ; i <= 2 * n ; ++ i ) {
        for ( int j = 1 ; j < i ; ++ j ) {
            col[ j ] = 0 ;
        }
        for ( int j = 1 ; j < i ; ++ j ) {
            if ( col[ j ] == 0 ) {
                dfs ( j , 1 ) ;
            }
        }
        w[ 1 ].clear ( ) ; w[ 2 ].clear ( ) ;
        for ( int j = 1 ; j < i ; ++ j ) {
            w[ col[ j ] ].push_back ( j ) ;
        }
        for ( int wh = 1 ; wh <= 2 ; ++ wh ) {
            int lst = -1 ;
            for ( int tm = 0 ; tm < 3 ; ++ tm ) {
                int l , r , mid ;
                l = lst + 1 ;
                r = w[ wh ].size ( ) - 1 ;
                if ( f ( wh , lst + 1 , r , i ) == false ) { break ; }
                while ( r - l > 3 ) {
                    mid = ( l + r ) / 2 ;
                    if ( f ( wh , lst + 1 , mid , i ) == true ) { r = mid ; }
                    else { l = mid ; }
                }
                while ( f ( wh , lst + 1 , l , i ) == false ) { ++ l ; }
                v[ i ].push_back ( w[ wh ][ l ] ) ;
                v[ w[ wh ][ l ] ].push_back ( i ) ;
                lst = l ;
            }
        }
    }
    for ( int i = 1 ; i <= 2 * n ; ++ i ) {
        if ( v[ i ].size ( ) == 1 && done[ i ] == false ) {
            Answer ( i , v[ i ][ 0 ] ) ;
            done[ i ] = done[ v[ i ][ 0 ] ] = true ;
        }
    }
    for ( int i = 1 ; i <= 2 * n ; ++ i ) {
        if ( v[ i ].size ( ) == 3 ) {
            for ( int j = 0 ; j < 3 ; ++ j ) {
                aux.clear ( ) ;
                aux.push_back ( i ) ;
                for ( int t = 0 ; t < 3 ; ++ t ) {
                    if ( j == t ) { continue ; }
                    aux.push_back ( v[ i ][ t ] ) ;
                }
                if ( Query ( aux ) == 1 ) {
                    nxt[ i ] = v[ i ][ j ] ;
                    prv[ v[ i ][ j ] ] = i ;
                    break ;
                }
            }
        }
    }
    for ( int i = 1 ; i <= 2 * n ; ++ i ) {
        if ( v[ i ].size ( ) == 3 && done[ i ] == false ) {
            int sm = v[ i ][ 0 ] + v[ i ][ 1 ] + v[ i ][ 2 ] ;
            sm = sm - prv[ i ] - nxt[ i ] ;
            Answer ( i , sm ) ;
            done[ i ] = done[ sm ] = true ;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 32 ms 368 KB Output is correct
4 Correct 32 ms 356 KB Output is correct
5 Correct 33 ms 356 KB Output is correct
6 Correct 33 ms 368 KB Output is correct
7 Correct 35 ms 480 KB Output is correct
8 Correct 34 ms 368 KB Output is correct
9 Correct 33 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 424 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 56 ms 364 KB Output is correct
4 Correct 52 ms 372 KB Output is correct
5 Correct 55 ms 368 KB Output is correct
6 Correct 57 ms 360 KB Output is correct
7 Correct 53 ms 376 KB Output is correct
8 Correct 57 ms 456 KB Output is correct
9 Correct 57 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 32 ms 368 KB Output is correct
4 Correct 32 ms 356 KB Output is correct
5 Correct 33 ms 356 KB Output is correct
6 Correct 33 ms 368 KB Output is correct
7 Correct 35 ms 480 KB Output is correct
8 Correct 34 ms 368 KB Output is correct
9 Correct 33 ms 336 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 0 ms 336 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 0 ms 336 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 0 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 424 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 0 ms 336 KB Output is correct
29 Correct 0 ms 336 KB Output is correct
30 Correct 56 ms 364 KB Output is correct
31 Correct 52 ms 372 KB Output is correct
32 Correct 55 ms 368 KB Output is correct
33 Correct 57 ms 360 KB Output is correct
34 Correct 53 ms 376 KB Output is correct
35 Correct 57 ms 456 KB Output is correct
36 Correct 57 ms 364 KB Output is correct
37 Correct 50 ms 380 KB Output is correct
38 Correct 34 ms 368 KB Output is correct
39 Correct 52 ms 492 KB Output is correct
40 Correct 51 ms 380 KB Output is correct
41 Correct 53 ms 372 KB Output is correct
42 Correct 34 ms 336 KB Output is correct
43 Correct 53 ms 364 KB Output is correct
44 Correct 50 ms 364 KB Output is correct
45 Correct 53 ms 368 KB Output is correct