Submission #1005967

#TimeUsernameProblemLanguageResultExecution timeMemory
1005967andecaandeciCollecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
11 ms8284 KiB
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned long long int ull;
const ll md = 1e9+7;
const int ukr = 2e5+10;
int read() {
    int ketek = 0; bool ne=0;
    register char c = getchar();
    while(c == ' ' or c =='\n') c =getchar();
    if(c=='-'){ne = 1; c = getchar();}
    while(c >= '0' and c <='9') { ketek = (ketek<<3)+(ketek<<1)+c-'0'; c = getchar();}
    if(ne) ketek*=-1;
    return ketek;
}   
void print(int x) {
    if (x < 0) {putchar('-');x = -x;}
    int len = 0, buf[10];
    if (x == 0) {putchar('0');return;}
    while (x > 0) {buf[len++] = x % 10; x/=10;}
    while (len > 0) {putchar('0' + buf[--len]);}
}
void File_Work(){
  freopen("test.in","r",stdin);
  freopen("test.out","w",stdout);
}
int n, m, a, b, c, d, id;
struct babi{
    ll x, y, id;
};
struct babis{
    ll x, y;
};
ll gcd(ll a, ll b) {
   if (b == 0) return a;
   return gcd(b, a % b);
}
ll pgkt(ll rnx, ll rny){
    if(rny == 0) return 1;
    ll nwrn = pgkt(rnx, rny/2);
    if(rny%2){
        return (((nwrn*nwrn)%md)*rnx)%md;
    }else{
        return (nwrn*nwrn)%md;
    }
}
vector<int> v;
string s;
void solve(){
    cin >> n >> m >> a >> b;
    int ar[n+2][m+2];
    bool vis[n+2][m+2];
    memset(ar, 0, sizeof(ar));
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            char f;
            vis[i][j] = 0; 
            cin >> f;
            if(f == '.') continue;
            if(f == 'M'){
                vis[i][j] = 1;
            }else{
                ar[max(1, i-a)][max(1, j-a)] += 1;
                ar[min(n+1, i+a+1)][max(1, j-a)] -= 1;
                ar[max(1, i-a)][min(m+1, j+a+1)] -= 1;
                ar[min(n+1, i+a+1)][min(m+1, j+a+1)] += 1;
            }
        }
    }
    int tot = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            ar[i][j] += ar[i-1][j] + ar[i][j-1] - ar[i-1][j-1];
            //cout << ar[i][j] << " ";
            if(ar[i][j] >= b && vis[i][j]){
                tot++;
            }
        }
        //cout << "\n";
    }
    cout << tot;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
  int t =1;
    //cin >> t;
    for(int i = 1; i <= t; i++){
        //cout << "Case " << i << ": ";
        solve();
    }
}

Compilation message (stderr)

mushrooms.cpp: In function 'int read()':
mushrooms.cpp:10:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   10 |     register char c = getchar();
      |                   ^
mushrooms.cpp: In function 'void File_Work()':
mushrooms.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   freopen("test.in","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   freopen("test.out","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...