제출 #1157018

#제출 시각아이디문제언어결과실행 시간메모리
1157018fhvirus수열 (BOI14_sequence)C++20
25 / 100
1096 ms1608 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;

ll solve(vi B, bool need) {
  if (B.empty()) { return need ? 1 : 0; }
  ll ans = 12345678900000ll;
  rep (d, 0, 10) {
    vi nB(sz(B));
    bool useful = false;
    rep (i, 0, sz(B)) {
      int j = (d + i) / 10, k = (d + i) % 10;
      nB[j] |= (B[i] & (~(1 << k)));
      useful |= ((B[i] & (1 << k)) != 0);
    }
    if (not useful) continue;
    while (not nB.empty() and nB.back() == 0) nB.pop_back();
    ans = min(ans, solve(nB, d == 0) * 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) << '\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...