답안 #734206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734206 2023-05-02T04:52:51 Z vjudge1 Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
70 ms 36532 KB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

template<typename... T>
void see(T&... args) {((cin >> args), ...);}
template<typename... T>
void put(T&&... args) {((cout << args << ' '), ...);}
template<typename... T>
void putl(T&&... args) {((cout << args << ' '), ...); cout << '\n';}

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define F first
#define S second
#define ii pair<int, int>

#define vt vector
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz size()

#define endl '\n'

#define rep(i,a,b) for(int i=a; i<=b; i++)
#define rev(i,b,a) for(int i=b; i>=a; i--)

#define reada(a,x,y) for(int i=x; i<=y; i++){cin >> a[i];}

const int Mxn = 1e6, Nxn = 2*1e5, Mxm = 5e5+5, Nxm = 1005, Dxn = 1e9+1;

int r, c, d, k;
vt<ii> m;
vt<vt<int>> bit;

void update(int x, int y, int val) {
    for(; x <= c; x += (x & -x)) {
        for(int i = y; i <= r; i += (i & -i))
            bit[x][i] += val;
    }
}

int query(int x1, int y1, int x2, int y2){
    int ans = 0;
    for(int i = x2; i; i -= (i & -i)) 
        for(int j = y2; j; j -= (j & -j))
            ans += bit[i][j];
    for(int i = x2; i; i -= (i & -i))
        for(int j = y1 - 1; j; j -= (j & -j))
            ans -= bit[i][j];
    for(int i = x1-1; i; i -= (i & -i))
        for(int j = y2; j; j-= (j & -j))
            ans -= bit[i][j];
    for(int i = x1-1; i; i -= (i & -i))
        for(int j = y1-1; j; j-= (j & -j))
            ans += bit[i][j];

    return ans;
}

void solve() {
    see(r, c, d, k);
    bit.resize(c+1, vt<int>(r+1, 0));
    rep(i,1,r) {
        rep(j,1,c) {
            char x; see(x);
            if(x == 'M') m.pb({i, j});
            if(x == 'S') update(j, i, 1);
        }
    }
    int s = 0, ans = 0;
    rep(i,0,m.size()-1) {
        s = 0;
        int x1 = m[i].F - d, y1 = m[i].S - d;
        int x2 = m[i].F + d, y2 = m[i].S + d;

        if(x1 < 1) x1 = 1;
        if(y1 < 1) y1 = 1;
        if(x2 > r) x2 = r;
        if(y2 > c) y2 = c;
        s += query(y1, x1, y2, x2);
        if(s >= k) ans++;
    }
    cout << ans;
    return;
}

signed main() { IOS
    int t=1;
    //cin >> t;
    while(t--) {
        solve();
        cout << endl;
    }
    return 0;
}

Compilation message

mushrooms.cpp: In function 'void solve()':
mushrooms.cpp:30:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 | #define rep(i,a,b) for(int i=a; i<=b; i++)
......
   77 |     rep(i,0,m.size()-1) {
      |         ~~~~~~~~~~~~~~            
mushrooms.cpp:77:5: note: in expansion of macro 'rep'
   77 |     rep(i,0,m.size()-1) {
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2004 KB Output is correct
2 Correct 4 ms 2052 KB Output is correct
3 Correct 4 ms 2516 KB Output is correct
4 Correct 4 ms 2068 KB Output is correct
5 Correct 4 ms 2176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 32276 KB Output is correct
2 Correct 70 ms 36488 KB Output is correct
3 Correct 56 ms 36532 KB Output is correct
4 Correct 62 ms 32356 KB Output is correct
5 Correct 60 ms 36512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 4 ms 2004 KB Output is correct
17 Correct 4 ms 2052 KB Output is correct
18 Correct 4 ms 2516 KB Output is correct
19 Correct 4 ms 2068 KB Output is correct
20 Correct 4 ms 2176 KB Output is correct
21 Correct 50 ms 32276 KB Output is correct
22 Correct 70 ms 36488 KB Output is correct
23 Correct 56 ms 36532 KB Output is correct
24 Correct 62 ms 32356 KB Output is correct
25 Correct 60 ms 36512 KB Output is correct
26 Correct 18 ms 6936 KB Output is correct
27 Correct 30 ms 8892 KB Output is correct
28 Correct 26 ms 7240 KB Output is correct
29 Correct 23 ms 7332 KB Output is correct
30 Correct 22 ms 9048 KB Output is correct