제출 #409332

#제출 시각아이디문제언어결과실행 시간메모리
409332Carmel_Ab1Counting Mushrooms (IOI20_mushrooms)C++17
0 / 100
18 ms640 KiB
#include <bits/stdc++.h>
#include "mushrooms.h"

//#include "stub.cpp"

using namespace std;

#define pb push_back
typedef vector<int> vi;
typedef long long ll;

int count_mushrooms(int n) {
    int ans=1;

    vi o,z,a(n,-1);
    a[0]=0;
    z.pb(0);

    const int k=max(2ll,ll(sqrt(n)));

    int first=1;
    for(int i=1; o.size()<k && z.size()<k;first++, i++){
        if(use_machine({0,i}))
            o.pb(i),a[i]=1;
        else
            ans++,z.pb(i),a[i]=0;
    }
    vi left;
    for(int i=first; i<n;i++)
        left.pb(i);

    if(o.size()>z.size()){
        for(int i=k,j=0; i<n;j=0, i++){
            vi cur;
            while(left.size() && cur.size()+3<=n && cur.size()+2<=o.size()){
                cur.pb(o[j]);
                cur.pb(left.back());
                left.pop_back();
                cur.pb(o[j+1]);
                j+=2;
            }
            if(cur.size()>=2)
                ans+= use_machine(cur)/2;
        }
    }
    else{
        for(int i=k,j=0; i<n;j=0, i++){
            int in=0;
            vi cur;
            while(left.size() && cur.size()+3<=n && cur.size()+2<=z.size()){
                cur.pb(z[j]);
                cur.pb(left.back());
                left.pop_back();
                cur.pb(z[j+1]);
                j+=2;
                in++;
            }

            if(cur.size()>=2)
                ans+= in-use_machine(cur)/2;
        }
    }
    while(left.size()){
        ans+= use_machine({0,left.back()});
        left.pop_back();
    }
    return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:22:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   22 |     for(int i=1; o.size()<k && z.size()<k;first++, i++){
      |                  ~~~~~~~~^~
mushrooms.cpp:22:40: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   22 |     for(int i=1; o.size()<k && z.size()<k;first++, i++){
      |                                ~~~~~~~~^~
mushrooms.cpp:35:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |             while(left.size() && cur.size()+3<=n && cur.size()+2<=o.size()){
      |                                  ~~~~~~~~~~~~^~~
mushrooms.cpp:50:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |             while(left.size() && cur.size()+3<=n && cur.size()+2<=z.size()){
      |                                  ~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...