제출 #1055596

#제출 시각아이디문제언어결과실행 시간메모리
1055596Trent버섯 세기 (IOI20_mushrooms)C++17
43.13 / 100
18 ms2644 KiB
#include "mushrooms.h" #include "bits/stdc++.h" using namespace std; #define forR(i, x) for(int i = 0; i < (x); ++i) #define REP(i, a, b) for(int i = (a); i < (b); ++i) #define all(x) x.begin(), x.end() typedef vector<int> vi; typedef vector<bool> vb; typedef long long ll; typedef vector<ll> vll; typedef set<int> si; int count_mushrooms(int n) { int IVL = 120; vi chk; for(int i = 0; i < n; i += IVL) chk.push_back(i); if(chk.back() < n-1) chk.push_back(n-1); vi ty(chk.size()); ty[0] = 0; REP(i, 1, chk.size()) { vi tst = {0, chk[i]}; ty[i] = use_machine(tst) == 0 ? 0 : 1; } vi ac, bc; forR(i, chk.size()) { if(ty[i] == 0) ac.push_back(chk[i]); else bc.push_back(chk[i]); } vb usd(n, false); for(int i : chk) usd[i] = true; vector<si> ai(ac.size()), bi(bc.size()); forR(i, (int) ac.size() - 1) for(int j = ac[i] + 1; j < ac[i+1]; ++j) if(!usd[j]) ai[i].insert(j); forR(i, (int) bc.size() - 1) for(int j = bc[i] + 1; j < bc[i+1]; ++j) if(!usd[j]) bi[i].insert(j); vi ain(n, -1), bin(n, -1); forR(i, ai.size()) for(int j : ai[i]) ain[j] = i; forR(i, bi.size()) for(int j : bi[i]) bin[j] = i; si ane, bne; forR(i, ai.size()) if(!ai[i].empty()) ane.insert(i); forR(i, bi.size()) if(!bi[i].empty()) bne.insert(i); int tot = (int) ac.size(); while(!ane.empty() || !bne.empty()){ si qus; if(ane.size() >= bne.size()) { for(int i : ane) { qus.insert(ac[i]); qus.insert(ac[i+1]); qus.insert(*ai[i].begin()); } vi qu; for(int i : qus) qu.push_back(i); int res = use_machine(qu); cerr << qu.size() << ' ' << res << '\n'; tot += (int) ane.size() - res / 2; } else { for(int i : bne) { qus.insert(bc[i]); qus.insert(bc[i+1]); qus.insert(*bi[i].begin()); } vi qu; for(int i : qus) qu.push_back(i); int res = use_machine(qu); cerr << qu.size() << ' ' << res << '\n'; tot += res / 2; } for(int i : qus) { if(!usd[i]) { usd[i] = true; if(ain[i] != -1) { ai[ain[i]].erase(i); if(ai[ain[i]].empty()) ane.erase(ain[i]); } if(bin[i] != -1) { bi[bin[i]].erase(i); if(bi[bin[i]].empty()) bne.erase(bin[i]); } } } } forR(i, n) if(!usd[i]) { tot += use_machine({0, i}) == 0 ? 1 : 0; } return tot; }

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

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:5:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define REP(i, a, b) for(int i = (a); i < (b); ++i)
      |                                         ^
mushrooms.cpp:20:2: note: in expansion of macro 'REP'
   20 |  REP(i, 1, chk.size()) {
      |  ^~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:26:2: note: in expansion of macro 'forR'
   26 |  forR(i, chk.size()) {
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:36:2: note: in expansion of macro 'forR'
   36 |  forR(i, ai.size()) for(int j : ai[i]) ain[j] = i;
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:37:2: note: in expansion of macro 'forR'
   37 |  forR(i, bi.size()) for(int j : bi[i]) bin[j] = i;
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:40:2: note: in expansion of macro 'forR'
   40 |  forR(i, ai.size()) if(!ai[i].empty()) ane.insert(i);
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:41:2: note: in expansion of macro 'forR'
   41 |  forR(i, bi.size()) if(!bi[i].empty()) bne.insert(i);
      |  ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...