제출 #780828

#제출 시각아이디문제언어결과실행 시간메모리
780828teamariaa버섯 세기 (IOI20_mushrooms)C++17
0 / 100
2 ms304 KiB
#include <bits/stdc++.h> #include "mushrooms.h" using namespace std; #define pb push_back int count_mushrooms(int n) { vector <int> m, aPos, bPos; int ans, cnt, flag = 0; int capat = min(200, n); aPos.pb(0); // cout << capat << "\n"; for(int i = 1; i < capat; i ++) { // cout << "a\n"; m = {0, i}; ans = use_machine(m); if(ans) bPos.pb(i); else aPos.pb(i); } // cout << "fsfsd " << bPos.size() << "\n"; if(n < 200) return aPos.size(); int len; if(aPos.size() > bPos.size()) { m.resize(2 * aPos.size()); for(int i = 0; i < aPos.size(); i ++) m[2 * i] = aPos[i]; len = aPos.size(); } else { m.resize(2 * bPos.size()); flag = 1; for(int i = 0; i < bPos.size(); i ++) m[2 * i] = bPos[i]; len = bPos.size(); } cnt += aPos.size(); int i = 200; while(i < n) { int k = 0; while(i < n && k < len) { m[2 * k + 1] = i; i ++; k ++; } if(i == n && k < len) m.resize(2 * k); ans = use_machine(m); if(flag) { cnt += (ans + 1) / 2; } else { int bNo = (ans + 1) / 2; cnt += len - bNo; } } return cnt; // for(int i = 0; i < (n - 200) / len; i ++) // { // for(int j = 200 + i * len; j < 200 + (i + 1) * len; j ++) // { // m[2 * j + 1] = j; // } // // ans = use_machine(m); // if(flag) // { // cnt += (ans + 1) / 2; // } // else // { // int bNo = (ans + 1) / 2; // cnt += len - bNo; // } // } }

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

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:35:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int i = 0; i < aPos.size(); i ++)
      |                        ~~^~~~~~~~~~~~~
mushrooms.cpp:43:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(int i = 0; i < bPos.size(); i ++)
      |                        ~~^~~~~~~~~~~~~
mushrooms.cpp:48:9: warning: 'cnt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |     cnt += aPos.size();
      |     ~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...