Submission #925571

# Submission time Handle Problem Language Result Execution time Memory
925571 2024-02-12T05:22:19 Z vjudge1 Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
10 ms 9728 KB
// Problem: A - Collecting Mushrooms
// Contest: Virtual Judge - Singapore National Olympiad in Informatics 2018
// URL: https://vjudge.net/contest/608158#problem/A
// Memoryy Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                  Solution
//                    Webbly, 27.01.2023
//
//
//                    Arsen ne katai
//
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////



#include<bits/stdc++.h>

/**
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <time.h>
*/
//#pragma GCC optimize("O3")
//#pragma GCC optimize("fast-loops")
/**
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC target("avx")
*/
#define ll long long
#define kebzaro ios_base::sync_with_stdio(0),cin.tie(0);
#define orz cout.tie(0);
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define flush cout.flush()

using namespace std;

const ll mod = (ll)1e9 + 7, mod3 = 998244353, inf = (ll)2e15, P = 31;

ll rnd(){
    ll x = rand();

    return rand() ^ x;
}

ll binpow (ll a, ll b){
    ll ans = 1;
    while(b){
        if (b & 1){
            ans *= a;

            ans %= mod;
        }

        b >>= 1;
        a *= a;

        a %= mod;
    }
    return ans;
}
ll gcd(ll a, ll b){
    return (b ? gcd(b, a % b) : a);
}
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

struct tr{
    ll four, seven, inc, dec;
};

struct T{
    ll l, r, val, ind;
};

ll n, m, k, a[500005], b[500005], d;

void sarsen(){
    cin >> n >> m >> d >> k;
    
    string s[n + 1];
    
    ll p[n + 1][m + 1];
    
    for (ll i = 0; i <= n; i++){
    	p[i][0] = 0;
    }
    
    for (ll i = 0; i <= m; i++) p[0][i] = 0;
    
    for (ll i = 1; i <= n; i++){
    	cin >> s[i];
    	
    	s[i] = '#' + s[i] + '#';
    	
    	for (ll j = 1; j <= m; j++){
    		p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1];
    		
    		if (s[i][j] == 'S'){
    			p[i][j]++;
    		}
    	}
    }
    
    ll ans = 0;
    
    for (ll i = 1; i <= n; i++){
    	for (ll j = 1; j <= m; j++){
    		if (s[i][j] == 'M'){
    			ll lx = max(1ll, i - d), ly = max(1ll, j - d), rxx = min(n, i + d), ryy = min(m, j + d);
    			
    			if (p[rxx][ryy] - p[rxx][ly - 1] - p[lx - 1][ryy] + p[lx - 1][ly - 1] >= k) ans++;
    		}
    	}
    }
    
    cout << ans;
}

int main(){
    kebzaro orz

    //freopen("justforfood.in", "r", stdin);
    //freopen("justforfood.out", "w", stdout);

    ll TT = 1, tests = 1;

    //cin >> TT;

    while(TT--){
        //cout << "Case " << tests << ": ";

        sarsen();

        //tests++;
    }

    return 0;
}
/**



*/

Compilation message

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:178:16: warning: unused variable 'tests' [-Wunused-variable]
  178 |     ll TT = 1, tests = 1;
      |                ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 2 ms 2392 KB Output is correct
3 Correct 3 ms 2908 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 2 ms 2524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9712 KB Output is correct
2 Correct 8 ms 9712 KB Output is correct
3 Correct 8 ms 9712 KB Output is correct
4 Correct 8 ms 9712 KB Output is correct
5 Correct 9 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 2 ms 2392 KB Output is correct
18 Correct 3 ms 2908 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 2 ms 2524 KB Output is correct
21 Correct 8 ms 9712 KB Output is correct
22 Correct 8 ms 9712 KB Output is correct
23 Correct 8 ms 9712 KB Output is correct
24 Correct 8 ms 9712 KB Output is correct
25 Correct 9 ms 9728 KB Output is correct
26 Correct 10 ms 6232 KB Output is correct
27 Correct 6 ms 5212 KB Output is correct
28 Correct 6 ms 5160 KB Output is correct
29 Correct 5 ms 4956 KB Output is correct
30 Correct 8 ms 5904 KB Output is correct