Submission #95965

# Submission time Handle Problem Language Result Execution time Memory
95965 2019-02-04T18:17:18 Z SpeedOfMagic Sequence (BOI14_sequence) C++17
0 / 100
1000 ms 1656 KB
/** MIT License Copyright (c) 2018-2019(!) Vasilyev Daniil **/
#include <bits/stdc++.h>
using namespace std;
template<typename T> using v = vector<T>;
#define int long long
typedef long double ld;
typedef string str;
typedef vector<int> vint;
#define rep(a, l, r) for(int a = (l); a < (r); a++)
#define pb push_back
#define fs first
#define sc second
#define sz(a) ((int) a.size())
const long long inf = 4611686018427387903; //2^62 - 1
const long double EPS = 1e-9;
#if 0  //FileIO
const string fileName = "";
ifstream fin ((fileName == "" ? "input.txt"  : fileName + ".in" ));
ofstream fout((fileName == "" ? "output.txt" : fileName + ".out"));
#define get fin >>
#define put fout <<
#else
#define get cin >>
#define put cout <<
#endif
#define eol put endl
void read() {} template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg)     ;read(args...) ;}
void print(){} template<typename Arg,typename... Args> void print(Arg  arg,Args...  args){put (arg)<<" ";print(args...);}
int getInt(){int a; get a; return a;}
//code starts here
const int M = 100000;
char decomp[M][10];
void decompose(int d) {
    if (d == 0) {decomp[d][0] = 1; return;}
    int p = d;
    while (p) {
        decomp[d][p % 10] = 1;
        p /= 10;
    }
}
void run() {
    int k;
    get k;
    int d[k];
    rep(i, 0, k)
        get d[i];
    rep(i, 0, M)
        decompose(i);

    int ans = inf;
    rep(i, 0, 99001) {
        char need[10];
        memset(need, 0, sizeof need);
        rep(j, 0, k)
            if (!decomp[i + j][d[j]])
                need[d[j]] = 1;
        int pans = i;
        int num = 0;
        rep(j, 1, 10)
            if (need[j]) {
                num = num * 10 + j;
                if (need[0]) {
                    need[0] = 0;
                    num *= 10;
                }
            }
        if (need[0])
            num = 10;
        pans += num * 100000;
        ans = min(ans, pans);
    }
    put ans;
}
signed main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); put fixed << setprecision(12); run(); return 0;}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1272 KB Output is correct
2 Correct 166 ms 1272 KB Output is correct
3 Correct 40 ms 1272 KB Output is correct
4 Correct 41 ms 1272 KB Output is correct
5 Correct 6 ms 1272 KB Output is correct
6 Incorrect 7 ms 1272 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1272 KB Output is correct
2 Correct 166 ms 1392 KB Output is correct
3 Correct 40 ms 1272 KB Output is correct
4 Correct 41 ms 1272 KB Output is correct
5 Correct 6 ms 1272 KB Output is correct
6 Incorrect 7 ms 1272 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1400 KB Output is correct
2 Correct 165 ms 1272 KB Output is correct
3 Correct 39 ms 1272 KB Output is correct
4 Correct 40 ms 1272 KB Output is correct
5 Execution timed out 1055 ms 1656 KB Time limit exceeded
6 Halted 0 ms 0 KB -