답안 #859710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859710 2023-10-10T14:03:29 Z activedeltorre Floppy (RMI20_floppy) C++14
100 / 100
319 ms 9060 KB
#include <stdlib.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <iostream>
#include <algorithm>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
//#include "floppy.h"

#include "floppy.h"
/*
#define NMAX 100000
#define MMAX 100000

int subtask_id, N, M;
std::vector<int> v, sorted_v;
std::vector<int> a, b;
std::vector<int> correct_answers;
using namespace std;
// Print score to stdout and exit.

void score_and_exit(const double pts, const char *verdict) {
    cout<<verdict;
    cout<<endl<<pts;
    exit(0);
}

// Contestant sent too many bits.
void too_many_bits() {
    score_and_exit(0, "Too many stored bits!");
}

// Contestant did not send any bits.
void misformatted_stored_bits() {
    score_and_exit(0, "Misformatted stored bits or save_to_floppy not called!");
}

// Contestant did not call the answer function.
void answer_not_provided() {
    score_and_exit(0, "Answer not provided!");
}

// Contestant sent a wrong answer.
void wrong_answer() {
    score_and_exit(0, "Wrong answer to query!");
}

// Contestant sent a correct answer.
void correct_answer() {
    score_and_exit(1, "OK!");
}*/
using namespace std;
vector<int>ans;
stack<int>st2;
int par[40005];
string biti;
vector<int>vec;
stack<int>st;
vector<int> solve_queries(int subtask_id, int N,const string &bits,const vector<int> &a, const vector<int> &b)
{
    int n,q,i,aux,j,poz;
    n=N;
    q=a.size();
    poz=0;
    for(i=1;i<=n;i++)
    {
        par[i]=0;
    }
    for(i=1;i<=n;i++)
    {
        int cnt=0,iter=0,val=0,sum=0;
        while(bits[poz]=='1')
        {
            poz++;
            cnt++;
        }
        sum=cnt;
        for(j=1;j<=sum;j++)
        {
            par[st2.top()]=i;
            st2.pop();
        }
        st2.push(i);
        poz++;
    }
    int l,r;
    for(i=0;i<q;i++)
    {
        l=a[i]+1;
        r=b[i]+1;
        for(j=l;j<=r;j++)
        {
            if(par[j]>r || par[j]==0)
            {
                ans.push_back(j-1);
                break;
            }
        }
    }
    return ans;
}

/*
void read_test()
{
    cin>>subtask_id;
    cin>>N>>M;
    assert(1 <= N && N <= NMAX);
    assert(0 <= M && M <= MMAX);
    v.resize(N);
    for (int i = 0; i < N; ++i) {
        assert(scanf("%d", &v[i]) == 1);
    }

    // Check all values are distinct.
    sorted_v.resize(N);
    for (int i = 0; i < N; ++i) {
        sorted_v[i] = v[i];
    }
    std::sort(sorted_v.begin(), sorted_v.end());
    for (int i = 0; i + 1 < N; ++i) {
        assert(sorted_v[i] < sorted_v[i + 1]);
    }

    a.resize(M);
    b.resize(M);
    correct_answers.resize(M);
    for (int i = 0; i < M; ++i) {
        assert(scanf("%d%d%d", &a[i], &b[i], &correct_answers[i]) == 3);
        assert(0 <= a[i] && a[i] <= correct_answers[i] &&
              correct_answers[i] <= b[i] && b[i] < N);
    }
}

void save_to_floppy(const std::string &bits) {
    std::vector<int> contestant_answers = solve_queries(subtask_id, N, bits, a, b);
    for (int i = 0; i < M; ++i) {
        if (contestant_answers[i] != correct_answers[i]) {
            wrong_answer();
        }
    }
    correct_answer();
    exit(0);
}*/
void read_array(int subtask_id, const vector<int> &v)
{
    int n=v.size(),i,j;
    int cnt=0;
    for(i=0;i<n;i++)
    {
        if(v[i]>v[i-1])
        {
            cnt++;
        }
        vec.push_back(v[i]);
    }
    st.push(1e9);
    for(i=0;i<n;i++)
    {
        cnt=0;
        while(st.top()<vec[i])
        {
            st.pop();
            cnt++;
        }
        st.push(vec[i]);
        for(j=1;j<=cnt;j++)
        {
            biti.push_back('1');
        }
        biti.push_back('0');
    }
    save_to_floppy(biti);

}
/*
int main(int argc, char **argv) {
    // Read input data.
    read_test();

    // Send subtask_id, v.
    read_array(subtask_id, v);

    answer_not_provided();
    return 0;
}
*/

Compilation message

floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:75:19: warning: unused variable 'iter' [-Wunused-variable]
   75 |         int cnt=0,iter=0,val=0,sum=0;
      |                   ^~~~
floppy.cpp:75:26: warning: unused variable 'val' [-Wunused-variable]
   75 |         int cnt=0,iter=0,val=0,sum=0;
      |                          ^~~
floppy.cpp:65:15: warning: unused variable 'aux' [-Wunused-variable]
   65 |     int n,q,i,aux,j,poz;
      |               ^~~
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 1 ms 816 KB Output is correct
2 Correct 1 ms 808 KB Output is correct
3 Correct 1 ms 816 KB Output is correct
4 Correct 1 ms 816 KB Output is correct
5 Correct 1 ms 808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 2780 KB Output is correct
2 Correct 26 ms 2832 KB Output is correct
3 Correct 17 ms 2616 KB Output is correct
4 Correct 33 ms 2872 KB Output is correct
5 Correct 25 ms 2632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 223 ms 8504 KB Output is correct
2 Correct 272 ms 9060 KB Output is correct
3 Correct 61 ms 8704 KB Output is correct
4 Correct 319 ms 8756 KB Output is correct
5 Correct 258 ms 8628 KB Output is correct