제출 #1084775

#제출 시각아이디문제언어결과실행 시간메모리
1084775IzzyBosses (BOI16_bosses)C++14
0 / 100
0 ms344 KiB
#include <vector> #include <algorithm> #include <iostream> #include <map> using namespace std; int n; map<int, vector<int>> arr; int test(int start) { vector<bool> visited(n, false); vector<vector<int>> levels = {{start}}; int lvl = 0; int pos = 0; int salary = 0; visited[start] = true; while (lvl < levels.size()) { start = levels[lvl][pos]; auto it = arr.find(start); if (it != arr.end()) { for (int i: arr[start]) { if (!visited[i]) { visited[i] = true; if (levels.size() > lvl + 1) { levels[lvl + 1].push_back(i); } else { levels.push_back({i}); } } } } pos++; if (pos == levels[lvl].size()) { salary += levels[lvl].size() * (lvl + 1); lvl++; pos = 0; } } if (find(visited.begin(), visited.end(), false) != visited.end()) { return salary; } return 2147483646; } int main() { int salary = 2147483646; cin >> n; for (int i = 0; i < n; i++) { int len; cin >> len; vector<int> temp; for (int j = 0; j < len; j++) { int x; cin >> x; x--; if (arr.find(x) == arr.end()) { arr[x] = {i}; } else { arr[x].push_back(i); } } } for (int i = 0; i < n; i++) { if (arr.find(i) != arr.end()) { int temp = test(i); if (temp < salary) { salary = temp; } } } cout << salary; }

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

bosses.cpp: In function 'int test(int)':
bosses.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     while (lvl < levels.size()) {
      |            ~~~~^~~~~~~~~~~~~~~
bosses.cpp:24:39: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |                     if (levels.size() > lvl + 1) {
      |                         ~~~~~~~~~~~~~~^~~~~~~~~
bosses.cpp:33:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         if (pos == levels[lvl].size()) {
      |             ~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...