QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#314674#7639. Forbidden SetinksamuraiAC ✓33ms7596kbC++231.4kb2024-01-26 03:18:442024-01-26 03:18:45

Judging History

This is the latest submission verdict.

  • [2024-01-26 03:18:45]
  • Judged
  • Verdict: AC
  • Time: 33ms
  • Memory: 7596kb
  • [2024-01-26 03:18:44]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

const int inf=1e9;

const int _n=1e6;

int pri[_n+11];

int dp[1<<10];

void gap(){
	for(int i=2;i<=_n;i++){
		for(int j=2*i;j<=_n;j+=i){
			pri[j]=1;
		}
	}
	rep(msk,1<<10){
		dp[msk]=inf;
	}
	for(int i=2;i<=_n;i++){
		if(!pri[i]){
			int v=i,msk=0;
			while(v){
				msk|=(1<<(v%10));
				v/=10;
			}
			msk=((1<<10)-1)^msk;
			dp[msk]=min(dp[msk],i);
		}
	}
	per(msk,(1<<10)){
		if(dp[msk]!=inf){
			rep(d,10){
				if(msk>>d&1){
					dp[msk^(1<<d)]=min(dp[msk^(1<<d)],dp[msk]);
				}
			}
		}
	}
	// rep(msk,1<<10){
	// 	if(!usd[msk]){
	// 		rep(i,10){
	// 			if(msk>>i&1){
	// 				cout<<i<<" ";
	// 			}
	// 		}
	// 		print();
	// 	}
	// }
}

void slv(){
	int n;
	cin>>n;
	int msk=0;
	rep(i,n){
		int x;
		cin>>x;
		msk|=(1<<x);
	}
	if(dp[msk]==inf){
		cout<<"-1\n";
	}else{
		cout<<dp[msk]<<"\n";
	}
}

signed main(){
	ios::sync_with_stdio(0),cin.tie(0);
	gap();
	slv();
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 31ms
memory: 7452kb

input:

7
0
1
2
4
6
8
9

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 26ms
memory: 7520kb

input:

9
0
1
2
3
5
6
7
8
9

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 24ms
memory: 7520kb

input:

9
0
2
3
4
5
6
7
8
9

output:

11

result:

ok 1 number(s): "11"

Test #4:

score: 0
Accepted
time: 25ms
memory: 7532kb

input:

9
0
1
3
4
5
6
7
8
9

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 29ms
memory: 7448kb

input:

9
0
1
2
4
5
6
7
8
9

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 25ms
memory: 7532kb

input:

9
0
1
2
3
4
6
7
8
9

output:

5

result:

ok 1 number(s): "5"

Test #7:

score: 0
Accepted
time: 27ms
memory: 7512kb

input:

9
0
1
2
3
4
5
7
8
9

output:

-1

result:

ok 1 number(s): "-1"

Test #8:

score: 0
Accepted
time: 26ms
memory: 7540kb

input:

9
0
1
2
3
4
5
6
8
9

output:

7

result:

ok 1 number(s): "7"

Test #9:

score: 0
Accepted
time: 29ms
memory: 7508kb

input:

9
0
1
2
3
4
5
6
7
9

output:

-1

result:

ok 1 number(s): "-1"

Test #10:

score: 0
Accepted
time: 28ms
memory: 7464kb

input:

9
0
1
2
3
4
5
6
7
8

output:

-1

result:

ok 1 number(s): "-1"

Test #11:

score: 0
Accepted
time: 26ms
memory: 7536kb

input:

4
1
3
7
9

output:

2

result:

ok 1 number(s): "2"

Test #12:

score: 0
Accepted
time: 30ms
memory: 7528kb

input:

7
1
2
3
4
5
7
8

output:

-1

result:

ok 1 number(s): "-1"

Test #13:

score: 0
Accepted
time: 29ms
memory: 7476kb

input:

8
0
1
2
3
4
5
7
8

output:

-1

result:

ok 1 number(s): "-1"

Test #14:

score: 0
Accepted
time: 31ms
memory: 7552kb

input:

8
1
2
3
4
5
6
7
8

output:

-1

result:

ok 1 number(s): "-1"

Test #15:

score: 0
Accepted
time: 29ms
memory: 7492kb

input:

5
1
2
3
5
7

output:

89

result:

ok 1 number(s): "89"

Test #16:

score: 0
Accepted
time: 29ms
memory: 7496kb

input:

6
1
2
3
5
7
8

output:

409

result:

ok 1 number(s): "409"

Test #17:

score: 0
Accepted
time: 29ms
memory: 7476kb

input:

8
0
1
2
3
5
6
7
8

output:

449

result:

ok 1 number(s): "449"

Test #18:

score: 0
Accepted
time: 33ms
memory: 7540kb

input:

5
2
3
5
7
9

output:

11

result:

ok 1 number(s): "11"

Test #19:

score: 0
Accepted
time: 29ms
memory: 7448kb

input:

6
1
2
4
5
7
8

output:

3

result:

ok 1 number(s): "3"

Test #20:

score: 0
Accepted
time: 30ms
memory: 7488kb

input:

8
0
1
2
4
5
7
8
9

output:

3

result:

ok 1 number(s): "3"

Test #21:

score: 0
Accepted
time: 30ms
memory: 7408kb

input:

8
0
1
3
5
6
7
8
9

output:

2

result:

ok 1 number(s): "2"

Test #22:

score: 0
Accepted
time: 29ms
memory: 7584kb

input:

8
0
2
3
5
6
7
8
9

output:

11

result:

ok 1 number(s): "11"

Test #23:

score: 0
Accepted
time: 30ms
memory: 7536kb

input:

8
0
2
4
5
6
7
8
9

output:

3

result:

ok 1 number(s): "3"

Test #24:

score: 0
Accepted
time: 30ms
memory: 7472kb

input:

7
0
2
3
5
6
7
8

output:

11

result:

ok 1 number(s): "11"

Test #25:

score: 0
Accepted
time: 30ms
memory: 7596kb

input:

8
2
3
4
5
6
7
8
9

output:

11

result:

ok 1 number(s): "11"

Test #26:

score: 0
Accepted
time: 30ms
memory: 7464kb

input:

8
0
1
2
5
6
7
8
9

output:

3

result:

ok 1 number(s): "3"

Test #27:

score: 0
Accepted
time: 30ms
memory: 7448kb

input:

1
2

output:

3

result:

ok 1 number(s): "3"

Test #28:

score: 0
Accepted
time: 29ms
memory: 7480kb

input:

10
0
1
2
3
4
5
6
7
8
9

output:

-1

result:

ok 1 number(s): "-1"

Test #29:

score: 0
Accepted
time: 29ms
memory: 7472kb

input:

7
0
2
3
5
6
8
9

output:

7

result:

ok 1 number(s): "7"

Test #30:

score: 0
Accepted
time: 27ms
memory: 7496kb

input:

8
1
2
3
4
5
6
7
9

output:

-1

result:

ok 1 number(s): "-1"

Test #31:

score: 0
Accepted
time: 30ms
memory: 7540kb

input:

4
0
2
6
7

output:

3

result:

ok 1 number(s): "3"

Test #32:

score: 0
Accepted
time: 27ms
memory: 7536kb

input:

5
2
3
4
6
8

output:

5

result:

ok 1 number(s): "5"

Test #33:

score: 0
Accepted
time: 29ms
memory: 7460kb

input:

6
0
2
3
4
5
8

output:

7

result:

ok 1 number(s): "7"

Test #34:

score: 0
Accepted
time: 26ms
memory: 7536kb

input:

3
1
5
7

output:

2

result:

ok 1 number(s): "2"

Test #35:

score: 0
Accepted
time: 26ms
memory: 7536kb

input:

3
1
4
9

output:

2

result:

ok 1 number(s): "2"

Test #36:

score: 0
Accepted
time: 28ms
memory: 7592kb

input:

6
2
3
4
6
7
9

output:

5

result:

ok 1 number(s): "5"

Test #37:

score: 0
Accepted
time: 30ms
memory: 7540kb

input:

7
1
2
3
4
5
6
8

output:

7

result:

ok 1 number(s): "7"

Test #38:

score: 0
Accepted
time: 27ms
memory: 7472kb

input:

6
0
1
3
5
8
9

output:

2

result:

ok 1 number(s): "2"

Test #39:

score: 0
Accepted
time: 31ms
memory: 7588kb

input:

3
1
3
4

output:

2

result:

ok 1 number(s): "2"

Test #40:

score: 0
Accepted
time: 26ms
memory: 7584kb

input:

4
1
5
6
9

output:

2

result:

ok 1 number(s): "2"

Test #41:

score: 0
Accepted
time: 26ms
memory: 7596kb

input:

7
0
2
3
5
6
7
9

output:

11

result:

ok 1 number(s): "11"

Test #42:

score: 0
Accepted
time: 30ms
memory: 7580kb

input:

4
0
3
7
9

output:

2

result:

ok 1 number(s): "2"

Extra Test:

score: 0
Extra Test Passed