Submission #1157125

#TimeUsernameProblemLanguageResultExecution timeMemory
1157125fhvirusSequence (BOI14_sequence)C++20
67 / 100
88 ms1296 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; #ifdef OWO #define debug(args...) _debug(#args,args) #define _OO(args...) ostream& operator<<(ostream&O,args) #define _DEF(S) template<class...T>_OO(S<T...>); #define _DEC(S,B,E,F) template<class...T>_OO(S<T...>s){O<<B;int c=0;for(auto i:s)O<<(c++?", ":"")<<F;return O<<E;} _DEF(vector);_DEF(deque);_DEF(set);_DEF(multiset);_DEF(unordered_set);_DEF(map);_DEF(unordered_map);_DEF(pair);_DEF(tuple);template<class T,size_t N>_OO(array<T,N>); _DEC(vector,'[',']',i);_DEC(deque,'[',']',i);_DEC(set,'{','}',i);_DEC(multiset,'{','}',i);_DEC(unordered_set,'{','}',i);_DEC(map,'{','}',i.first<<':'<<i.second);_DEC(unordered_map,'{','}',i.first<<':'<<i.second); template<class...T>_OO(pair<T...>p){return O<<'('<<p.first<<','<<p.second<<')';}template<class...T>_OO(tuple<T...>t){return O<<'(',apply([&O](T...s){int c=0;(...,(O<<(c++?", ":"")<<s));},t),O<<')';}template<class T,size_t N>_OO(array<T,N>a){return O<<vector<T>(begin(a),end(a));} template<class...T>void _debug(const char* s,T...a){int c=sizeof...(T);if(!c){cerr<<"\033[1;32mvoid\033[0m\n";return;}(cerr<<"\033[1;32m("<<s<<") = (",...,(cerr<<a<<(--c?", ":")\033[0m\n")));} #else #define debug(...) ((void)0) #endif ll solve(vi B, bool need, bool can9) { if (B.empty()) { return need; } if (sz(B) == 1) { if (B[0] == 1) return 10; ll ans = 0; rep (d, 1, 10) if (B[0] >> d & 1) { ans = ans * 10 + d; if (B[0] & 1) { B[0] ^= 1; ans *= 10; } } return ans; } ll ans = 12345678900000ll; rep (d, 0, 10) { if (sz(B) <= 2 and d == 9 and not can9) continue; vi nB(sz(B) / 10 + 2); rep (i, 0, sz(B)) { int j = (d + i) / 10, k = (d + i) % 10; nB[j] |= (B[i] & (~(1 << k))); } while (not nB.empty() and nB.back() == 0) nB.pop_back(); ans = min(ans, solve(nB, d == 0 and (B[0] & 1), not (sz(B) <= 2 and d == 9)) * 10 + d); } return ans; } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int K; cin >> K; vi B(K); rep (i, 0, K) { int a; cin >> a; B[i] = (1 << a); } cout << solve(B, false, true) << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...