QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#111152 | #3236. Hills And Valleys | Sorting | 0 | 30ms | 11504kb | C++20 | 2.4kb | 2023-06-06 06:01:39 | 2023-06-06 06:01:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MAXN = 1e5 + 7 ;
int n ;
string a ;
int pref[ MAXN ][ 10 ] , suff[ MAXN ][ 10 ] ;
pii dp[ 10 ][ 10 ][ 10 ] ;
void solve ( ) {
cin >> n ;
cin >> a ;
a = '#' + a ;
for ( int i = 1 ; i <= n ; ++ i ) {
for ( int j = 0 ; j < 10 ; ++ j ) {
pref[ i ][ j ] = pref[ i - 1 ][ j ] ;
}
++ pref[ i ][ ( a[ i ] - '0' ) ] ;
for ( int j = 1 ; j < 10 ; ++ j ) {
pref[ i ][ j ] = max ( pref[ i ][ j ] , pref[ i ][ j - 1 ] ) ;
}
}
for ( int i = 0 ; i < 10 ; ++ i ) {
suff[ n + 1 ][ i ] = 0 ;
}
for ( int i = n ; i >= 1 ; -- i ) {
for ( int j = 0 ; j < 10 ; ++ j ) {
suff[ i ][ j ] = suff[ i + 1 ][ j ] ;
}
++ suff[ i ][ ( a[ i ] - '0' ) ] ;
for ( int j = 8 ; j >= 0 ; -- j ) {
suff[ i ][ j ] = max ( suff[ i ][ j ] , suff[ i ][ j + 1 ] ) ;
}
}
for ( int i = 0 ; i < 10 ; ++ i ) {
for ( int j = 0 ; j < 10 ; ++ j ) {
for ( int t = 0 ; t < 10 ; ++ t ) {
dp[ i ][ j ][ t ] = { 0 , 0 } ;
}
}
}
int ans = pref[ n ][ 9 ] , l = 1 , r = 1 ;
for ( int i = n ; i >= 1 ; -- i ) {
int x = ( a[ i ] - '0' ) ;
for ( int st = 1 ; st <= x ; ++ st ) {
for ( int en = x ; en < 10 ; ++ en ) {
pii mx ;
for ( int mid = st ; mid <= x ; ++ mid ) {
mx = max ( mx , dp[ st ][ en ][ mid ] ) ;
}
if ( mx.fi == 0 ) { continue ; }
dp[ st ][ en ][ x ] = { mx.fi + 1 , mx.se } ;
if ( ans < mx.fi + 1 + pref[ i - 1 ][ st ] ) {
ans = mx.fi + 1 + pref[ i - 1 ][ st ] ;
l = i , r = mx.se ;
}
}
}
for ( int en = x ; en < 10 ; ++ en ) {
dp[ x ][ en ][ x ] = max ( dp[ x ][ en ][ x ] , make_pair ( suff[ i + 1 ][ en ] + 1 , i ) ) ;
}
}
cout << ans << " " << l << " " << r << "\n" ;
}
int main ( ) {
ios_base :: sync_with_stdio ( false ) ;
cin.tie ( NULL ) ;
int t = 1 ; cin >> t ;
while ( t -- ) { solve ( ) ; }
return 0 ;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 30ms
memory: 11504kb
input:
100 564 3348010339062339968164170543732424036101480063385567796871300633327190066610177797479597931706239956680908434521050648311220502482402268964497684451036156162125014743550622955579737715237323508714467463047351532756224409691528642332476831673220319724437158730801472447651264708417183934709815...
output:
106 135 473 296 760 1295 1419 1 1585 89 87 350 870 1553 1808 262 626 1239 338 190 982 258 950 1736 847 3 359 1804 43 1416 100 169 531 102 195 479 95 182 293 263 375 1196 1306 1422 1450 296 320 1471 100 56 239 107 177 471 356 635 1018 1108 1 1778 96 293 482 1094 538 1098 1039 1151 1156 706 533 1340 5...
result:
wrong answer read m = 106 but expected m = 108 (test case 1)