Submission #32048

#TimeUsernameProblemLanguageResultExecution timeMemory
32048chonkaUnscrambling a Messy Bug (IOI16_messy)C++98
100 / 100
4 ms640 KiB
#include<iostream> #include<stdio.h> #include<vector> #include<string> #include "messy.h" using namespace std ; #define MAXN 157 int N ; void init ( int l , int r ) { if ( l >= r ) { return ; } int i ; string cur ; cur.clear ( ) ; for ( i = 0 ; i < N ; i ++ ) { cur += '1' ; } for ( i = l ; i <= r ; i ++ ) { cur[ i ] = '0' ; } int mid = ( l + r ) / 2 ; for ( i = l ; i <= mid ; i ++ ) { cur[ i ] = '1' ; add_element ( cur ) ; cur[ i ] = '0' ; } init ( l , mid ) ; init ( mid + 1 , r ) ; } vector < int > solve ( vector < int > v ) { if ( v.size ( ) <= 1 ) { return v ; } int i ; string cur ; cur.clear ( ) ; for ( i = 0 ; i < N ; i ++ ) { cur += '1' ; } int sz = v.size ( ) ; for ( i = 0 ; i < sz ; i ++ ) { cur[ v[ i ] ] = '0' ; } vector < int > l , r ; l.clear ( ) ; r.clear ( ) ; for ( i = 0 ; i < sz ; i ++ ) { cur[ v[ i ] ] = '1' ; if ( check_element ( cur ) == true ) { l.push_back ( v[ i ] ) ; } else { r.push_back ( v[ i ] ) ; } cur[ v[ i ] ] = '0' ; } l = solve ( l ) ; r = solve ( r ) ; sz = r.size ( ) ; for ( i = 0 ; i < sz ; i ++ ) { l.push_back ( r[ i ] ) ; } return l ; } std::vector<int> restore_permutation(int n, int w, int r) { N = n ; init ( 0 , n - 1 ) ; compile_set(); int i , j ; vector < int > aux ; aux.clear ( ) ; for ( i = 0 ; i < n ; i ++ ) { aux.push_back ( i ) ; } aux = solve ( aux ) ; vector < int > ret ; ret.clear ( ) ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( aux[ j ] == i ) { ret.push_back ( j ) ; break ; } } } return ret ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...