제출 #613685

#제출 시각아이디문제언어결과실행 시간메모리
613685Jarif_Rahman버섯 세기 (IOI20_mushrooms)C++17
56.93 / 100
1057 ms408 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

int count_mushrooms(int n){
    vector<int> A, B;
    A.pb(0);
    int k = sqrt(n);
    k = max(2, k);

    if(n > 10){
        int mn = 1e9;
        for(int i = 3; i <= n; i++){
            int c = 0;
            for(int j = i; j <= 2*i-1; j++) c = max(c, j-1+(n-j+i-1)/i);
            if(c < mn) mn = c, k = i;
        }
    }

    int ls = n;

    for(int i = 1; i < n; i++){
        if(max(A.size(), B.size()) == k){
            ls = i;
            break;
        }

        if(use_machine({0, i})) B.pb(i);
        else A.pb(i);
    }

    int ans = A.size();

    if(A.size() == k){
        for(int i = ls; i < n; i+=k){
            vector<int> Q;
            for(int j = 0; j < k; j++){
                Q.pb(A[j]);
                if(i+j < min(n, i+k)) Q.pb(i+j);
            }
            int x = use_machine(Q);
            ans+=min(n, i+k)-i-x%2-x/2;
        }
    }
    else{
        for(int i = ls; i < n; i+=k){
            vector<int> Q;
            for(int j = 0; j < k; j++){
                Q.pb(B[j]);
                if(i+j < min(n, i+k)) Q.pb(i+j);
            }
            int x = use_machine(Q);
            ans+=x%2+x/2;
        }
    }

    return ans;
}

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

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:28:36: warning: comparison of integer expressions of different signedness: 'const long unsigned int' and 'int' [-Wsign-compare]
   28 |         if(max(A.size(), B.size()) == k){
      |            ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
mushrooms.cpp:39:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |     if(A.size() == k){
      |        ~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...