답안 #596465

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
596465 2022-07-14T19:05:10 Z CaroLinda Floppy (RMI20_floppy) C++14
100 / 100
123 ms 15140 KB
#include <stdlib.h>
#include <string.h>
#include <bits/stdc++.h>
#include "floppy.h"
 
const int LOG=20;
 
using namespace std;
 
void read_array(int subtask_id, const vector<int> &v) {
    string ans;
    stack<int> st;
 
    for(int i = 0; i < v.size();i++){
        while(!st.empty() && st.top() < v[i]){
            st.pop();
            ans.push_back('1');
        }
 
        if(!st.empty())
            ans.push_back('0');
 
        st.push(v[i]);
    }
 
    save_to_floppy(ans);
}
 
vector<int> solve_queries(int subtask_id, int N,
        const string &bits,
        const vector<int> &a, const vector<int> &b) {
 
    vector<int> retDummy(a.size(), 0);
 
 
    vector< vector<int> >dp(LOG, vector<int>(N,-1));
    stack<int> st;
    int ptr = 0;
    st.push(0);
 
    for(int i = 1; i < N; i++){
        while(!st.empty() && bits[ptr] == '1'){
            ptr++;
            st.pop();
        }
 
        if(!st.empty()){
            dp[0][i] = st.top();
            ptr++;
        }
 
        st.push(i);
    }
 
    for(int i= 1; i < LOG; i++)
        for(int j= 0; j < N; j++)
            if(dp[i-1][j] != -1)
                dp[i][j] = dp[i-1][dp[i-1][j]];
 
    vector<int> ret;
 
    for(int i = 0; i < a.size(); i++){
        int l = a[i];
        int r = b[i];
 
        for(int j = LOG-1; j >= 0; j--){
            if(dp[j][r] >= l)
                r = dp[j][r];
        }
 
        ret.push_back(r);
    }
 
    return ret;
}

Compilation message

floppy.cpp: In function 'void read_array(int, const std::vector<int>&)':
floppy.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     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:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i = 0; i < a.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) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 784 KB Output is correct
2 Correct 2 ms 788 KB Output is correct
3 Correct 2 ms 812 KB Output is correct
4 Correct 2 ms 788 KB Output is correct
5 Correct 2 ms 812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 3324 KB Output is correct
2 Correct 33 ms 4052 KB Output is correct
3 Correct 26 ms 4032 KB Output is correct
4 Correct 25 ms 4124 KB Output is correct
5 Correct 20 ms 4092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 11560 KB Output is correct
2 Correct 86 ms 15036 KB Output is correct
3 Correct 123 ms 15012 KB Output is correct
4 Correct 102 ms 15140 KB Output is correct
5 Correct 87 ms 14956 KB Output is correct