QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#332115 | #7940. Impossible Numbers | UNos_maricones | WA | 1ms | 3852kb | C++20 | 2.6kb | 2024-02-19 09:13:34 | 2024-02-19 09:13:35 |
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< set< 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 )
{
set< int > arr;
for( int j = 0; j < 6; ++ j )
{
int x;
cin >> x;
arr.insert( x );
}
for( auto d : arr )
++cn[d];
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 ) ) );
for( int f = 0; f < k; ++ f )
{
auto it = bad.begin();
const string curr = (*it).s;
cout << curr << " \n"[f==k-1];
bad.erase( it );
{
string nx = curr;
const int m = (int) nx.size();
int carry = 1;
for( int i = m - 1; carry && i >= 0; -- i )
{
if( nx[i] == '9' ) nx[i] = '0', carry = 1;
else nx[i]++, carry = 0;
}
if( carry ) nx = "1" + nx;
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' && !bad.count( number( nx ) ) && !can( nx ) )
bad.insert( number( nx ) );
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3632kb
input:
2 3 1 8 7 0 6 2 1 2 5 4 9 3
output:
33 34 35
result:
ok single line: '33 34 35'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
1 10 1 5 2 2 6 4
output:
3 7 8 9 10 11 12 13 14 15
result:
ok single line: '3 7 8 9 10 11 12 13 14 15'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
4 10 1 5 7 1 2 4 0 1 5 8 9 4 3 5 2 2 7 8 6 1 7 0 2 2
output:
33 66 99 133 166 199 233 266 299 303
result:
ok single line: '33 66 99 133 166 199 233 266 299 303'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
5 10 5 9 4 8 3 3 1 1 9 2 8 9 6 3 3 0 2 1 2 6 0 3 6 4 3 6 4 2 9 4
output:
7 17 27 37 47 55 57 67 70 71
result:
ok single line: '7 17 27 37 47 55 57 67 70 71'
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3852kb
input:
5 10 8 7 1 4 8 9 2 5 0 1 0 1 9 5 5 3 9 7 6 0 0 2 3 1 1 0 0 4 9 3
output:
66 88 166 188 222 266 288 366 388 444
result:
wrong answer 1st lines differ - expected: '66 88 166 188 222 226 262 266 288 366', found: '66 88 166 188 222 266 288 366 388 444'