답안 #141281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
141281 2019-08-07T09:51:58 Z meatrow Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
40 ms 5112 KB
//#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

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) {
                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 6 ms 1528 KB Output is correct
3 Correct 8 ms 1784 KB Output is correct
4 Correct 7 ms 1656 KB Output is correct
5 Correct 7 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 4744 KB Output is correct
2 Correct 40 ms 4796 KB Output is correct
3 Correct 28 ms 4748 KB Output is correct
4 Correct 35 ms 4748 KB Output is correct
5 Correct 35 ms 4748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 6 ms 1528 KB Output is correct
17 Correct 6 ms 1528 KB Output is correct
18 Correct 8 ms 1784 KB Output is correct
19 Correct 7 ms 1656 KB Output is correct
20 Correct 7 ms 1656 KB Output is correct
21 Correct 25 ms 4744 KB Output is correct
22 Correct 40 ms 4796 KB Output is correct
23 Correct 28 ms 4748 KB Output is correct
24 Correct 35 ms 4748 KB Output is correct
25 Correct 35 ms 4748 KB Output is correct
26 Correct 30 ms 5112 KB Output is correct
27 Correct 31 ms 3320 KB Output is correct
28 Correct 27 ms 3248 KB Output is correct
29 Correct 23 ms 3320 KB Output is correct
30 Correct 34 ms 4588 KB Output is correct