Submission #494349

# Submission time Handle Problem Language Result Execution time Memory
494349 2021-12-15T09:18:55 Z jasen_penchev Floppy (RMI20_floppy) C++14
28 / 100
1000 ms 8300 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();
    string bits = "";
    stack<int> st;
    for (int i = 0; i < n; ++ i)
    {
        while (st.size() and v[st.top()] < v[i])
        {
            bits += '1';
            st.pop();
        }
        st.push(i);
        bits += '0';
    }

    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 pos = 0;
    stack<int> st;
    st.push(-1);
    for (int i = 0; i < n; ++ i)
    {
        while (bits[pos] == '1')
        {
            st.pop();
            pos++;
        }
        link[i] = st.top();
        st.push(i);
        pos++;
    }

    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

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) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 648 KB Output is correct
2 Correct 2 ms 648 KB Output is correct
3 Correct 2 ms 648 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2468 KB Output is correct
2 Correct 20 ms 2452 KB Output is correct
3 Correct 115 ms 2404 KB Output is correct
4 Correct 27 ms 2472 KB Output is correct
5 Correct 21 ms 2492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 8300 KB Output is correct
2 Correct 83 ms 8220 KB Output is correct
3 Execution timed out 1138 ms 8128 KB Time limit exceeded
4 Halted 0 ms 0 KB -