QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#285068#7940. Impossible Numbersucup-team266#WA 1ms3728kbC++204.2kb2023-12-16 16:25:462023-12-16 16:25:47

Judging History

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

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

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[1500005];
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++) for(int j=i+1;j<10;j++) if(b[i]>1&&b[j])
	{
		b[i]--,b[j]++;
		if(!ma[b]) 
		{
			ma[b]=1;
			tot++;
			memset(a[tot].buc,0,sizeof(a[tot].buc));
			for(int l=0;l<10;l++) a[tot].buc[l]=b[l];
			a[tot].construct();
			pq2.push(tot);
		}
		b[i]++,b[j]--;
	}
}
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++;
			memset(a[tot].buc,0,sizeof(a[tot].buc));
			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]--;
	}
}
int lst=0;
void adddig()
{
	ma.clear();
	int tmp_tot=tot;
//	cout<<pq.size()<<" "<<pq2.size()<<"\n";
	for(int i=lst+1;i<=tmp_tot;i++) gennext2(i);
	lst=tmp_tot;
//	cerr<<tmp_tot<<" "<<tot<<"\n";
//	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);
		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++) 
//	{
//		int s=0;
//		for(int j=0;j<10;j++) s+=a[i].buc[j];
//		if(s!=dig) cerr<<i<<" ",assert(0);
//	}
//	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: 3728kb

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: 3616kb

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: 3608kb

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: 3596kb

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: 3588kb

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: 3660kb

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: 1ms
memory: 3724kb

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 577 585 588 595 599 655 656 665 666 755 757 775 777 855 858 885 888 955 959 995 1055 1111 1116 1119 1155 1161 1166 1169 1191 1196 1199 1255 1333 1335 1353 1355 1455 1505 1515 1525 1533 1535 154...

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... 7597 7599 7655 7656 7657 7665 '