Submission #404501

# Submission time Handle Problem Language Result Execution time Memory
404501 2021-05-14T14:04:57 Z danielcm585 Floppy (RMI20_floppy) C++14
100 / 100
126 ms 15780 KB
#include "floppy.h"

#include <bits/stdc++.h>
using namespace std;

void read_array(int subtask_id, const vector<int> &v) {
    string bits;
    stack<int> s;
    for (auto i : v) {
        while (!s.empty() && s.top() < i) {
            bits += '0';
            s.pop();
        }
        bits += '1';
        s.push(i);
    }
    save_to_floppy(bits);
}

vector<int> solve_queries(int subtask_id, int N, const string &bits, const vector<int> &l, const vector<int> &r) {
    stack<int> s;
    vector<vector<int>> ls(N,vector<int>(16));
    for (int i = 0, j = 0; i < bits.length(); i++) {
        if (bits[i] == '1') {
            if (s.empty()) ls[j][0] = j;
            else ls[j][0] = s.top();
            s.push(j++);
        }
        else s.pop();
    }
    for (int i = 1; i < 16; i++) {
        for (int j = 0; j < N; j++) {
            ls[j][i] = ls[ls[j][i-1]][i-1];
        }
    }
    vector<int> res;
    for (int i = 0; i < l.size(); i++) {
        int ans = r[i];
        for (int j = 15; j >= 0; j--) {
            if (ls[ans][j] >= l[i]) ans = ls[ans][j];
        }
        res.push_back(ans);
    }
    return res;
}

Compilation message

floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:23:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int i = 0, j = 0; i < bits.length(); i++) {
      |                            ~~^~~~~~~~~~~~~~~
floppy.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for (int i = 0; i < l.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 3 ms 768 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 4196 KB Output is correct
2 Correct 29 ms 4228 KB Output is correct
3 Correct 30 ms 4152 KB Output is correct
4 Correct 32 ms 4160 KB Output is correct
5 Correct 43 ms 4232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 15632 KB Output is correct
2 Correct 126 ms 15456 KB Output is correct
3 Correct 126 ms 15764 KB Output is correct
4 Correct 117 ms 15780 KB Output is correct
5 Correct 115 ms 15536 KB Output is correct