Submission #859660

# Submission time Handle Problem Language Result Execution time Memory
859660 2023-10-10T12:24:09 Z nguyentunglam Floppy (RMI20_floppy) C++17
100 / 100
76 ms 17676 KB
#include <stdlib.h>
#include <string.h>

#include "floppy.h"

#include<bits/stdc++.h>
using namespace std;
void read_array(int subtask_id, const std::vector<int> &v) {
   string ret;
   vector<int> st;
   for(int i = 0; i < v.size(); i++) {
      while (!st.empty() && v[i] > v[st.back()]) {
         ret.push_back('1');
         st.pop_back();
      }
      ret.push_back('0');
      st.push_back(i);
   }
   save_to_floppy(ret);
}

const int M = 1e5 + 10;

vector<pair<int, int> > query[M];

std::vector<int> solve_queries(int subtask_id, int N,
        const std::string &bits,
        const std::vector<int> &a, const std::vector<int> &b) {
    std::vector<int> ans(a.size());

    for(int i = 0; i < a.size(); i++) query[b[i]].emplace_back(a[i], i);

    int j = 0;
    vector<int> st;

    for(int i = 0; i < N; i++) {
      int cnt = 0;
      while (bits[j] == '1') {
         j++;
         st.pop_back();
      } j++;

      st.push_back(i);

      for(auto &[l, idx] : query[i]) {
         ans[idx] = *lower_bound(st.begin(), st.end(), l);
//         ans[idx] = 1;
      }
    }

    return ans;
}

Compilation message

floppy.cpp: In function 'void read_array(int, const std::vector<int>&)':
floppy.cpp:11:21: 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++) {
      |                   ~~^~~~~~~~~~
floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int i = 0; i < a.size(); i++) query[b[i]].emplace_back(a[i], i);
      |                    ~~^~~~~~~~~~
floppy.cpp:37:11: warning: unused variable 'cnt' [-Wunused-variable]
   37 |       int cnt = 0;
      |           ^~~
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 5432 KB Output is correct
2 Correct 2 ms 5440 KB Output is correct
3 Correct 2 ms 5440 KB Output is correct
4 Correct 2 ms 5440 KB Output is correct
5 Correct 2 ms 5440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 8628 KB Output is correct
2 Correct 22 ms 8408 KB Output is correct
3 Correct 18 ms 8364 KB Output is correct
4 Correct 18 ms 8268 KB Output is correct
5 Correct 18 ms 8380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 17432 KB Output is correct
2 Correct 76 ms 17416 KB Output is correct
3 Correct 73 ms 17572 KB Output is correct
4 Correct 69 ms 17676 KB Output is correct
5 Correct 69 ms 17300 KB Output is correct