답안 #305012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
305012 2020-09-22T11:47:56 Z MarcoMeijer 버섯 세기 (IOI20_mushrooms) C++14
0 / 100
2 ms 256 KB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()

int mx=92;

int count_mushrooms(int n) {
    if(n <= 227) {
        int ans = 1;
        REP(i,1,n) ans += 1-use_machine({0,i});
        return ans;
    }
    int cur = 0;
    vi a[2]; bool swp = 0;
    a[0].pb(++cur);

    // A_
    while(a[0].size() < 2 && a[1].size() < 2) {
        a[use_machine({a[0][0],cur})].pb(cur); cur++;
    }
    if(a[1].size() == 2) swap(a[0], a[1]), swp^=1;

    // A_A_
    while(a[0].size() < 3 && a[1].size() < 3) {
        vi m;
        m.pb(a[0][0]);
        m.pb(cur);
        m.pb(a[0][1]);
        m.pb(cur+1);
        int res = use_machine(m);
        a[(res&2)==2].pb(cur);
        a[(res&1)==1].pb(cur+1);
        cur += 2;
    }
    if(a[1].size() > a[0].size()) swap(a[0],a[1]), swp^=1;

    // A_A_A_ => A_A_
    while(a[1].size() < 2) {
        vi m;
        m.pb(a[0][0]);
        m.pb(cur);
        m.pb(a[0][1]);
        m.pb(cur+1);
        m.pb(a[0][2]);
        m.pb(cur+2);
        int res = use_machine(m);
        a[(res&1)==1].pb(cur+2);
        if(res&2) {
            m.clear();
            m.pb(a[0][0]);
            m.pb(cur);
            m.pb(a[0][1]);
            m.pb(cur+1);
            res = use_machine(m);
            a[(res&2)==2].pb(cur);
            a[(res&1)==1].pb(cur+1);
        } else {    
            a[(res&4)==4].pb(cur  );
            a[(res&4)==4].pb(cur+1);
        }
        cur += 3;
        if(a[1].size() > a[0].size()) swap(a[0],a[1]), swp^=1;
    }

    // A_A_A_ => B_BA_A_A_
    while(a[0].size() < mx && a[1].size() < mx) {
        vi m;
        m.pb(a[0][0]);
        m.pb(cur);
        m.pb(a[0][1]);
        m.pb(cur+1);
        m.pb(a[0][2]);
        m.pb(cur+2);
        int res = use_machine(m);
        a[(res&1)==1].pb(cur+2);
        a[(res&4)==4].pb(cur+1);
        a[(res&4)==4].pb(cur  );
        if(res&2) {
            m.clear();
            m.pb(a[1][0]);
            m.pb(cur);
            m.pb(a[1][1]);
            m.pb(a[0][0]);
            m.pb(cur+1);
            m.pb(a[0][1]);
            m.pb(cur+3);
            m.pb(a[0][2]);
            m.pb(cur+4);
            res = use_machine(m)-1;
            a[(res&2)==2].pb(cur+3);
            a[(res&1)==1].pb(cur+4);
            if(res&4) {
                a[0].pb(cur);
                a[1].pb(cur+1);
            } else {
                a[1].pb(cur);
                a[0].pb(cur+1);
            }
            cur += 5;
        } else {
            cur += 3;
        }
    }
    if(a[1].size() > a[0].size()) swap(a[0],a[1]), swp^=1;

    int ans = a[0].size();
    while(cur < n) {
        vi m;
        FOR(i,a[0]) {
            m.pb(i);
            m.pb(cur++);
            if(cur == n) break;
        }
        ans += (use_machine(m)+1)/2;
    }
    if(swp) ans = n-ans;
    return ans;
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:92:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   92 |     while(a[0].size() < mx && a[1].size() < mx) {
      |           ~~~~~~~~~~~~^~~~
mushrooms.cpp:92:43: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   92 |     while(a[0].size() < mx && a[1].size() < mx) {
      |                               ~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 0 ms 256 KB Duplicate value 1 in the query array.
7 Halted 0 ms 0 KB -