QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#285017#7940. Impossible Numbersucup-team266#WA 1ms3476kbC++204.0kb2023-12-16 16:13:262023-12-16 16:13:26

Judging History

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

  • [2023-12-17 13:41:15]
  • hack成功,自动添加数据
  • (/hack/501)
  • [2023-12-16 16:13:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3476kb
  • [2023-12-16 16:13:26]
  • 提交

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=minn+1;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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3476kb

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: -100
Wrong Answer
time: 0ms
memory: 3384kb

input:

1 10
1 5 2 2 6 4

output:

3 7 8 9 11 12 13 14 15 16 

result:

wrong answer 1st lines differ - expected: '3 7 8 9 10 11 12 13 14 15', found: '3 7 8 9 11 12 13 14 15 16 '