답안 #494347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494347 2021-12-15T09:12:21 Z jasen_penchev Floppy (RMI20_floppy) C++14
28 / 100
130 ms 3288 KB
#include "floppy.h"
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#define endl '\n'
using namespace std;

const int MAXN = 40000;

int link[MAXN + 5];

void save_to_floppy(const string &bits);

void read_array(int subtask_id, const vector<int> &v)
{
    int n = v.size();
    stack<int> st;
    st.push(-1);
    for (int i = 0; i < n; ++ i)
    {
        while (st.top() != -1 and v[st.top()] < v[i]) st.pop();
        link[i] = st.top() + 1;
        st.push(i);
    }

    int cnt = 0, n0 = n;
    while (n0)
    {
        n0 /= 2;
        cnt++;
    }

    string bits = "";
    for (int i = 0; i < n; ++ i)
    {
        string s = "";
        int j = link[i];
        while (j)
        {
            s = char(j % 2 + '0') + s;
            j /= 2;
        }
        while (s.size() < cnt) s = '0' + s;
        bits += s;
    }

    save_to_floppy(bits);
}

vector<int> solve_queries(int subtask_id, int n, const string &bits, const vector<int> &a, const vector<int> &b)
{
    int cnt = 0, n0 = n;
    while (n0)
    {
        n0 /= 2;
        cnt++;
    }

    for (int i = 0; i < n; ++ i)
    {
        link[i] = 0;
        for (int j = i * cnt; j < (i + 1) * cnt; ++ j)
        {
            link[i] = link[i] * 2 + (bits[j] - '0');
        }
        link[i]--;
    }

    vector<int> v;
    int m = a.size();
    for (int i = 0; i < m; ++ i)
    {
        int pos = b[i];
        while (link[pos] >= a[i]) pos = link[pos];
        v.push_back(pos);
    }

    return v;
}

Compilation message

floppy.cpp: In function 'void read_array(int, const std::vector<int>&)':
floppy.cpp:44:25: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |         while (s.size() < cnt) s = '0' + s;
      |                ~~~~~~~~~^~~~~
stub.cpp: In function 'void run2()':
stub.cpp:101:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  101 |     if (query_answers.size() != M) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 648 KB Output is correct
2 Correct 2 ms 660 KB Output is correct
3 Correct 2 ms 648 KB Output is correct
4 Correct 2 ms 648 KB Output is correct
5 Correct 2 ms 648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 3264 KB Output is correct
2 Correct 31 ms 3188 KB Output is correct
3 Correct 130 ms 3288 KB Output is correct
4 Correct 36 ms 3248 KB Output is correct
5 Correct 33 ms 3276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 2984 KB L is too large
2 Halted 0 ms 0 KB -