답안 #925570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925570 2024-02-12T05:21:20 Z vjudge1 Collecting Mushrooms (NOI18_collectmushrooms) C++17
56 / 100
12 ms 6604 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;
char c[5001][5001];

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;
    long long cnt1 = 0 , cnt2 = 0;
    for ( int i = 1 ; i <= n ; i++ ) {
        for ( int j = 1 ; j <= m ; j++ ) {
            cin >> c[i][j];
            if ( c[i][j] == 'S' ) {
                cnt1++;
            }
            if ( c[i][j] == 'M' ) {
                cnt2++;
            }
        }
    }
    if ( d == max( n , m ) && cnt1 >= k ) {
        cout << cnt2 ;
    }
    else {
        if ( d == 1 && k == 1 ) {
            long long ans = 0;
            for ( int i = 1 ; i <= n ; i++ ) {
                for ( int j = 1 ; j <= m ; j++ ) {
                    if ( c[i][j] == 'M' ) {
                        if ( c[i][j-1] == 'S' || c[i-1][j] == 'S' || c[i+1][j] == 'S' || c[i][j+1] == 'S' ||c[i+1][j-1] == 'S' ||c[i-1][j+1] == 'S' ||c[i-1][j-1] == 'S' ||c[i+1][j+1] == 'S') {
                            ans++;
                        }
                    }
                }
            }
            cout << ans;
        }
        else {
            if ( n == 1 ) {
                long long scan[m+5];
                for ( int i = 0 ; i <= m ; i++ ) {
                    scan[i] = 0;
                }
                for ( int i = 1 ; i <= m ; i++ ) {
                    if ( c[1][i] == 'S' ) {
                        scan[min( m + 1 , i + d + 1 )]--;
                        scan[max( 1ll , i - d )]++;
                    }
                }
                long long ans = 0;
                for ( int i = 1 ; i <= m ; i++ ) {
                    scan[i] += scan[i-1];
                    if ( c[1][i] == 'M' && scan[i] >= k ) {
                        ans++;
                    }
                }
                cout << ans;
            }
            else {
                cout << 0;
            }
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 6492 KB Output is correct
2 Correct 8 ms 6492 KB Output is correct
3 Correct 12 ms 6488 KB Output is correct
4 Correct 11 ms 6488 KB Output is correct
5 Correct 10 ms 6604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Incorrect 2 ms 2648 KB Output isn't correct
17 Halted 0 ms 0 KB -