Submission #850337

# Submission time Handle Problem Language Result Execution time Memory
850337 2023-09-16T12:06:28 Z alexdd Floppy (RMI20_floppy) C++17
28 / 100
1000 ms 12432 KB
#include<bits/stdc++.h>
#include "floppy.h"
using namespace std;
string cv = "";
string inc = "";
int prim[40005];
string get01(int x)
{
    if(x==0)
        return "0";
    string s;
    for(int i=0;i<20;i++)
    {
        if(((1<<i)&x))
            s.push_back('1');
        else
            s.push_back('0');
    }
    while(s[s.size()-1]=='0')
        s.pop_back();
    //cout<<"\n"<<x<<" "<<s<<"  int -> string\n";
    return s;
}
int toint(string s)
{
    int x=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='1')
            x+=(1<<i);
    }
    //cout<<"\n"<<s<<" "<<x<<" string -> int \n";
    return x;
}
void read_array(int subtask_id, const std::vector<int> &v)
{
    deque<int> dq;
    for(int i=0;i<v.size();i++)
    {
        int cnt=0;
        while(!dq.empty() && v[dq.back()]<v[i])
        {
            dq.pop_back();
            cnt++;
        }
        //cout<<cnt<<" ";
        dq.push_back(i);
        string s = get01(cnt);
        cv = cv + s;
        inc.push_back('1');
        for(int j=1;j<s.size();j++)
            inc.push_back('0');
    }
    //cout<<"\n";
    save_to_floppy(cv+inc);
}

vector<int> solve_queries(int subtask_id, int N, const std::string &bits, const std::vector<int> &a, const std::vector<int> &b)
{
    int poz=0, L=(int)bits.size()/2;
    deque<int> dq;
    for(int i=0;i<N;i++)
    {
        int newpoz=L;
        string s="";
        s.push_back(bits[poz]);
        for(int j=poz+1;j<L;j++)
        {
            newpoz=j;
            if(bits[L+j]=='1')
                break;
            s.push_back(bits[j]);
        }
        int x = toint(s);
        //cout<<x<<" ";
        for(int j=0;j<x;j++)
            dq.pop_back();
        if(!dq.empty())
            prim[i]=dq.back();
        else
            prim[i]=-1;
        dq.push_back(i);
        poz = newpoz;
    }
    //cout<<"\n";
    vector<int> ans;
    for(int i=0;i<a.size();i++)
    {
        int cur = b[i];
        while(prim[cur]>=a[i])
            cur=prim[cur];
        ans.push_back(cur);
    }
    return ans;
}

Compilation message

floppy.cpp: In function 'int toint(std::string)':
floppy.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
floppy.cpp: In function 'void read_array(int, const std::vector<int>&)':
floppy.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
floppy.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(int j=1;j<s.size();j++)
      |                     ~^~~~~~~~~
floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:87:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     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 812 KB Output is correct
2 Correct 1 ms 832 KB Output is correct
3 Correct 2 ms 824 KB Output is correct
4 Correct 2 ms 832 KB Output is correct
5 Correct 2 ms 820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2872 KB Output is correct
2 Correct 30 ms 3416 KB Output is correct
3 Correct 103 ms 3512 KB Output is correct
4 Correct 25 ms 3504 KB Output is correct
5 Correct 20 ms 3504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 144 ms 11320 KB Partially correct
2 Partially correct 144 ms 12432 KB Partially correct
3 Execution timed out 1133 ms 12300 KB Time limit exceeded
4 Halted 0 ms 0 KB -