Submission #107800

# Submission time Handle Problem Language Result Execution time Memory
107800 2019-04-25T19:58:36 Z dfistric Sequence (BOI14_sequence) C++14
100 / 100
274 ms 1532 KB
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define ll long long

using namespace std;


ll rek(vector <int> ve, int flag) {
    if (ve.size() == 1) {
        ll out = 0;
        int a = ve[0];

        FOR(i, 1, 10) {
            if (a & (1 << i)) out = out * 10 + i;
            if (out == i && (a & 1)) out *= 10;
        }
        if (out == 0 && (a & 1)) out = 10;

        return out;
    }

    ll out = 102345678900000LL;
    REP(n, 9 + flag) {
        int y = n, fl = 0, tr = 0;
        vector <int> tmp;
        
        REP(i, ve.size()) {
            int a = ve[i];
            tr |= ((1023 ^ (1 << y)) & a);
            if (y == 0 && (a & 1)) fl = 1;

            y = (y + 1) % 10;
            if (y == 0 || i == ve.size() - 1) tmp.push_back(tr), tr = 0;
        }

        ll curr = rek(tmp, n < 9 || ve.size() > 2) * 10 + n;
        if (curr == 0 && fl) curr = 10;

        out = min(out, curr);
    }

    return out;
}

int main() {
    ios_base::sync_with_stdio(false);
 
    int n;
    cin >> n;
    vector <int> tmp;
    REP(i, n) {
        int x;
        cin >> x;
        tmp.push_back((1 << x));
    }

    cout << rek(tmp, 1) << endl;

    return 0;
}

Compilation message

sequence.cpp: In function 'long long int rek(std::vector<int>, int)':
sequence.cpp:3:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(i, a, b) for (int i = (a); i < (b); i++)
                                          ^
sequence.cpp:5:19: note: in expansion of macro 'FOR'
 #define REP(i, n) FOR(i, 0, n)
                   ^~~
sequence.cpp:30:9: note: in expansion of macro 'REP'
         REP(i, ve.size()) {
         ^~~
sequence.cpp:36:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (y == 0 || i == ve.size() - 1) tmp.push_back(tr), tr = 0;
                           ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 356 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 28 ms 512 KB Output is correct
3 Correct 39 ms 512 KB Output is correct
4 Correct 30 ms 496 KB Output is correct
5 Correct 29 ms 512 KB Output is correct
6 Correct 20 ms 492 KB Output is correct
7 Correct 158 ms 1204 KB Output is correct
8 Correct 103 ms 896 KB Output is correct
9 Correct 217 ms 1400 KB Output is correct
10 Correct 232 ms 1504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 115 ms 868 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 225 ms 1532 KB Output is correct
12 Correct 226 ms 1532 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 40 ms 512 KB Output is correct
28 Correct 30 ms 512 KB Output is correct
29 Correct 29 ms 512 KB Output is correct
30 Correct 31 ms 512 KB Output is correct
31 Correct 19 ms 384 KB Output is correct
32 Correct 150 ms 1152 KB Output is correct
33 Correct 112 ms 1016 KB Output is correct
34 Correct 218 ms 1532 KB Output is correct
35 Correct 201 ms 1524 KB Output is correct
36 Correct 147 ms 1268 KB Output is correct
37 Correct 204 ms 1404 KB Output is correct
38 Correct 190 ms 1024 KB Output is correct
39 Correct 206 ms 1504 KB Output is correct
40 Correct 274 ms 1504 KB Output is correct