Submission #493445

# Submission time Handle Problem Language Result Execution time Memory
493445 2021-12-11T11:21:00 Z Jeff12345121 Floppy (RMI20_floppy) C++14
8.8394 / 100
102 ms 3464 KB
#include <stdlib.h>
#include <string.h>
#include <bits/stdc++.h>
using namespace std;

#include "floppy.h"

const int MAXBIT = 16;

/*string gbits;
void save_to_floppy(const string &bits) {
    gbits = bits;
}*/

string makeBin(int x) {
    string bin = "";
    for (int i = 0; i <= MAXBIT; i++) {
        bin += ( ( x & ( 1 << i ) ) ? '1' : '0' );
    }
    return bin;
}
void read_array(int subtask_id, const std::vector<int> &v) {
    string bits = "";
    vector<pair<int,int>> norm(v.size());
    for (int i = 0; i < v.size(); i++) norm[i] = {v[i] , i};
    sort(norm.begin() , norm.end());

    vector<int> place(v.size());
    for (int i = 0; i < norm.size(); i++) {
        place[norm[i].second] = i;
    }

    for (int i = 0; i < v.size(); i++) {
        bits += makeBin(place[i]);
    }
    save_to_floppy(bits);
}

std::vector<int> solve_queries(int subtask_id, int N,
                               const std::string &bits,
                               const std::vector<int> &a, const std::vector<int> &b) {
    vector<int> place(N);
    int pos = 0;
    for (int i = 0; i < bits.size();) {
        for (int bit = 0; bit <= MAXBIT; bit++) {
            if (bits[i] == '1') {
                place[pos] += (1 << bit);
            }
            i++;
        }
        pos++;
    }

    vector<int> answers;

    for (int i = 0; i < a.size(); i++) {
        int maxInd = a[i];
        for (int j = a[i] + 1; j <= b[i]; j++) {
            if (place[j] > place[maxInd]) {
                maxInd = j;
            }
        }
        answers.push_back(maxInd);
    }
    return answers;
}

/*
int main() {
    read_array(1 , {4 , 2 , 3 , 7 , 1 , 5 , 6, 8});
    solve_queries(1 , 8 , gbits , {2,2} , {4,7});
}*/

Compilation message

floppy.cpp: In function 'void read_array(int, const std::vector<int>&)':
floppy.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i = 0; i < v.size(); i++) norm[i] = {v[i] , i};
      |                     ~~^~~~~~~~~~
floppy.cpp:29:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i = 0; i < norm.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
floppy.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     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:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for (int i = 0; i < bits.size();) {
      |                     ~~^~~~~~~~~~~~~
floppy.cpp:56:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     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) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 2 ms 652 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 3 ms 656 KB Output is correct
5 Correct 3 ms 776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 60 ms 3280 KB Partially correct
2 Partially correct 56 ms 3324 KB Partially correct
3 Partially correct 80 ms 3412 KB Partially correct
4 Partially correct 102 ms 3408 KB Partially correct
5 Partially correct 57 ms 3464 KB Partially correct
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 3208 KB L is too large
2 Halted 0 ms 0 KB -