답안 #44335

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44335 2018-03-31T11:51:07 Z chonka 도서관 (JOI18_library) C++14
19 / 100
560 ms 596 KB
#include "library.h"
#include<iostream>
#include<stdio.h>
using namespace std ;

int n ;
vector < int > ret ;

vector < int > aux ;

void rev ( vector < int > &v ) {
    int sz = v.size ( ) ;
    int i ;
    for ( i = 0 ; i < ( sz / 2 ) ; i ++ ) {
        swap ( v[ i ] , v[ sz - i - 1 ] ) ;
    }
}

void unite ( int val ) {
    int i ;
    for ( i = 0 ; i < n ; i ++ ) {
        aux[ i ] = 0 ;
    }
    int sz = ret.size ( ) ;
    aux[ ret[ sz - 1 ] - 1 ] = 1 ;
    aux[ val - 1 ] = 1 ;
    if ( Query ( aux ) == 2 ) {
        rev ( ret ) ;
    }
    ret.push_back ( val ) ;
}

bool f ( int x ) {
    int i ;
    for ( i = 0 ; i < n ; i ++ ) {
        aux[ i ] = 0 ;
    }
    int sz = ret.size ( ) ;
    for ( i = 0 ; i < sz ; i ++ ) {
        aux[ ret[ i ] - 1 ] = 1 ;
    }
    int lft = x ;
    for ( i = 0 ; i < n ; i ++ ) {
        if ( aux[ i ] != 0 ) { continue ; }
        lft -- ;
        aux[ i ] = 1 ;
        if ( lft <= 0 ) { break ; }
    }
    int ans1 = Query ( aux ) ;
    for ( i = 0 ; i < sz ; i ++ ) {
        aux[ ret[ i ] - 1 ] = 0 ;
    }
    int ans2 = Query ( aux ) ;
    return ( ans1 <= ans2 ) ;
}


void add ( int id ) {
    int l , r , mid ;
    l = 1 ;
    r = n - id + 1 ;
    while ( r - l > 3 ) {
        int mid = ( l + r ) / 2 ;
        if ( f ( mid ) == true ) { r = mid ; }
        else { l = mid ; }
    }
    while ( f ( l ) == false ) { l ++ ; }
    int i ;
    for ( i = 0 ; i < n ; i ++ ) {
        aux[ i ] = 0 ;
    }
    for ( i = 0 ; i < id - 1 ; i ++ ) {
        aux[ ret[ i ] - 1 ] = 1 ;
    }
    for ( i = 0 ; i < n ; i ++ ) {
        if ( aux[ i ] != 0 ) { continue ; }
        l -- ;
        if ( l == 0 ) {
            unite ( i + 1 ) ;
            return ;
        }
    }
}

void Solve ( int N ) {
    n = N ;
    ret.clear ( ) ;
    ret.push_back ( 1 ) ;
    aux.resize ( n ) ;
    int i ;
    for ( i = 0 ; i < n ; i ++ ) { aux[ i ] = 0 ; }
    for ( i = 2 ; i <= n ; i ++ ) {
        add ( i ) ;
    }
    Answer ( ret ) ;
}

Compilation message

library.cpp: In function 'void add(int)':
library.cpp:59:17: warning: unused variable 'mid' [-Wunused-variable]
     int l , r , mid ;
                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 248 KB Output is correct
2 Correct 49 ms 436 KB Output is correct
3 Correct 37 ms 500 KB Output is correct
4 Correct 62 ms 500 KB Output is correct
5 Correct 55 ms 500 KB Output is correct
6 Correct 51 ms 500 KB Output is correct
7 Correct 46 ms 532 KB Output is correct
8 Correct 52 ms 540 KB Output is correct
9 Correct 55 ms 556 KB Output is correct
10 Correct 43 ms 556 KB Output is correct
11 Correct 2 ms 556 KB Output is correct
12 Correct 2 ms 572 KB Output is correct
13 Correct 2 ms 572 KB Output is correct
14 Correct 2 ms 580 KB Output is correct
15 Correct 3 ms 580 KB Output is correct
16 Correct 6 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 248 KB Output is correct
2 Correct 49 ms 436 KB Output is correct
3 Correct 37 ms 500 KB Output is correct
4 Correct 62 ms 500 KB Output is correct
5 Correct 55 ms 500 KB Output is correct
6 Correct 51 ms 500 KB Output is correct
7 Correct 46 ms 532 KB Output is correct
8 Correct 52 ms 540 KB Output is correct
9 Correct 55 ms 556 KB Output is correct
10 Correct 43 ms 556 KB Output is correct
11 Correct 2 ms 556 KB Output is correct
12 Correct 2 ms 572 KB Output is correct
13 Correct 2 ms 572 KB Output is correct
14 Correct 2 ms 580 KB Output is correct
15 Correct 3 ms 580 KB Output is correct
16 Correct 6 ms 596 KB Output is correct
17 Incorrect 560 ms 596 KB Wrong Answer [3]
18 Halted 0 ms 0 KB -