제출 #446082

#제출 시각아이디문제언어결과실행 시간메모리
446082raid도서관 (JOI18_library)C++17
0 / 100
0 ms200 KiB
#include "library.h" #include <iostream> #include <vector> #define pb push_back using namespace std; void Solve( int n ) { vector<int> bk, a, x, y, sol, pos; int ext, lg = 0; for ( int i = 1; i <= n + 5; ++i ) { a.pb( 0 ); x.pb( 0 ); y.pb( 0 ); bk.pb( 0 ); } if ( n == 1 ) { a[0] = 1; Answer( a ); return; } int p = n; while ( p ) { p >>= 1; ++lg; } --lg; ext = 0; for ( int i = 0; i <= lg; ++i ) { for ( int j = 1; j <= n; ++j ) { x[j - 1] = ((j & (1 << i)) >> i); y[j - 1] = x[j - 1] ^ 1; } int qx = Query( x ), qy = Query( y ); if ( qx > qy ) { ext += (1 << i); } else if ( qx == qy ) { pos.pb( i ); } for ( int j = 1; j <= n; ++j ) { x[j - 1] = y[j - 1] = 0; } } if ( pos.size() ) { ext += (1 << pos[0]); } int bt = 1; for ( int i = 1; i < pos.size(); ++i ) { int p1 = pos[i - 1], p2 = pos[i], cnt1 = 0, cnt2 = 0; for ( int j = 1; j <= n; ++j ) { if ( ((j & (1 << p1)) >> p1) == ((j & (1 << p2)) >> p2) ) { x[j - 1] = 1; ++cnt1; } else { y[j - 1] = 1; ++cnt2; } } if ( !cnt2 ) { ext += bt * (1 << p2); continue; } if ( !cnt1 ) { bt ^= 1; ext += bt * (1 << p2); continue; } int qx = Query( x ), qy = Query( y ); if ( qx > qy ) { ext += bt * (1 << p2); } else { bt ^= 1; ext += bt * (1 << p2); } for ( int j = 1; j <= n; ++j ) { x[j - 1] = y[j - 1] = 0; } } a[ext - 1] = x[ext - 1] = 1; sol.pb( ext ); for ( int i = 2; i < n; ++i ) { int res = 0; for ( int b = 0; b <= lg; ++b ) { int cnt = 0; for ( int j = 1; j <= n; ++j ) { if ( (j & (1 << b)) && !x[j - 1] ) { y[j - 1] = 1; x[j - 1] = 1; ++cnt; } } if ( cnt ) { if ( Query( x ) == Query( y ) ) { res += (1 << b); } } for ( int j = 1; j <= n; ++j ) { x[j - 1] = a[j - 1]; y[j - 1] = 0; } } a[res - 1] = 1; x[res - 1] = 1; sol.pb( res ); } for ( int i = 1; i <= n; ++i ) { if ( a[i - 1] == 0 ) { sol.pb( i ); } } Answer( sol ); }

컴파일 시 표준 에러 (stderr) 메시지

library.cpp: In function 'void Solve(int)':
library.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for ( int i = 1; i < pos.size(); ++i ) {
      |                    ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...