QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#205160 | #7567. Joining Cats | ucup-team1325# | TL | 1ms | 3488kb | C++17 | 2.6kb | 2023-10-07 15:01:48 | 2023-10-07 15:01:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; typedef unsigned long long ull;
const int inf = 1e9; const ll llnf = 4e18;
template< class Tp > void chkmax( Tp &x , Tp y ) { x = max( x , y ); }
template< class Tp > void chkmin( Tp &x , Tp y ) { x = min( x , y ); }
void solve( ) {
int n , k; cin >> n >> k;
vector< int > a( n + 1 ); for( int i = 1; i <= n; i ++ ) cin >> a[i];
vector< ll > b( k + 2 ); for( int j = 1; j <= k; j ++ ) cin >> b[j]; b[k + 1] = llnf;
vector< ll > sa( n + 1 ); for( int i = 1; i <= n; i ++ ) sa[i] = sa[i - 1] + a[i];
vector< vector< pair< ll , int > > > B( k + 2 );
for( int i = k + 1; i >= 1; i -- ) {
vector< int > ord; for( int j = i; j <= k + 1; j ++ ) ord.emplace_back( j );
sort( ord.begin( ) , ord.end( ) , [&] ( int j1 , int j2 ) -> bool { return b[j1] < b[j2]; } );
int minj = k + 1; for( int j = ( int ) ord.size( ) - 1; j >= 0; j -- ) chkmin( minj , ord[j] ) , B[i].emplace_back( b[ord[j]] , minj ); reverse( B[i].begin( ) , B[i].end( ) );
}
auto least = [&] ( int j , ll v ) -> int { return lower_bound( B[j].begin( ) , B[j].end( ) , make_pair( v , -1 ) ) -> second; } ;
vector< vector< int > > f( n + 1 , vector< int >( n + 1 ) ) , g1( n + 1 , vector< int >( n + 1 ) ) , g2( n + 1 , vector< int >( n + 1 ) );
for( int i = 1; i <= n; i ++ ) f[i][i] = 0 , g1[i][i] = i , g2[i][i] = i;
for( int L = n; L >= 1; L -- ) for( int R = L + 1; R <= n; R ++ ) {
int f1 = least( 1 , sa[R] - sa[L] ); g1[L][R] = L;
for( int M = max( L , g1[L][R - 1] - 5 ); M <= min( R - 1 , g1[L + 1][R] + 5 ); M ++ )
if( f[L][M] <= k ) { int curf = least( f[L][M] + 1 , sa[R] - sa[M] ); if( f1 > curf ) f1 = curf , g1[L][R] = M; }
for( int M = max( L , g2[L][R - 1] - 5 ); M <= min( R - 1 , g2[L + 1][R] + 5 ); M ++ )
if( f[L][M] <= k ) { int curf = least( f[L][M] + 1 , sa[R] - sa[M] ); if( f1 > curf ) f1 = curf , g1[L][R] = M; }
int f2 = least( 1 , sa[R - 1] - sa[L - 1] ); g2[L][R] = R;
for( int M = max( L + 1 , g2[L][R - 1] - 5 ); M <= min( R , g2[L + 1][R] + 5 ); M ++ )
if( f[M][R] <= k ) { int curf = least( f[M][R] + 1 , sa[M - 1] - sa[L - 1] ); if( f2 > curf ) f2 = curf , g2[L][R] = M; }
for( int M = max( L + 1 , g1[L][R - 1] - 5 ); M <= min( R , g1[L + 1][R] + 5 ); M ++ )
if( f[M][R] <= k ) { int curf = least( f[M][R] + 1 , sa[M - 1] - sa[L - 1] ); if( f2 > curf ) f2 = curf , g2[L][R] = M; }
f[L][R] = min( f1 , f2 );
}
cout << ( f[1][n] <= k ? "Yes" : "No" ) << "\n";
}
int main( ) {
ios::sync_with_stdio( 0 ), cin.tie( 0 ), cout.tie( 0 );
int T = 1; while( T -- ) solve( ); return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3424kb
input:
5 2 1 1 1 1 1 2 2
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
6 7 3 2 1 1 2 3 2 2 2 2 2 2 2
output:
No
result:
ok answer is NO
Test #3:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
7 4 1 2 3 4 3 2 1 3 3 3 3
output:
Yes
result:
ok answer is YES
Test #4:
score: 0
Accepted
time: 0ms
memory: 3444kb
input:
5 1 5 4 3 2 1 10
output:
Yes
result:
ok answer is YES
Test #5:
score: -100
Time Limit Exceeded
input:
5000 5000 775487425 856128884 277783434 903422359 477267301 475103384 297595527 426167697 732858986 408894759 274205836 78265305 841664344 827278645 235744961 539622829 661053351 709331224 497285040 688977639 794889854 890450616 730989757 164925481 519732355 5132018 793806705 617096813 966338860 838...