답안 #982674

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
982674 2024-05-14T15:45:37 Z canadavid1 수열 (BOI14_sequence) C++14
25 / 100
82 ms 2220 KB
#include <iostream>
#include <vector>
#include <bitset>


using digits = std::bitset<10>;
using u64 = unsigned long long;


u64 min_valid(std::vector<digits> v)
{
    if(v.size()==0) return 0;
    if(v.size()==1)
    {
        auto w = v[0];
        u64 o = 0;
        if(w.none()) return 0;
        if(w.count()==1 && w[0]) return 10;
        int i = 1;
        while(!w[i]) i++;
        o = i;
        w[i] = 0;
        if(w[0]) o *= 10;
        for(int i = 1; i < 10; i++)
        {
            if(!w[i]) continue;
            o *= 10;
            o += i;
        }
        return o;
    }
    u64 min = (u64)-1;
    for(u64 ls = 0; ls < 10; ls++)
    {
        std::vector<digits> n;
        auto k = ls;
        n.emplace_back();
        for(int i = 0; i < v.size(); i++)
        {
            auto r = v[i];
            r[k] = 0;
            n.back() |= r;
            if(++k==10)
            {
                k = 0;
                n.emplace_back();
            }
        }
        if(n.back().none()) n.pop_back();
        if(n == v) continue;
        auto a = min_valid(n);
        min = std::min(10*a+ls,min);
    }
    return min;
}

int main()
{
    int K;
    std::cin >> K;
    std::vector<digits> v(K);
    for(auto& i : v) {int j; std::cin >> j; i[j]=1;}
    std::cout << min_valid(v) << "\n";
}

Compilation message

sequence.cpp: In function 'u64 min_valid(std::vector<std::bitset<10> >)':
sequence.cpp:38:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::bitset<10> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(int i = 0; i < v.size(); i++)
      |                        ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 15 ms 604 KB Output is correct
3 Correct 14 ms 604 KB Output is correct
4 Correct 7 ms 604 KB Output is correct
5 Correct 7 ms 640 KB Output is correct
6 Correct 7 ms 600 KB Output is correct
7 Correct 53 ms 1628 KB Output is correct
8 Correct 57 ms 1116 KB Output is correct
9 Correct 82 ms 2136 KB Output is correct
10 Correct 78 ms 2220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 56 ms 1248 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -