답안 #1001510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001510 2024-06-19T05:12:17 Z irmuun 버섯 세기 (IOI20_mushrooms) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include "mushrooms.h"

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

vector<int>c;

int use_machine(vector<int>v){
    int res=0;
    for(int i=1;i<v.size();i++){
        res+=(c[v[i-1]]!=c[v[i]]);
    }
    return res;
}

int count_mushrooms(int n){
    int ans=0;
    vector<int>a,b;
    a.pb(0);
    for(int i=1;i<min(n,200);i++){
        int d=use_machine({0,i});
        if(d==0){
            a.pb(i);
        }
        else{
            b.pb(i);
        }
    }
    if(n<200){
        return (int)a.size();
    }
    ans=a.size();
    if(b.size()>a.size()){
        int len=b.size();
        len-=2;
        for(int i=200;i<n;i+=len){
            int r=min(i+len,n-1);
            int cur=0;
            vector<int>v;
            v.pb(b[0]);
            for(int j=i;j<=r;j++){
                v.pb(j);
                v.pb(b[++cur]);
            }
            for(int j=cur;j<b.size();j++){
                v.pb(b[j]);
            }
            ans+=use_machine(v)/2;
        }
    }
    else{
        int len=a.size();
        len-=2;
        for(int i=200;i<n;i+=len){
            int r=min(i+len,n-1);
            int cur=0;
            vector<int>v;
            v.pb(b[0]);
            int cnt=0;
            for(int j=i;j<=r;j++){
                v.pb(j);
                cnt++;
                v.pb(a[++cur]);
            }
            for(int j=cur;j<a.size();j++){
                v.pb(a[j]);
            }
            ans+=cnt-use_machine(v)/2;
        }
    }
    return ans;
}

Compilation message

mushrooms.cpp: In function 'int use_machine(std::vector<int>)':
mushrooms.cpp:17:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i=1;i<v.size();i++){
      |                 ~^~~~~~~~~
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:52:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |             for(int j=cur;j<b.size();j++){
      |                           ~^~~~~~~~~
mushrooms.cpp:72:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |             for(int j=cur;j<a.size();j++){
      |                           ~^~~~~~~~~
/usr/bin/ld: /tmp/ccwb5gnE.o: in function `use_machine(std::vector<int, std::allocator<int> >)':
stub.cpp:(.text+0x150): multiple definition of `use_machine(std::vector<int, std::allocator<int> >)'; /tmp/ccZyp89A.o:mushrooms.cpp:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status