QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#285022 | #7940. Impossible Numbers | ucup-team266# | WA | 1ms | 5792kb | C++20 | 4.0kb | 2023-12-16 16:14:03 | 2023-12-16 16:14:04 |
Judging History
你现在查看的是最新测评结果
- [2023-12-17 13:41:15]
- hack成功,自动添加数据
- (/hack/501)
- [2023-12-16 17:44:29]
- hack成功,自动添加数据
- (//qoj.ac/hack/496)
- [2023-12-16 16:14:03]
- 提交
answer
/*
Things to notice:
1. do not calculate useless values
2. do not use similar names
Things to check:
1. submit the correct file
2. time (it is log^2 or log)
3. memory
4. prove your naive thoughts
5. long long
6. corner case like n=0,1,inf or n=m
7. check if there is a mistake in the ds or other tools you use
8. fileio in some oi-contest
9. module on time
10. the number of a same divisor in a math problem
11. multi-information and queries for dp and ds problems
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
const int mod=998244353;
const int inf=0x3f3f3f3f;
int n,k;
int input_flg[10];
bitset <105> cnt[10],emp;
map <array<int,10>,int> ma;
struct Node
{
int buc[10];
int now[64];
int m;
void construct()
{
m=0;
int minn=0;
for(int i=1;i<10;i++) if(buc[i])
{
minn=i;
now[m++]=i;
break;
}
for(int i=0;i<10;i++)
{
for(int j=0;j<(i==minn?buc[i]-1:buc[i]);j++) now[m++]=i;
}
}
bool nxt()
{
return next_permutation(now,now+m);
}
void print()
{
for(int i=0;i<m;i++) cout<<now[i];
cout<<" ";
}
array<int,10> gethash()
{
return {buc[0],buc[1],buc[2],buc[3],buc[4],buc[5],buc[6],buc[7],buc[8],buc[9]};
}
}a[1000005];
bool cmp(int x,int y)
{
for(int i=0;i<a[x].m;i++) if(a[x].now[i]!=a[y].now[i])
{
return a[x].now[i]<a[y].now[i];
}
return 0;
}
class CMP{
public:
bool operator()(const int& n1, const int& n2){
return !cmp(n1,n2);
}
};
priority_queue <int,vector<int>,CMP > pq,pq2;
int dig=0,tot=0;
void gennext(int id)
{
array <int,10> b=a[id].gethash();
for(int i=0;i<9;i++) if(b[i]>1&&b[i+1])
{
b[i]--,b[i+1]++;
if(!ma[b])
{
ma[b]=1;
tot++;
for(int j=0;j<10;j++) a[tot].buc[j]=b[j];
a[tot].construct();
pq2.push(tot);
}
b[i]++,b[i+1]--;
}
}
void gennext2(int id)
{
array <int,10> b=a[id].gethash();
for(int i=0;i<10;i++)
{
b[i]++;
if(!ma[b])
{
ma[b]=1;
tot++;
for(int j=0;j<10;j++) a[tot].buc[j]=b[j];//,cout<<b[j]<<" ";
// cout<<"\n";
a[tot].construct();
pq2.push(tot);
// gennext(tot);
}
b[i]--;
}
}
void adddig()
{
ma.clear();
int tmp_tot=tot;
// cout<<pq.size()<<" "<<pq2.size()<<"\n";
for(int i=1;i<=tmp_tot;i++) gennext2(i);
// cout<<"...... "<<ma[{0,1,0,1,0,0,0,0,0,0}]<<"\n";
for(int mask=2;mask<(1<<10);mask++) if(__builtin_popcount(mask)<=dig)
{
emp.reset();
int sum=0,minn=inf;
for(int j=0;j<10;j++) if(mask&(1<<j)) emp|=cnt[j],minn=min(minn,(j==0?inf:j));
sum=emp.count();
if(sum>=dig) continue;
tot++;
memset(a[tot].buc,0,sizeof(a[tot].buc));
sum=dig;
for(int j=0;j<10;j++) if(mask&(1<<j)) a[tot].buc[j]++,sum--;
// cout<<"new :\n";
a[tot].buc[minn]+=sum;
if(ma[a[tot].gethash()])
{
tot--;
continue;
}
a[tot].construct();
// a[tot].print();
// cout<<"\n";
// for(int j=0;j<10;j++) cout<<a[tot].gethash()[j]<<" ";
// cout<<ma[a[tot].gethash()]<<"\n";
pq2.push(tot);
ma[a[tot].gethash()]=1;
}
// for(int i=tmp_tot+1;i<=tot;i++)
// {
// for(int j=0;j<10;j++) cout<<a[i].buc[j]<<" ";
// cout<<"\n";
// }
// cout<<pq.size()<<" "<<pq2.size()<<"\n";
}
void work()
{
while(1)
{
if(!pq.size()&&!pq2.size())
{
dig++,adddig();
continue;
}
if(pq2.size()&&(!pq.size()||cmp(pq2.top(),pq.top())))
{
int u=pq2.top();
pq2.pop();
pq.push(u);
gennext(u);
}
int u=pq.top();
pq.pop();
a[u].print();
// system("pause");
// cout<<k<<"\n";
if(a[u].nxt()) pq.push(u);
break;
}
}
void solve()
{
cin>>n>>k;
for(int j=0;j<n;j++)
{
memset(input_flg,0,sizeof(input_flg));
for(int i=0;i<6;i++)
{
int x;
cin>>x;
input_flg[x]=1;
}
for(int i=0;i<10;i++) if(input_flg[i]) cnt[i][j]=1;
}
while(k--) work();
}
signed main()
{
// freopen("output.txt","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int _=1;
// cin>>_;
while(_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3596kb
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: 3748kb
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: 0ms
memory: 3688kb
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: 0ms
memory: 3676kb
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: 0
Accepted
time: 0ms
memory: 3736kb
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 226 262 266 288 366
result:
ok single line: '66 88 166 188 222 226 262 266 288 366 '
Test #6:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
5 10 6 8 7 7 0 0 0 5 1 9 4 1 5 9 6 9 5 4 0 4 6 9 1 6 2 8 7 4 4 0
output:
3 13 22 23 30 31 32 33 34 35
result:
ok single line: '3 13 22 23 30 31 32 33 34 35 '
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 5792kb
input:
5 1000 0 4 1 3 9 6 9 6 2 1 8 6 5 3 0 7 7 3 0 2 8 0 8 4 2 4 1 2 9 7
output:
55 155 255 333 335 353 355 455 505 515 525 533 535 545 550 551 552 553 554 555 556 557 558 559 565 566 575 585 595 655 656 665 666 755 777 855 888 955 1055 1111 1116 1119 1155 1161 1169 1191 1196 1255 1333 1335 1353 1355 1455 1505 1515 1525 1533 1535 1545 1550 1551 1552 1553 1554 1555 155 1556 1557 ...
result:
wrong answer 1st lines differ - expected: '55 155 255 333 335 353 355 455...0 10053 10055 10111 10116 10119', found: '55 155 255 333 335 353 355 455... 10533 10535 10545 10550 10551 '