답안 #1058145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058145 2024-08-14T08:41:52 Z idas 버섯 세기 (IOI20_mushrooms) C++17
0 / 100
1 ms 344 KB
#include "mushrooms.h"
#include "bits/stdc++.h"
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define sz(x) ((int)((x).size()))
#define pb push_back

using namespace std;
typedef vector<int> vi;

const int MxN=2e4, C=142;
int n;
vi a, b;

int count_mushrooms(int N) {
    n=N; a.pb(0);

    if(use_machine({0,1})) b.pb(1);
    else a.pb(1);

    if(use_machine({0,2})) b.pb(2);
    else a.pb(2);

    int in=3;
    while(in<=n-2 && sz(a)<C && sz(b)<C) {
        if(sz(a)>=2) {
            int k=use_machine({a[0], in, a[1], in+1});
            if(k==0) a.pb(in), a.pb(in+1);
            else if(k==1) a.pb(in), b.pb(in+1);
            else if(k==2) b.pb(in), a.pb(in+1);
            else b.pb(in), b.pb(in+1);
            in+=2;
        }
        else {
            int k=use_machine({b[0], in, b[1], in+1});
            if(k==0) b.pb(in), b.pb(in+1);
            else if(k==1) b.pb(in), a.pb(in+1);
            else if(k==2) a.pb(in), b.pb(in+1);
            else a.pb(in), a.pb(in+1);
            in+=2;
        }
    }

    int ans=sz(a);
    if(sz(a)>=sz(b)) {
        while(in<n) {
            vi tmp;
            FOR(i, 0, sz(a)) {
                tmp.pb(a[i]);
                if(in<n) tmp.pb(in++);
            }
            int k=use_machine(tmp);
            ans+=sz(a)-k/2-k&1;
        }
    }
    else {
        while(in<n) {
            vi tmp;
            FOR(i, 0, sz(b)) {
                tmp.pb(b[i]);
                if(in<n) tmp.pb(in++);
            }
            int k=use_machine(tmp);
            ans+=k/2+k&1;
        }
    }

    return ans;
}
/*
3
0 1 0

10
0 0 0 0 0 0 0 0 0 0
*/

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:52:27: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   52 |             ans+=sz(a)-k/2-k&1;
      |                           ^
mushrooms.cpp:63:21: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   63 |             ans+=k/2+k&1;
      |                  ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Answer is not correct.
3 Halted 0 ms 0 KB -