Submission #925582

# Submission time Handle Problem Language Result Execution time Memory
925582 2024-02-12T05:35:13 Z vjudge1 Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
22 ms 26868 KB
// By ObeliX
#include <bits/stdc++.h>
#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include <unordered_map>
#include <cstddef>
#include <cassert>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>

using namespace std;

const long long N = 1e6 + 5;
const long long MOD = 1e7 + 7;
const long long inf = 1e18;

long long n , m , d , k;

int main(){
    //freopen( "cinema.in" , "r" , stdin );
    //freopen( "cinema.out" , "w" , stdout );
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> d >> k;
    char c[n+5][m+5];
    long long pref[n+5][m+5];
    for ( int i = 0 ; i <= n + 1 ; i++ ) {
        for ( int j = 0 ; j <= m + 1 ; j++ ) {
            c[i][j] = '.';
            pref[i][j] = 0;
        }
    }
    long long cnt1 = 0 , cnt2 = 0;
    for ( int i = 1 ; i <= n ; i++ ) {
        for ( int j = 1 ; j <= m ; j++ ) {
            cin >> c[i][j];
            pref[i][j] += pref[i-1][j];
            pref[i][j] += pref[i][j-1];
            pref[i][j] -= pref[i-1][j-1];
            if ( c[i][j] == 'S' ) {
                pref[i][j]++;
            }
        }
    }
    long long ans = 0;
    for ( int i = 1 ; i <= n ; i++ ) {
        for ( int j = 1 ; j <= m ; j++ ) {
            if ( c[i][j] == 'M' ) {
                long long x2 = min( n , i + d ) , y2 = min( m , j + d );
                long long x1 = max( 0ll , i - d - 1 ) , y1 = max( 0ll , j - d - 1 );
                long long x = pref[x2][y2] - ( pref[x2][y1] + pref[x1][y2] ) + pref[x1][y1];
                if ( x >= k ) {
                    ans++;
                }
            }
        }
    }
    cout << ans;
}

Compilation message

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:40:15: warning: unused variable 'cnt1' [-Wunused-variable]
   40 |     long long cnt1 = 0 , cnt2 = 0;
      |               ^~~~
mushrooms.cpp:40:26: warning: unused variable 'cnt2' [-Wunused-variable]
   40 |     long long cnt1 = 0 , cnt2 = 0;
      |                          ^~~~
# 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 1 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 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 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 3 ms 2140 KB Output is correct
2 Correct 3 ms 2136 KB Output is correct
3 Correct 4 ms 2648 KB Output is correct
4 Correct 3 ms 2392 KB Output is correct
5 Correct 3 ms 2284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 26868 KB Output is correct
2 Correct 22 ms 26692 KB Output is correct
3 Correct 21 ms 26712 KB Output is correct
4 Correct 21 ms 26716 KB Output is correct
5 Correct 22 ms 26864 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 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 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 3 ms 2140 KB Output is correct
17 Correct 3 ms 2136 KB Output is correct
18 Correct 4 ms 2648 KB Output is correct
19 Correct 3 ms 2392 KB Output is correct
20 Correct 3 ms 2284 KB Output is correct
21 Correct 22 ms 26868 KB Output is correct
22 Correct 22 ms 26692 KB Output is correct
23 Correct 21 ms 26712 KB Output is correct
24 Correct 21 ms 26716 KB Output is correct
25 Correct 22 ms 26864 KB Output is correct
26 Correct 11 ms 5724 KB Output is correct
27 Correct 10 ms 4956 KB Output is correct
28 Correct 10 ms 5208 KB Output is correct
29 Correct 10 ms 5212 KB Output is correct
30 Correct 11 ms 5444 KB Output is correct