답안 #674705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674705 2022-12-26T00:18:19 Z Antekb 수열 (BOI14_sequence) C++14
100 / 100
525 ms 3576 KB
#include<bits/stdc++.h>
 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("trapv")
 
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define pp(x) pop_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
 
using namespace std;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~~
 
template <typename H, typename T> 
ostream& operator<<(ostream& os, pair<H, T> m){
	return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H> 
ostream& operator<<(ostream& os, vector<H> V){
	os<<"{";
	for(int i=0; i<V.size(); i++){
		if(i)os<<" ";
		os<<V[i];
	}
	os<<"}";
	return os;
}
 
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
 
///~~~~~~~~~~~~~~~~~~~~~~~~~
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;
 
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const int K=18, N=(1<<K), INF=1e9+5, mod=1e9+7, mod2=998244353;

struct modint{
	int n=0;
	modint(){}
	modint(ll x){
		n=x%mod;
		if(n<0)n+=mod;
	}
	operator int(){
		return n;
	}
	modint operator+(modint a){a.n = n+a.n; if(a.n>=mod)a.n-=mod;return a;}
	modint operator+=(modint a){return (*this)=(*this)+a;}
	modint operator-(modint a){a.n = n-a.n; if(a.n<0)a.n+=mod;return a;}
	modint operator-=(modint a){return (*this)=(*this)-a;}
	modint operator*(modint a){a.n = (n*1ll*a.n)%mod; return a;}
	modint operator*=(modint a){return (*this)=(*this)*a;}
	modint operator^(const ll &m)const{
		modint a(1);
		if(m==0)return a;
		if(m==1)return (*this);
		a=(*this)^(m/2);
		a*=a;
		return a*((*this)^(m&1));
	}
	modint odw(){
		return (*this)^((ll)mod-2);
	}
	modint operator/(modint a){return (*this)*a.odw();}
	modint operator/=(modint a){return (*this)=(*this)/a;}
	bool operator==(modint a){return a.n==n;}
	friend ostream& operator<<(ostream& os, modint m) {
		return os << m.n; 
	}
};
modint fact[N], fact2[N];
typedef vector<modint> vm;
void factinit(){
    fact[0]=1;
    for(int i=1; i<N; i++){
        fact[i]=(fact[i-1]*modint(i))%mod;
    }
    fact2[N-1]=fact[N-1].odw();
    for(int i=N-2; i>=0; i--){
    	fact2[i]=(fact2[i+1]*modint(i+1))%mod;
    }
}
modint npok(int _n, int _k){
    return fact[_n]*fact2[_k]*fact2[_n-_k];
}
ll solve(vector<int> V, bool b){
	//deb(V, b);
	int n=V.size();
	if(n==0)return 1;
	if(n==1 && V[0]==0){
		return 10*(!b);		
	}
	if(n==1){
		vi V2;
		for(int i=0; i<10; i++){
			if(V[0]&(1<<i))V2.pb(i);
		}
		assert(V.size());
		sor(V2);
		if(V2[0]==0){
			if(V2.size()==1)V2.pb(1);
			swap(V2[0], V2[1]);
		}
		//deb(V2);
		ll ans=0;
		for(int i:V2){
			ans*=10;
			ans+=i;
		}
		//deb(ans);
		return ans;
	}
	//deb(n, V);
	ll ans=1e18;
	for(int i=0; i<10; i++){
		vector<int> V2;
		for(int j=0; j<n; j++){
			if(i==j%10 || !V2.size())V2.pb(0);
			V2.back()|=V[j]&(~(1<<((j-i+10)%10)));
		}
		while(V2.size() && V2.back()==0)V2.pp();
		if(i==0 && V[0]&1){
			if(!V2.size())return 10;
		}
		if(!V2.size()){
			if(i==0 && b)return 0;
			else return 10-i;
		}
		//deb(V, b, i, V2);
		if(V2!=V)ans=min(ans, 10*solve(V2, b|i)+(10-i)%10);
		if(V2==V && !b && i)ans=min(ans, 10*solve(V2, b|i)+(10-i)%10);
		//deb(V, b, i, ans);
	}
	return ans;
}
int main(){
	//factinit();
	//BOOST;
	int n;
	cin>>n;
	vector<int> V(n);
	for(int i=0; i<n; ++i){
		int x;
		cin>>x;
		V[i]=1<<x;
	}

	cout<<solve(V, 0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 4 ms 2360 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 1 ms 2260 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 1 ms 2260 KB Output is correct
7 Correct 2 ms 2260 KB Output is correct
8 Correct 2 ms 2260 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 5 ms 2260 KB Output is correct
11 Correct 5 ms 2260 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
13 Correct 2 ms 2356 KB Output is correct
14 Correct 6 ms 2364 KB Output is correct
15 Correct 6 ms 2364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 3 ms 2260 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 1 ms 2260 KB Output is correct
7 Correct 3 ms 2260 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 3 ms 2260 KB Output is correct
10 Correct 1 ms 2260 KB Output is correct
11 Correct 5 ms 2260 KB Output is correct
12 Correct 7 ms 2388 KB Output is correct
13 Correct 5 ms 2356 KB Output is correct
14 Correct 2 ms 2260 KB Output is correct
15 Correct 2 ms 2352 KB Output is correct
16 Correct 6 ms 2260 KB Output is correct
17 Correct 6 ms 2260 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 6 ms 2260 KB Output is correct
21 Correct 3 ms 2260 KB Output is correct
22 Correct 7 ms 2352 KB Output is correct
23 Correct 6 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 18 ms 2388 KB Output is correct
3 Correct 23 ms 2388 KB Output is correct
4 Correct 19 ms 2476 KB Output is correct
5 Correct 18 ms 2388 KB Output is correct
6 Correct 12 ms 2440 KB Output is correct
7 Correct 97 ms 3128 KB Output is correct
8 Correct 70 ms 2772 KB Output is correct
9 Correct 131 ms 3412 KB Output is correct
10 Correct 132 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 3 ms 2260 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 1 ms 2260 KB Output is correct
5 Correct 229 ms 2756 KB Output is correct
6 Correct 1 ms 2260 KB Output is correct
7 Correct 2 ms 2356 KB Output is correct
8 Correct 3 ms 2260 KB Output is correct
9 Correct 2 ms 2260 KB Output is correct
10 Correct 3 ms 2260 KB Output is correct
11 Correct 154 ms 3448 KB Output is correct
12 Correct 170 ms 3452 KB Output is correct
13 Correct 1 ms 2260 KB Output is correct
14 Correct 5 ms 2260 KB Output is correct
15 Correct 8 ms 2360 KB Output is correct
16 Correct 5 ms 2260 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2352 KB Output is correct
19 Correct 6 ms 2388 KB Output is correct
20 Correct 6 ms 2260 KB Output is correct
21 Correct 2 ms 2260 KB Output is correct
22 Correct 3 ms 2240 KB Output is correct
23 Correct 6 ms 2260 KB Output is correct
24 Correct 3 ms 2352 KB Output is correct
25 Correct 6 ms 2260 KB Output is correct
26 Correct 6 ms 2260 KB Output is correct
27 Correct 18 ms 2388 KB Output is correct
28 Correct 18 ms 2424 KB Output is correct
29 Correct 22 ms 2388 KB Output is correct
30 Correct 20 ms 2388 KB Output is correct
31 Correct 12 ms 2368 KB Output is correct
32 Correct 95 ms 3028 KB Output is correct
33 Correct 73 ms 2892 KB Output is correct
34 Correct 130 ms 3576 KB Output is correct
35 Correct 150 ms 3504 KB Output is correct
36 Correct 354 ms 3164 KB Output is correct
37 Correct 525 ms 3420 KB Output is correct
38 Correct 300 ms 2980 KB Output is correct
39 Correct 477 ms 3340 KB Output is correct
40 Correct 518 ms 3448 KB Output is correct