답안 #493444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493444 2021-12-11T11:17:50 Z Jeff12345121 Floppy (RMI20_floppy) C++14
18.4517 / 100
101 ms 3452 KB
#include <stdlib.h>
#include <string.h>
#include <bits/stdc++.h>
using namespace std;

#include "floppy.h"

const int MAXBIT = 15;

/*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) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 652 KB Output is correct
2 Correct 2 ms 644 KB Output is correct
3 Correct 2 ms 644 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 2 ms 652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 67 ms 3208 KB Partially correct
2 Partially correct 60 ms 3272 KB Partially correct
3 Partially correct 82 ms 3344 KB Partially correct
4 Partially correct 101 ms 3452 KB Partially correct
5 Partially correct 62 ms 3220 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 3256 KB L is too large
2 Halted 0 ms 0 KB -