QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#357676 | #7940. Impossible Numbers | teikn | WA | 14ms | 4840kb | C++20 | 3.6kb | 2024-03-19 07:51:50 | 2024-03-19 07:51:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#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()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int procc=0;
struct genr {
map<int,int> inclp;
int k;
int inclc=0;
int recdep;
deque<int> digs;
genr(set<int>const&incld,int k):k(k){
auto it = incld.end();it--;
int p=*it;
for(int d:incld)inclp[p]=d,p=d;
it = incld.begin();
int lo=*it;
int v=lo?lo:*++it;
digs.push_back(v);
inclc=1;
while(inclc<=k)inclc++,digs.push_back(lo);
}
int next()const{
int v=0;
for(int d:digs)v=v*10+d;
return v;
}
void step(int restorincls=-1){
if(restorincls==-1){
// cout<<"STart:";
// pp();
procc++;
recdep=1;
restorincls=inclc==k+1;
} else {
recdep++;
}
// if(procc==2){
// cout<<"Proc:"<<next()<<endl;
// }
if(!sz(digs)){
digs.push_back(1);
if(inclp.count(1))inclc++;
recdep--;
return;
}
int ld=digs.back();
int nld=(ld+1)%10;
if(inclp.count(ld)){
inclc--;
if(restorincls){
nld=inclp[ld];
}
}
// if(procc==2)
// cout<<" ld,nld:"<<ld<<','<<nld<<'\n';
if(nld>ld){
digs.back()=nld;
if(inclp.count(nld))inclc++;
recdep--;
return;
}
if(restorincls&&!inclp.count(ld))restorincls=0;
digs.pop_back();
step(restorincls);
int spaceleft=recdep;
int nummoreneeded=k+1-inclc;
assert(nummoreneeded<=spaceleft);
if(spaceleft==nummoreneeded)nld=inclp.begin()->first;
else nld=0;
digs.push_back(nld);
if(inclp.count(nld))inclc++;
recdep--;
}
void pp(){
for(auto [a,b]:inclp)cout<<a<<"->"<<b<<" ";
cout<<next()<<'\n';
}
};
struct genrcomp {
bool operator()(genr const *a, genr const *b)const{return a->next()>b->next();}
};
int hasinter(set<int>const&a,set<int>const&b){
const set<int> *sm=&a,*la=&b;
if(sz(a)>sz(b))sm=&b,la=&a;
for(int v:*sm)if(la->count(v))return 1;
return 0;
}
int main() {
int n,k,v;cin>>n>>k;
vector<set<int>> cubes(n);
rep(i,0,n)rep(j,0,6)cin>>v,cubes[i].insert(v);
priority_queue<genr*,vector<genr*>,genrcomp> genrs;
set<int> incl;
int p=0,ko;
rep(m,2,1<<10){
rep(i,0,10)if((p^m)&(1<<i)){
if(p&(1<<i))incl.erase(i);
else incl.insert(i);
}
ko=0;
for(auto&s:cubes)ko+=hasinter(s,incl);
genrs.push(new genr(incl,ko));
p=m;
}
string sep="";
while(k--){
// vector<genr*> store;
// rep(i,0,10){
// genrs.top()->pp();
// store.push_back(genrs.top());
// genrs.pop();
// }
// for(genr*g:store)genrs.push(g);
// cout<<"\n";
int v=genrs.top()->next();
cout<<sep<<v;
// cout<<"\n\n";
sep=" ";
while(v==genrs.top()->next()){
genr*t=genrs.top();
genrs.pop();
t->step();
genrs.push(t);
}
}
cout<<endl;
// while(sz(genrs)){
// genrs.top()->pp();
// genrs.pop();
// }
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4548kb
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: 4476kb
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: 4484kb
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: 4588kb
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: 1ms
memory: 4592kb
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: 4664kb
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: 0
Accepted
time: 0ms
memory: 4576kb
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 575 577 585 595 655 666 755 757 775 777 855 888 955 1055 1111 1116 1119 1155 1161 1166 1169 1191 1196 1199 1255 1333 1335 1353 1355 1455 1505 1515 1525 1533 1535 1545 1550 1551 1552 1553 1554 1555 1556...
result:
ok single line: '55 155 255 333 335 353 355 455...0 10053 10055 10111 10116 10119'
Test #8:
score: 0
Accepted
time: 14ms
memory: 4488kb
input:
5 10000 1 4 7 5 6 0 2 3 8 4 9 0 1 2 8 8 3 0 7 9 9 7 2 9 4 7 1 9 3 6
output:
55 155 255 355 455 505 515 525 535 545 550 551 552 553 554 555 556 557 558 559 565 566 575 585 595 655 656 665 666 755 855 888 955 1055 1111 1115 1116 1151 1155 1156 1161 1165 1166 1255 1355 1455 1505 1511 1515 1516 1525 1535 1545 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1561 1565 1566 1575...
result:
ok single line: '55 155 255 355 455 505 515 525...6 45507 45508 45509 45510 45511'
Test #9:
score: -100
Wrong Answer
time: 4ms
memory: 4840kb
input:
6 10000 0 1 3 2 4 7 7 6 4 8 7 9 5 5 7 2 3 9 8 4 6 1 6 4 2 4 9 9 0 7 1 2 3 3 2 0
output:
55 155 255 355 455 505 515 525 535 545 550 551 552 553 554 555 556 557 558 559 565 575 585 595 655 666 668 686 688 755 855 866 868 886 888 955 1055 1111 1155 1255 1355 1455 1505 1515 1525 1535 1545 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1565 1575 1585 1595 1655 1666 1668 1686 1688 1755 18...
result:
wrong answer 1st lines differ - expected: '55 155 255 355 455 505 515 525...6 66847 66848 66849 66850 66851', found: '55 155 255 355 455 505 515 525...8 66849 66850 66851 66852 66853'