Submission #141281

#TimeUsernameProblemLanguageResultExecution timeMemory
141281meatrowCollecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
40 ms5112 KiB
//#pragma GCC optimize("O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") //#pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; vector<vector<int>> f; void add(int x, int y) { for (int i = x; i < f.size(); i |= i + 1) { for (int j = y; j < f[0].size(); j |= j + 1) { f[i][j]++; } } } int get(int x, int y) { x = min(x, int(f.size()) - 1); y = min(y, int(f[0].size()) - 1); int res = 0; for (int i = x; i >= 0; i = (i & (i + 1)) - 1) { for (int j = y; j >= 0; j = (j & (j + 1)) - 1) { res += f[i][j]; } } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int r, c, d, k; cin >> r >> c >> d >> k; vector<vector<char>> field(r, vector<char>(c)); f.assign(r, vector<int>(c, 0)); for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { cin >> field[i][j]; if (field[i][j] == 'S') { add(i, j); } } } int ans = 0; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { if (field[i][j] == 'M') { int cnt = get(i + d, j + d) - get(i + d, j - d - 1) - get(i - d - 1, j + d) + get(i - d - 1, j - d - 1); if (cnt >= k) { ans++; } } } } cout << ans; return 0; }

Compilation message (stderr)

mushrooms.cpp: In function 'void add(int, int)':
mushrooms.cpp:14:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = x; i < f.size(); i |= i + 1) {
                     ~~^~~~~~~~~~
mushrooms.cpp:15:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = y; j < f[0].size(); j |= j + 1) {
                         ~~^~~~~~~~~~~~~
#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...