QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#73077 | #5161. Last Guess | Sorting# | WA | 39ms | 10460kb | C++ | 5.3kb | 2023-01-21 22:36:00 | 2023-01-21 22:36:03 |
Judging History
answer
#include<bits/stdc++.h>
#include<bits/extc++.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());
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
const ll INF = numeric_limits < ll > :: max ( ) / 4 ;
typedef vector < ll > VL ;
struct MCMF {
int N ;
vector < vi > ed , red ;
vector < VL > cap , flow , cost ;
vi seen ;
VL dist , pi ;
vector < pii > par ;
MCMF ( int N ) :
N( N ) , ed ( N ) , red ( N ) , cap ( N , VL ( N ) ) ,
flow ( cap ) , cost ( cap ) , seen ( N ) , dist ( N ) ,
pi ( N ) , par ( N ) { }
void addEdge ( int from , int to , ll cap , ll cost ) {
this->cap[ from ][ to ] = cap ;
this->cost[ from ][ to ] = cost ;
ed[ from ].push_back ( to ) ;
red[ to ].push_back ( from ) ;
}
void path ( int s ) {
fill ( all ( seen ) , 0 ) ;
fill ( all ( dist ) , INF ) ;
dist[ s ] = 0 ; ll di ;
__gnu_pbds :: priority_queue < pair < ll , int > > q ;
vector < decltype ( q ) :: point_iterator > its ( N ) ;
q.push ( { 0 , s } ) ;
auto relax = [ & ] ( int i , ll cap , ll cost , int dir ) {
ll val = di - pi[ i ] + cost ;
if ( cap && val < dist[ i ] ) {
dist[ i ] = val ;
par[ i ] = { s , dir } ;
if ( its[ i ] == q.end ( ) ) { its[ i ] = q.push ( { -dist[ i ] , i } ) ; }
else { q.modify ( its[ i ] , { -dist[ i ] , i } ) ; }
}
};
while ( !q.empty ( ) ) {
s = q.top ( ).second ; q.pop ( ) ;
seen[ s ] = 1 ; di = dist[ s ] + pi[ s ] ;
for ( int i : ed[ s ] )
if ( !seen[ i ] )
relax ( i , cap[ s ][ i ] - flow[ s ][ i ] , cost[ s ][ i ] , 1 ) ;
for ( int i : red[ s ] )
if ( !seen[ i ] )
relax ( i , flow[ i ][ s ] , -cost[ i ][ s ] , 0 ) ;
}
rep ( i , 0 , N ) pi[ i ] = min ( pi[ i ] + dist[ i ] , INF ) ;
}
pair < ll , ll > maxflow ( int s , int t ) {
ll totflow = 0 , totcost = 0 ;
while ( path ( s ) , seen[ t ] ) {
ll fl = INF ;
for ( int p , r , x = t ; tie ( p , r ) = par[ x ] , x != s ; x = p )
fl = min ( fl , r ? cap[ p ][ x ] - flow[ p ][ x ] : flow[ x ][ p ] ) ;
totflow += fl ;
for ( int p , r , x = t ; tie ( p , r ) = par[ x ] , x != s ; x = p ) {
if ( r ) flow[ p ][ x ] += fl ;
else flow[ x ][ p ] -= fl ;
}
}
rep ( i , 0 , N ) rep ( j , 0 , N ) totcost += cost[ i ][ j ] * flow[ i ][ j ] ;
return { totflow , totcost } ;
}
};
const int MAXN = 507 ;
int g , n ;
int fix[ MAXN ] ;
int cnt[ 26 ] ;
int mn[ 26 ] ;
int foo[ 26 ] ;
bool ban[ 26 ] ;
int ctr[ MAXN ][ 26 ] ;
void solve ( ) {
cin >> g >> n ;
for ( int i = 0 ; i < 26 ; ++ i ) {
cnt[ i ] = MAXN , mn[ i ] = 0 ;
}
for ( int i = 1 ; i <= n ; ++ i ) {
fix[ i ] = -1 ;
}
-- g ;
while ( g -- ) {
for ( int i = 0 ; i < 26 ; ++ i ) {
foo[ i ] = 0 ;
ban[ i ] = false ;
}
string a , ret ;
cin >> a >> ret ;
for ( int i = 1 ; i <= n ; ++ i ) {
if ( ret[ i - 1 ] == 'G' ) {
fix[ i ] = ( a[ i - 1 ] - 'a' ) ;
}
else {
++ ctr[ i ][ a[ i - 1 ] - 'a' ] ;
}
if ( ret[ i - 1 ] == 'G' || ret[ i - 1 ] == 'Y' ) {
++ foo[ a[ i - 1 ] - 'a' ] ;
}
else {
ban[ a[ i - 1 ] - 'a' ] = true ;
}
}
for ( int i = 0 ; i < 26 ; ++ i ) {
mn[ i ] = max ( mn[ i ] , foo[ i ] ) ;
if ( ban[ i ] == true ) {
cnt[ i ] = foo[ i ] ;
}
}
}
MCMF aux ( n + 26 + 1 + 1 + 1 + 3 ) ;
int source = n + 26 + 1 , target = n + 26 + 2 , foo = n + 26 + 3 ;
for ( int i = 1 ; i <= n ; ++ i ) {
aux.addEdge ( i , target , 1 , 0 ) ;
}
for ( int i = 0 ; i < 26 ; ++ i ) {
aux.addEdge ( source , n + i + 1 , mn[ i ] , 0 ) ;
aux.addEdge ( foo , n + i + 1 , n + 1 , 0 ) ;
}
aux.addEdge ( source , foo , n + 1 , 1 ) ;
for ( int i = 1 ; i <= n ; ++ i ) {
if ( fix[ i ] != -1 ) {
aux.addEdge ( n + fix[ i ] + 1 , i , 1 , 0 ) ;
}
else {
for ( int j = 0 ; j < 26 ; ++ j ) {
if ( ctr[ i ][ j ] == 0 ) {
aux.addEdge ( n + j + 1 , i , 1 , 0 ) ;
}
}
}
}
auto [ ret1 , ret2 ] = aux.maxflow ( source , target ) ;
for ( int i = 1 ; i <= n ; ++ i ) {
for ( int j = 0 ; j < 26 ; ++ j ) {
if ( aux.flow[ n + j + 1 ][ i ] > 0 ) {
cout << char ( 'a' + j ) ;
break ;
}
}
}
cout << "\n" ;
}
int main ( ) {
ios_base :: sync_with_stdio ( false ) ;
cin.tie ( NULL ) ;
int t = 1 ; // cin >> t ;
while ( t -- ) { solve ( ) ; }
return 0 ;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3488kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 2ms
memory: 3544kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabzcabbadde
result:
ok
Test #3:
score: -100
Wrong Answer
time: 39ms
memory: 10460kb
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...
output:
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzqzzzzzzzz...
result:
FAIL Wrong answer: does not fit word 0