답안 #398973

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398973 2021-05-04T23:34:21 Z mars 수열 (BOI14_sequence) C++14
100 / 100
130 ms 1116 KB
/*
 * A solution for task Sequence.
 * Complexity - O(K log K).
 *
 * Author: Daumilas Ardickas
 * Idea: Vytautas Gruslys
 */
 
#include <cstdio>
#include <vector>
using namespace std;


long long minN(const vector<int>& A, bool try9 = true) {
    long long m = 102345678900000L;

    if (A.size() == 1) {
        m = 0;
        for (int a = 1; a <= 9; a++) {
            if (A[0] & (1 << a)) {
                m = m * 10 + a;
                if (m == a && A[0] & 1) m *= 10;
            }
        }
        if (m == 0 && A[0] & 1) {
            m = 10;
        }
        return m;
    }

    for (int n = 0; n < 9 + try9; n++) {
        int y = n, a = 0;
    	bool zero = false;
        vector<int> B;
        for (int i = 0; i < A.size(); i++) {
            a |= A[i] & (1023 - (1 << y));
            if (A[i] & 1 && y == 0) {
                zero = true;
            }
            y = (y + 1) % 10;
            if (!y || i == A.size() - 1) {
                B.push_back(a);
                a = 0;
            }
        }

    	long long mm = minN(B, n < 9 || A.size() > 2) * 10 + n;
    	if (!mm && zero) {
            mm = 10;
        }
        m = min(m, mm);
    }
    return m;
}

int main() {
    int K, d, i;
    vector<int> A;
    scanf("%d", &K);
    for (i = 0; i < K; i++) {
        scanf("%d", &d);
        A.push_back(1 << d);
    }
    printf ("%lld\n", minN(A));
}

Compilation message

sequence.cpp: In function 'long long int minN(const std::vector<int>&, bool)':
sequence.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (int i = 0; i < A.size(); i++) {
      |                         ~~^~~~~~~~~~
sequence.cpp:41:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             if (!y || i == A.size() - 1) {
      |                       ~~^~~~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   59 |     scanf("%d", &K);
      |     ~~~~~^~~~~~~~~~
sequence.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |         scanf("%d", &d);
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 2 ms 204 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 15 ms 388 KB Output is correct
3 Correct 14 ms 332 KB Output is correct
4 Correct 15 ms 332 KB Output is correct
5 Correct 15 ms 396 KB Output is correct
6 Correct 10 ms 332 KB Output is correct
7 Correct 88 ms 900 KB Output is correct
8 Correct 60 ms 588 KB Output is correct
9 Correct 129 ms 840 KB Output is correct
10 Correct 124 ms 884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 60 ms 588 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 129 ms 1020 KB Output is correct
12 Correct 125 ms 1064 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 1 ms 288 KB Output is correct
18 Correct 1 ms 276 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 2 ms 284 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 15 ms 412 KB Output is correct
28 Correct 15 ms 412 KB Output is correct
29 Correct 15 ms 332 KB Output is correct
30 Correct 15 ms 332 KB Output is correct
31 Correct 10 ms 360 KB Output is correct
32 Correct 92 ms 968 KB Output is correct
33 Correct 60 ms 716 KB Output is correct
34 Correct 124 ms 1096 KB Output is correct
35 Correct 130 ms 1096 KB Output is correct
36 Correct 96 ms 968 KB Output is correct
37 Correct 125 ms 1116 KB Output is correct
38 Correct 75 ms 680 KB Output is correct
39 Correct 130 ms 1096 KB Output is correct
40 Correct 129 ms 1096 KB Output is correct