QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#351109#7940. Impossible Numbersmc020207WA 0ms3636kbC++171.4kb2024-03-11 15:46:272024-03-11 15:46:27

Judging History

你现在查看的是最新测评结果

  • [2024-03-11 15:46:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3636kb
  • [2024-03-11 15:46:27]
  • 提交

answer

#include<bits/stdc++.h>
#define MAXN 1000010
#define INF 1000000010
#define INFLL (1LL*INF*INF)
#define MOD 1000000007
#define LL long long
#define LLL __int128_t
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rof(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
int n,k;
int s[1<<11];
set<string> seed;
string cur;
void dp(int now,int msk,int d,int need){
	if (d<need) return ;
	if (d==0){
		auto it=lower_bound(cur.begin(),cur.end(),'1');
        swap(cur[0],cur[it-cur.begin()]);
		if (cur[0]!='0') seed.insert(cur);
		if (seed.size()>k) seed.erase(*seed.rbegin());
		swap(cur[0],cur[it-cur.begin()]);
		return ;
	}
	For(i,now,9){
		cur.push_back(i+'0');
		dp(i,msk,d-1,need-((msk&(1<<i))!=0));
		cur.pop_back();
	}
}
void Main(){
	cin>>n>>k;
	For(i,1,n){
		int msk=0;
		For(j,1,6){
			int t;cin>>t;
			msk|=1<<t;
		}
		For(j,0,(1<<10)-1) if (j&msk) s[j]++;
	}
	For(d,1,1000000000){
		seed.clear();
		For(msk,0,(1<<10)-1){
			if (d>s[msk]) dp(0,msk,d,s[msk]+1);
		}
		priority_queue<string,vector<string>,greater<string> >li;
		for (string x:seed) li.push(x);
		while (!li.empty()){
			string x=li.top();li.pop();
			k--;
			cout<<x<<" ";
			if (next_permutation(x.begin(),x.end())) li.push(x);
			if (!k) return ;
		}
	}
}	
int main(){
	std::ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int T=1;/* cin>>T; */
	while (T--) Main();
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3636kb

input:

2 3
1 8 7 0 6 2
1 2 5 4 9 3

output:


result:

wrong answer 1st lines differ - expected: '33 34 35', found: ''