Submission #858154

# Submission time Handle Problem Language Result Execution time Memory
858154 2023-10-07T13:47:27 Z alexdumitru Floppy (RMI20_floppy) C++17
100 / 100
74 ms 13808 KB
#include <stdlib.h>
#include <string.h>
#include <stack>

#include "floppy.h"


void read_array(int subtask_id, const std::vector<int> &v) {
    std :: string s;
    std :: stack<int> st;
    for (int i = 0; i < v.size(); i++) {
        while (!st.empty() && st.top() < v[i]) {
            s += "1";
            st.pop();
        }
        s += "0";
        st.push(v[i]);
    }
    save_to_floppy(s);
}

int query(int st, int dr, int prev[][16]) {
    for(int i = 15; i >= 0; i--)
        if(prev[dr][i] >= st)
            dr = prev[dr][i];
    return dr;
}

std :: vector<int> solve_queries(int subtask_id, int N,
        const std :: string &bits,
        const std :: vector<int> &a, const std :: vector<int> &b) {
    int ptr = 0;
    std :: stack<int> st;
    int prev[N][16];
    for (int i = 0; i < N; i++) {
        while(bits[ptr] == '1'){
            st.pop();
            ptr++;
        }
        prev[i][0] = st.empty() ? i : st.top();
        for(int j = 1; j < 16; j++)
            prev[i][j] = prev[prev[i][j - 1]][j - 1];
        st.push(i);
        ptr++;
    }
    std :: vector<int> answers;
    int M = a.size();
    for (int i = 0; i < M; i++)
        answers.push_back(query(a[i], b[i], prev));
    return answers;
}

Compilation message

floppy.cpp: In function 'void read_array(int, const std::vector<int>&)':
floppy.cpp:11:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
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 1 ms 808 KB Output is correct
2 Correct 1 ms 808 KB Output is correct
3 Correct 1 ms 804 KB Output is correct
4 Correct 2 ms 812 KB Output is correct
5 Correct 1 ms 808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3132 KB Output is correct
2 Correct 17 ms 3068 KB Output is correct
3 Correct 16 ms 3108 KB Output is correct
4 Correct 16 ms 3464 KB Output is correct
5 Correct 18 ms 3228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 10680 KB Output is correct
2 Correct 66 ms 13800 KB Output is correct
3 Correct 65 ms 13640 KB Output is correct
4 Correct 74 ms 13808 KB Output is correct
5 Correct 69 ms 13784 KB Output is correct