| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1048060 | Lobo | Sequence (BOI14_sequence) | C++17 | 662 ms | 22612 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e17 + 10;
const int inf1 = 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxn = -1;
set<int> digits(int x) {
    set<int> s;
    while(x != 0) {
        s.insert(x%10);
        x/= 10;
    }
    return s;
}
int sol(int qtd, vector<set<int>> a) {
    if(a.size() == 0) {
        return 0;
    }
    else if(a.size() == 1) {
        int ans = 0;
        vector<int> vec;
        for(auto x : a[0]) {
            vec.pb(x);
        }
        if(vec[0] == 0) {
            if(vec.size() == 1) vec = {1,0};
            else swap(vec[0],vec[1]);
        }
        for(auto x : vec) {
            ans = 10*ans + x;
        }
        return ans;
    }
    if(qtd > 5) return inf;
    int ans = inf;
    for(int y = 0; y <= 9; y++) {
        vector<set<int>> b;
        for(int i = 0; i < a.size(); i++) {
            for(auto ele : a[i]) {
                if(ele != (y+i)%10) {
                    if((y+i)/10 >= (int) b.size()) b.resize((y+i)/10 + 1);
                    b[(y+i)/10].insert(ele);
                }
            }
        }
        // if(a != b or true) {
        ans = min(ans, y + 10*sol(qtd+1,b));
        // }
        //     if(qtd == 0) {
        //         int kkk = sol(qtd+1,b);
        //         cout << y << " " << kkk << " " << b.size() << endl;
        //     }
        //     if(qtd == 1 && a.size() == 36) {
        //         cout << " " << y << " " << sol(qtd+1,b) << " " << b.size() << endl;
        //     }
    }
    return ans;
}
void solve() {
    int k;
    cin >> k;
    vector<int> b(k);
    vector<set<int>> setb(k);
    for(int i = 0; i < k; i++) {
        cin >> b[i];
        setb[i].insert(b[i]);
    }
    cout << sol(0,setb) << endl;
}
int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
