답안 #1101274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101274 2024-10-16T02:30:50 Z Roumak77 Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
11 ms 13308 KB
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <limits>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
using namespace std;

using ll = long long;

void solve(){

    ll r, c, d, k;
    cin >> r >> c >> d >> k;

    vector<string>grid(r);

    for(ll i = 0; i < r; i++){
        string temp;
        cin >> temp;
        grid[i] = temp;
    }
    //cout << "lol" << endl;


    vector<vector<ll>> dp(r + 1, vector<ll>(c + 1, 0));

    for(ll i = 1; i <= r; i++){
        for(ll j = 1; j <= c; j++){
            dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
            if(grid[i - 1][j - 1] == 'S'){
                dp[i][j]++;
            }
        }
    }

    ll total = 0;
    for(ll i = 0; i < r; i++){
        for(ll j = 0; j < c; j++){
            if(grid[i][j] == 'M'){
                ll temp = 0;
                temp += dp[min(i + d + 1, r)][min(j + d + 1, c)];
                temp -= dp[min(i + d + 1, r)][max(0LL, j - d)];
                temp -= dp[max(0LL, i - d)][min(j + d + 1, c)];
                temp += dp[max(0LL, i - d)][max(0LL, j - d)];
                if(temp >= k){
                    total++;
                }
            }
        }
    }
    cout << total << endl;




}

bool single = true;

int main(){

    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);

    ll t = 1;
    if(!single) cin >> t;

    while(t--){
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2332 KB Output is correct
2 Correct 3 ms 2396 KB Output is correct
3 Correct 3 ms 2900 KB Output is correct
4 Correct 3 ms 2388 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 13308 KB Output is correct
2 Correct 8 ms 13308 KB Output is correct
3 Correct 9 ms 13308 KB Output is correct
4 Correct 11 ms 13204 KB Output is correct
5 Correct 11 ms 13308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 2332 KB Output is correct
17 Correct 3 ms 2396 KB Output is correct
18 Correct 3 ms 2900 KB Output is correct
19 Correct 3 ms 2388 KB Output is correct
20 Correct 3 ms 2644 KB Output is correct
21 Correct 9 ms 13308 KB Output is correct
22 Correct 8 ms 13308 KB Output is correct
23 Correct 9 ms 13308 KB Output is correct
24 Correct 11 ms 13204 KB Output is correct
25 Correct 11 ms 13308 KB Output is correct
26 Correct 11 ms 7252 KB Output is correct
27 Correct 7 ms 5204 KB Output is correct
28 Correct 6 ms 5460 KB Output is correct
29 Correct 6 ms 5472 KB Output is correct
30 Correct 11 ms 6512 KB Output is correct