Submission #398972

# Submission time Handle Problem Language Result Execution time Memory
398972 2021-05-04T23:33:41 Z mars Sequence (BOI14_sequence) C++14
0 / 100
907 ms 262148 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) {
    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; 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) * 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>&)':
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);
      |         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 892 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 879 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Runtime error 819 ms 262148 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 907 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -