이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std ;
#define maxn 500009
#define ll long long
#define fi first
#define se second
#define pb push_back
#define left id<<1
#define right id<<1|1
#define re exit(0);
const int mod = 1e9+7 ;
const int INF = 1e9 ;
const int LOG = 18 ;
typedef vector<int> vi ;
typedef vector<ll> vl ;
typedef pair<int,int> pii ;
typedef vector<pii> vii ;
typedef pair<ll,ll> pll ;
void add ( int &a , int b )
{
a += b ;
if ( a < 0 ) a += mod ;
if ( a >= mod ) a -= mod ;
}
template < typename T > void chkmin (T &a , T b) { if (a>b) a=b ;}
template < typename T > void chkmax (T &a , T b) { if (a<b) a=b ;}
void rf ()
{
freopen ("bai1.inp","r",stdin) ;
// freopen ("bai1.out","w",stdout) ;
}
int _pow ( int a , int n )
{
if ( n == 0 ) return 1 ;
int res = _pow(a,n/2) ;
if ( n % 2 ) return (1ll*res*res%mod*a%mod) ;
else return 1ll*res*res%mod ;
}
int n , m , k , d ;
vector <char> a [maxn] ;
const int N = 1e4 + 9 ;
int bit [N] ;
vii event [maxn] ;
void update ( int x , int y )
{
while ( x < N ) bit [x] += y , x += (x&-x) ;
}
int get ( int x )
{
int res = 0 ;
while ( x ) res += bit [x] , x -= (x&-x) ;
return res ;
}
void update ( int l , int r , int w )
{
update (l,w) ;
update (r+1,-w) ;
}
void solve ()
{
for ( int j = 1 ; j <= m ; j ++ )
{
for ( int i = 1 ; i <= n ; i ++ )
{
if ( a [i][j] == 'S' )
{
int l = max (i-d,1) , r = min (i+d,n) ;
int col = max (j-d,1) ;
event [col] . pb ({l,r}) ;
col = min (j+d+1,m+1) ;
event [col] . pb ({-l,-r}) ;
}
}
}
int res = 0 ;
for ( int j = 1 ; j <= m ; j ++ )
{
sort (event[j].begin(),event[j].end()) ;
for ( auto x : event [j] )
{
int l = x.fi , r = x.se ;
if ( l < 0 ) update (abs(l),abs(r),-1) ;
else update (l,r,1) ;
}
for ( int i = 1 ; i <= n ; i ++ )
{
if ( a [i][j] == 'M' && get (i) >= k ) res ++ ;
}
}
cout << res ;
}
int main ()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ; cout.tie(0) ;
// rf () ;
cin >> n >> m >> d >> k ;
if ( n < m )
{
for ( int i = 1 ; i <= n ; i ++ )
{
a [i] . resize (m+1) ;
for ( int j = 1 ; j <= m ; j ++ )
{
cin >> a [i][j] ;
}
}
}
else
{
for ( int j = 1 ; j <= m ; j ++ ) a [j] . resize (n+1) ;
for ( int i = 1 ; i <= n ; i ++ )
{
for ( int j = 1 ; j <= m ; j ++ )
{
cin >> a [j][i] ;
}
}
swap (n,m) ;
}
solve () ;
}
컴파일 시 표준 에러 (stderr) 메시지
mushrooms.cpp: In function 'void rf()':
mushrooms.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen ("bai1.inp","r",stdin) ;
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |