제출 #548727

#제출 시각아이디문제언어결과실행 시간메모리
548727usukhbaatarCollecting Mushrooms (NOI18_collectmushrooms)C++14
100 / 100
113 ms17920 KiB
#include <vector> #include <iostream> #include <algorithm> using namespace std; int H, W, D, K; vector<pair<pair<int, int>, pair<int, int>>> v; int bit[2000001]; int N; int query(int i) { int ii = i; int res = 0; while (i > 0) { res += bit[i]; i -= (i & -i); } //cout << "query: " << ii << ": " << res << endl; return res; } void update(int i, int x) { while (i <= N) { bit[i] += x; i += (i & -i); } } void update(int l, int r, int x) { //cout << "update: " << l << " " << r << " " << x << endl; update(l, x); update(r + 1, -x); } int main() { cin >> H >> W >> D >> K; N = W + 2 * D; string temp; for (int i = 0; i < H; i++) { cin >> temp; for (int j = 0; j < W; j++) { if (temp[j] == 'M') { v.push_back({{i, 2}, {j + D + 1, j + D + 1}}); } if (temp[j] == 'S') { v.push_back({{i - D, 1}, {j + 1, j + 2 * D + 1}}); v.push_back({{i + D, 3}, {j + 1, j + 2 * D + 1}}); } } } sort(v.begin(), v.end()); int ans = 0; for (int i = 0; i < v.size(); i++) { if (v[i].first.second == 2) { int temp = query(v[i].second.first); //cout << temp << endl; if (temp >= K) { ans++; } } else { update(v[i].second.first, v[i].second.second, v[i].first.second == 3 ? -1 : 1); } } cout << ans << endl; return 0; }

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

mushrooms.cpp: In function 'int query(int)':
mushrooms.cpp:15:6: warning: unused variable 'ii' [-Wunused-variable]
   15 |  int ii = i;
      |      ^~
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...