QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#332102 | #7940. Impossible Numbers | UNos_maricones# | WA | 1ms | 3548kb | C++20 | 2.4kb | 2024-02-19 08:52:48 | 2024-02-19 08:52:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int D = 10;
struct mbm {
int l, r;
vector< int > seen, match;
vector< vector< int > > g;
mbm( int _l, int _r ) : l( _l ), r ( _r ), seen( _r ), match( _r ), g ( _l ) { }
void add_edge( int _l, int _r ) { g[_l].push_back( _r ); }
bool dfs( int u ) {
for( auto v : g[u] ) {
if( seen[v]++ ) continue;
if( match[v] == -1 || dfs( match[v] ) ) {
match[v] = u;
return true;
}
}
return false;
}
int max_matching() {
int ans = 0;
fill( match.begin(), match.end(), -1 );
for( int u = 0; u < l; ++ u )
{
fill( seen.begin(), seen.end(), 0 );
ans += dfs( u );
}
return ans;
}
};
vector< vector< int > > dices;
bool can( const string &s )
{
mbm aMatching( (int) s.size(), (int) dices.size() );
for( int i = 0; i < (int) s.size(); ++ i )
{
const int target = s[i] - '0';
for( int idx = 0; idx < (int) dices.size(); ++ idx )
{
for( auto &dig : dices[idx] )
if( dig == target )
aMatching.add_edge( i, idx );
}
}
return aMatching.max_matching() == (int) s.size();
}
struct number
{
string s;
number( string _s ) : s ( _s ) {}
};
bool operator < ( const number &a, const number &b )
{
if( a.s.size() != b.s.size() )
return a.s.size() < b.s.size();
return a.s < b.s;
}
int main()
{
cin.tie( NULL );
ios_base::sync_with_stdio( 0 );
int n, k;
cin >> n >> k;
vector< int > cn( D );
for( int i = 0; i < n; ++ i )
{
vector< int > arr( 6 );
for( int j = 0; j < 6; ++ j )
{
cin >> arr[j];
++cn[arr[j]];
}
dices.push_back( arr );
}
set< number > bad;
string d0 = "1" + string( cn[0] + 1, '0' );
bad.insert( number( d0 ) );
for( int i = 1; i < D; ++ i )
bad.insert( number( string( cn[i] + 1, '0' + i ) ) );
while( k-- )
{
auto it = bad.begin();
const string curr = (*it).s;
cout << curr << '\n';
bad.erase( it );
if( curr.back() != '9' )
{
string nx = curr;
++nx.back();
if( !can( nx ) ) bad.insert( number( nx ) );
}
for( int i = 0; i < D; ++ i )
{
for( int idx = 0; idx <= (int) curr.size(); ++ idx )
{
string nx = curr.substr( 0, idx );
nx.push_back( i + '0' );
nx += curr.substr( idx );
if( nx[0] != '0' && !can( nx ) )
bad.insert( number( nx ) );
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3548kb
input:
2 3 1 8 7 0 6 2 1 2 5 4 9 3
output:
33 34 35
result:
wrong answer 1st lines differ - expected: '33 34 35', found: '33'