Submission #72567585


Source Code Expand

#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <ranges>
#include <limits>
#include <numeric>
#include <utility>
#include <type_traits>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std;
using namespace placeholders;

using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VLL = vector< long long >;
using VVLL = vector< vector< long long > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< VT< T > >;
using VS = vector< string >;
using ISS = istringstream;
using OSS = ostringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using LIM = numeric_limits< T >;
template < typename T = int > using OSI = ostream_iterator< T >;

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }

void in_impl(){};
template < typename T, typename... TS > void in_impl( T &head, TS &... tail ){ cin >> head; in_impl( tail ... ); }
#define IN( T, ... ) T __VA_ARGS__; in_impl( __VA_ARGS__ );

template < typename T, typename V >
auto make_vector( const int n, const V &v )
{
	return vector< T >( n, v );
}
template < typename T, typename... TS >
auto make_vector( const int n, TS... ts )
{
	return vector< decltype( make_vector< T >( forward< TS >( ts )...) ) >( n, make_vector< T >( forward< TS >( ts )... ) );
}
template < typename T, typename V >
auto make_vector0()
{
	return vector< T >();
}
template < typename T, typename... TS >
auto make_vector0( const int n, TS... ts )
{
	return vector< decltype( make_vector0< T >( forward< TS >( ts )...) ) >( n, make_vector0< T >( forward< TS >( ts )... ) );
}

template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define NUMBERED( name, number ) NUMBERED2( name, number )
#define NUMBERED2( name, number ) name ## _ ## number
#define REP1( n ) REP2( NUMBERED( REP_COUNTER, __LINE__ ), n )
#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2, REP1 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
template < typename C, typename F > void EACH( C &c, const F &&f ) { std::for_each( std::begin( c ), std::end( c ), f ); }
#define ALL( c ) begin( c ), end( c )
#define AALL( a ) ( remove_all_extents< decltype( a ) >::type * )a, ( remove_all_extents< decltype( a ) >::type * )a + sizeof( a ) / sizeof( remove_all_extents< decltype( a ) >::type )

#define MAP_PRED( c ) transform( begin( c ), end( c ), begin( c ), bind( minus< int >(), _1, 1 ) );

#define SZ( v ) ( (int)( v ).size() )
#define EXISTS( c, e ) ( ( c ).find( e ) != ( c ).end() )

template < typename T > inline bool chmin( T &a, const T &b ){ if ( b < a ) { a = b; return true; } return false; }
template < typename T > inline bool chmax( T &a, const T &b ){ if ( a < b ) { a = b; return true; } return false; }

inline std::string YES( const bool l ){ return l ? "YES" : "Yes"; }
inline std::string NO( const bool l ){ return l ? "NO" : "No"; }
inline std::string YESNO( const bool f, const bool l = false ){ return f ? YES( l ) : NO( l ); }
constexpr char LF = '\n';

#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

//     Λ   Λ__
//  /(*゚ー゚)/\
// /|  ̄U U ̄|\/
//   |      |/

constexpr auto INF = LIM< LL >::max() / 2;

int main()
{
	cin.tie( nullptr );
	ios::sync_with_stdio( false );
	cout << setprecision( 12 ) << fixed;

	IN( int, N, M );
	VI P( N ), V( N );
	REP( i, N )
	{
		cin >> P[i] >> V[i];
	}

	static LL dp1[ 1 << 10 ][ 1 << 16 ], dp2[ 1 << 10 ][ 1 << 16 ];
	fill( AALL( dp2 ), -INF );
	fill( AALL( dp2 ), -INF );
	// dp[ # of considered ][ sum of P_i ] := max sum V
	dp1[0][0] = dp2[N][0] = 0;
	REP( i, N )
	{
		REP( j, M + 1 )
		{
			chmax( dp1[ i + 1 ][j], dp1[i][j] );
			if ( j + P[i] <= M )
			{
				chmax( dp1[ i + 1 ][ j + P[i] ], dp1[i][j] + V[i] );
			}
		}
	}
	for ( int i = N; 0 < i; --i )
	{
		REP( j, M + 1 )
		{
			chmax( dp2[ i - 1 ][j], dp2[i][j] );
			if ( j + P[ i - 1 ] <= M )
			{
				chmax( dp2[ i - 1 ][ j + P[ i - 1 ] ], dp2[i][j] + V[ i - 1 ] );
			}
		}
	}

// 	REP( i, N + 1 )
// 	{
// 		REP( j, M )
// 		{
// 			chmax( dp1[i][ j + 1 ], dp1[i][j] );
// 			chmax( dp2[i][ j + 1 ], dp2[i][j] );
// 		}
// 	}

	const LL ma = *max_element( begin( dp1[N] ), begin( dp1[N] ) + M + 1 );

	string res( N, '-' );
	REP( i, N )
	{
		bool inc = false, exc = false;
		REP( j, M - P[i] + 1 )
		{
			inc |= dp1[i][j] + dp2[ i + 1 ][ M - P[i] - j ] + V[i] == ma;
		}
		REP( j, M + 1 )
		{
			exc |= dp1[i][j] + dp2[ i + 1 ][ M - j ] == ma;
		}

		if ( inc && !exc )
		{
			res[i] = 'A';
		}
		else if ( inc && exc )
		{
			res[i] = 'B';
		}
		else
		{
			res[i] = 'C';
		}
	}

	cout << res << endl;

	return 0;
}

Submission Info

Submission Time
Task F - Must Buy
User torus711
Language C++23 (GCC 15.2.0)
Score 500
Code Size 5856 Byte
Status AC
Exec Time 727 ms
Memory 920020 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 50
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name Status Exec Time Memory
example_00.txt AC 263 ms 528084 KiB
example_01.txt AC 254 ms 528036 KiB
hand_00.txt AC 696 ms 919808 KiB
hand_01.txt AC 593 ms 723840 KiB
hand_02.txt AC 661 ms 917620 KiB
hand_03.txt AC 678 ms 919960 KiB
hand_04.txt AC 685 ms 919988 KiB
hand_05.txt AC 390 ms 654276 KiB
hand_06.txt AC 602 ms 729396 KiB
hand_07.txt AC 301 ms 555892 KiB
hand_08.txt AC 590 ms 731904 KiB
hand_09.txt AC 696 ms 919924 KiB
hand_10.txt AC 682 ms 919916 KiB
hand_11.txt AC 503 ms 531908 KiB
hand_12.txt AC 262 ms 528196 KiB
hand_13.txt AC 253 ms 528372 KiB
hand_14.txt AC 273 ms 539776 KiB
hand_15.txt AC 676 ms 919880 KiB
hand_16.txt AC 675 ms 919984 KiB
hand_17.txt AC 686 ms 920020 KiB
random_00.txt AC 674 ms 917020 KiB
random_01.txt AC 671 ms 914540 KiB
random_02.txt AC 676 ms 915396 KiB
random_03.txt AC 280 ms 551728 KiB
random_04.txt AC 276 ms 547644 KiB
random_05.txt AC 373 ms 638292 KiB
random_06.txt AC 354 ms 618612 KiB
random_07.txt AC 474 ms 729736 KiB
random_08.txt AC 468 ms 718340 KiB
random_09.txt AC 677 ms 904704 KiB
random_10.txt AC 684 ms 918832 KiB
random_11.txt AC 691 ms 917576 KiB
random_12.txt AC 688 ms 917192 KiB
random_13.txt AC 698 ms 919204 KiB
random_14.txt AC 696 ms 919540 KiB
random_15.txt AC 726 ms 917308 KiB
random_16.txt AC 727 ms 911752 KiB
random_17.txt AC 705 ms 914076 KiB
random_18.txt AC 716 ms 917504 KiB
random_19.txt AC 695 ms 919196 KiB
random_20.txt AC 705 ms 914456 KiB
random_21.txt AC 688 ms 917660 KiB
random_22.txt AC 690 ms 914048 KiB
random_23.txt AC 680 ms 917188 KiB
random_24.txt AC 681 ms 919556 KiB
random_25.txt AC 686 ms 917296 KiB
random_26.txt AC 681 ms 911932 KiB
random_27.txt AC 706 ms 914508 KiB
random_28.txt AC 701 ms 914816 KiB
random_29.txt AC 702 ms 919192 KiB