답안 #494583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494583 2021-12-15T18:54:42 Z ovidiush11 Floppy (RMI20_floppy) C++14
28 / 100
1000 ms 7752 KB
#include <stdlib.h>
#include <string.h>

#include "floppy.h"

void read_array(int subtask_id, const std::vector<int> &v) {
    std::string bits;
    std::vector<int> p;
    int x = 0,n = v.size();
    for(int i = 1;i < n;i++)
    {
        if(v[i] < v[i-1])
        {
            bits.push_back('0');
            p.push_back(v[i-1]);
            x++;
        }
        else
        {
            bits.push_back('1');
            while(x != 0 && v[i] > p[x-1])
            {
                bits.push_back('1');
                p.pop_back();
                x--;
            }
            if(x != 0)bits.push_back('0');
        }
    }
    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)
{
    int n = bits.size(),pos[N],x = 0,j = 0,s = 0;
    for(int i = 0;i < n;i++)
    {
        if(s == 1)
        {
            if(bits[i] == '1')
            {
                x--;
                if(x == 0)s = 0;
            }
            else s = 0;
        }
        else
        {
            if(bits[i] == '0')x++;
            else if(x != 0)s = 1;
            pos[j] = i;
            j++;
        }
    }
    pos[N-1] = bits.size();
    n = a.size();
    std::vector<int> ans;
    for(int k = 0;k < n;k++)
    {
        int m = a[k];
        x = 0;
        for(int i = a[k];i < b[k];i++)
        {
            int l = pos[i],r = pos[i+1];
            if(bits[l] == '0')x++;
            else if(r - l >= x + 1)
            {
                if(bits[l + x] == '1')
                {
                    x = 0;
                    m = i + 1;
                }
                else x = 1;
            }
            else x -= r - l - 2;
        }
        ans.push_back(m);
    }
    return ans;
}

Compilation message

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 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 516 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 2376 KB Output is correct
2 Correct 150 ms 2340 KB Output is correct
3 Correct 248 ms 2296 KB Output is correct
4 Correct 209 ms 2356 KB Output is correct
5 Correct 151 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1104 ms 7752 KB Time limit exceeded
2 Halted 0 ms 0 KB -