답안 #1068247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1068247 2024-08-21T08:49:49 Z lollipop COVID tests (CEOI24_covid) C++17
79.91 / 100
1499 ms 344 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define int long long
#define pb push_back
#define s second
#define f first
#define pf push_front
#define inf 100000000000000000
#define bitebi __builtin_popcountll
#define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
#define YES cout <<"YES\n"
#define NO cout << "NO\n"
#define debug cout << "Here Fine" << endl ;
#define pr pair < int , int >
#define fbo find_by_order // returns iterator
#define ook order_of_key // returns strictly less numbers than key
using namespace std ;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template<class T> using ordered_set =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
const double Pi=acos(-1.0);
const double EPS=1E-8;
const int mod =  1000000007 ;
const int mod1 = 998244353 ;
const int N = 3e5 + 10 ;
mt19937 R(time(0));
map < int , int > ma , ma1 ;

int n , t , T ;
double p ;
string s = "" , ans = "" ;
vector < int > v ; 
char ask( int l , int r ){
	for( int i = l ; i <= r ; i ++ ) s[ v[ i ] ] = '1' ;
	cout << "Q " << s << endl ;
	char c ; cin >> c ;
	for( int i = l ; i <= r ; i ++ ) s[ v[ i ] ] = '0' ;
	return c ;
}

void go( int l , int r ){	
	int mid = ( l + r ) / 2 ; 
	if( l == r ){
		ans[ l ] = '1' ; 
		return ; 
	}
	char c = ask( l , mid ) ;
	
	if( c == 'N' ){
		go( mid + 1 , r ) ;
		return ; 
	}
	go( l , mid ) ;
	return ;
}

void gg( int l , int r ){
	for( int i = l ; i <= r ; i ++ ) s[ i ] = '1' ;
	cout << "Q " << s << endl ;
	char c ; cin >> c ;
	for( int i = l ; i <= r ; i ++ ) s[ i ] = '0' ;
	
	if( c == 'N' ) return ;
	
	if( l == r ){
		ans[ l ] = '1' ; return ; 
	}
	int mid = ( l + r ) / 2 ; 
	gg( l , mid ) ;
	gg( mid + 1 , r ) ;
	
}
int len ;
void solve(){

	FOR( i , n ) s[ i ] = ans[ i ] = '0' ;
	
	
	if( T == 1 ){
		FOR( i , n ){
			s[ i ] = '1' ;
			cout << "Q " << s << endl ;
			s[ i ] = '0' ;
			char c ; cin >> c ;
			if( c == 'P' ) ans[ i ] = '1' ;
		}
		cout << "A " << ans << endl ;
		char c ; cin >> c ;
		if( c == 'W' ) return ; 
		return ;
	}
	
	
	// else go binary search?
	
		
	
	int L = 0 , R = n - 1 ;
	
	v.clear() ;
	FOR( i , n ) v.pb( i ) ; 
//	srand(time(0));
//	std::random_device r;
//	std::seed_seq seed{r(), r(), r(), r(), r(), r(), r(), r()};
//	std::mt19937 eng(seed);
//	
//	std::shuffle(v.begin(), v.end() , eng);
	
	
	while( true ){
		if( L > R ) break ; 
		
			int l = L , r = L + len ;
			r = min( n - 1 , r ) ; 
//			gg( l , r ) ;
			while( true ){
				if( ask( l , r ) == 'N' ) break ;
				go( l , r ) ;
				for( int i = l ; i <= r ; i ++ ) if( ans[ i ] == '1' ) l = i + 1 ; 
				if( l > r ) break ;
			}
		L = r + 1 ;
    }
    
    
		string nns = ans ;
		FOR( i , n ) nns[ i ] = '0' ;
		FOR( i , n ) if( ans[ i ] == '1' ) nns[ v[ i ] ] = '1' ;
		
		
		cout << "A " << nns << endl ;
		char c ; cin >> c ;
		return ;
	
//	gg( 0 , n - 1 ) ; 
//	cout << "A " << ans << endl ;
//	char c ; cin >> c ;	
}
signed main() {
   srand(time(0)) ;
   ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
   cin >> n >> p >> t ; 
   T = t ;
   FOR( i , n ) s += '0' , ans += '0' ; 
   
	pair < int , int > mn = { INT_MAX , n } ;   
	int nmb = ( n * p ) ;
	for( int i = 1 ; i <= n ; i ++ ){
	//	if( i * p < 1 ) continue ;
		int cc = 0 , ii = i ;
		while( ii > 0 ){
			cc ++ ; ii /= 2 ; 
		}
		
		if( ( cc * nmb + ( ( n + i - 1 ) / i ) ) < mn.f ){
			mn.f = cc * nmb + ( ( n + i - 1 ) / i ) ; 
			mn.s = i ; 
		}
	}
	
	len = mn.s ;    
//	 cout << mn.f << " " << mn.s << endl ;
	 
   while( t -- ){
   	 solve() ;
   }

}




# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 6 ms 344 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 6 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Correct 5 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 344 KB Output is correct (P=0.001, F=15.1, Q=10.9) -> 90.00 points
2 Correct 89 ms 344 KB Output is correct (P=0.005256, F=51.1, Q=47.6) -> 90.00 points
3 Correct 189 ms 344 KB Output is correct (P=0.011546, F=94.9, Q=93.0) -> 90.00 points
4 Correct 380 ms 344 KB Output is correct (P=0.028545, F=191.5, Q=194.6) -> 84.53 points
5 Correct 479 ms 344 KB Output is correct (P=0.039856, F=246.3, Q=253.2) -> 80.93 points
6 Correct 734 ms 344 KB Output is correct (P=0.068648, F=366.2, Q=383.3) -> 75.84 points
7 Correct 981 ms 344 KB Output is correct (P=0.104571, F=490.3, Q=507.4) -> 78.98 points
8 Correct 1336 ms 344 KB Output is correct (P=0.158765, F=639.1, Q=685.0) -> 69.91 points
9 Correct 1499 ms 344 KB Output is correct (P=0.2, F=731.4, Q=758.3) -> 78.46 points