답안 #520186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
520186 2022-01-28T17:13:41 Z prvocislo Zalmoxis (BOI18_zalmoxis) C++17
65 / 100
427 ms 262148 KB
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <chrono>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <queue>
#include <bitset>
#include <cmath>
#include <cassert>
typedef long long ll;
typedef long double ld;
using namespace std;

void compress(vector<int>& st)
{
    while (st.size() >= 2 && st[st.size() - 2] == st[st.size() - 1])
    {
        int x = st.back();
        st.pop_back();
        st.pop_back();
        st.push_back(x + 1);
    }
}
void split(int x, int k, vector<int>& v)
{
    //cout << x << " " << k << "\n";
    if (k == 1)
    {
        v.push_back(x);
        return;
    }
    int l = min(k - 1, 1 << (x - 2));
    split(x - 1, l, v);
    split(x - 1, k - l, v);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    vector<int> st, ans1, added;
    for (int i = 0; i < n; i++)
    {
        while (!st.empty() && st.back() < v[i])
        {
            st.push_back(st.back());
            ans1.push_back(st.back());
            added.push_back(1);
            compress(st);
        }
        st.push_back(v[i]);
        ans1.push_back(v[i]);
        added.push_back(0);
        compress(st);
    }
    while (st.size() > 1 || st.back() < 30)
    {
        st.push_back(st.back());
        ans1.push_back(st.back());
        added.push_back(1);
        compress(st);
    }
    assert(ans1.size() <= n + k);
    k = n + k - ans1.size();
    vector<int> ans2;
    for (int i = 0; i < ans1.size(); i++)
    {
        if (added[i])
        {
            int val = min(k + 1, 1 << (ans1[i] - 1));
            split(ans1[i], val, ans2);
            k -= val - 1;
        }
        else
        {
            ans2.push_back(ans1[i]);
        }
    }
    for (int i = 0; i < ans2.size(); i++)
    {
        cout << ans2[i] << " \n"[i == ans2.size() - 1];
    }
    return 0;
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from zalmoxis.cpp:14:
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:71:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   71 |     assert(ans1.size() <= n + k);
      |            ~~~~~~~~~~~~^~~~~~~~
zalmoxis.cpp:74:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for (int i = 0; i < ans1.size(); i++)
      |                     ~~^~~~~~~~~~~~~
zalmoxis.cpp:87:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     for (int i = 0; i < ans2.size(); i++)
      |                     ~~^~~~~~~~~~~~~
zalmoxis.cpp:89:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         cout << ans2[i] << " \n"[i == ans2.size() - 1];
      |                                  ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 135 ms 18208 KB Output is correct
2 Correct 145 ms 18140 KB Output is correct
3 Correct 138 ms 18208 KB Output is correct
4 Correct 143 ms 18140 KB Output is correct
5 Correct 148 ms 18140 KB Output is correct
6 Correct 139 ms 18208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 18140 KB Output is correct
2 Runtime error 416 ms 262148 KB Execution killed with signal 9
3 Runtime error 405 ms 262148 KB Execution killed with signal 9
4 Correct 184 ms 18192 KB Output is correct
5 Correct 139 ms 18144 KB Output is correct
6 Correct 183 ms 18144 KB Output is correct
7 Correct 142 ms 18136 KB Output is correct
8 Correct 159 ms 18288 KB Output is correct
9 Runtime error 427 ms 262148 KB Execution killed with signal 9
10 Runtime error 368 ms 262148 KB Execution killed with signal 9
11 Runtime error 399 ms 262148 KB Execution killed with signal 9
12 Runtime error 351 ms 262148 KB Execution killed with signal 9
13 Runtime error 360 ms 262148 KB Execution killed with signal 9
14 Correct 72 ms 6320 KB Output is correct