Submission #925591

# Submission time Handle Problem Language Result Execution time Memory
925591 2024-02-12T05:46:51 Z vjudge1 Collecting Mushrooms (NOI18_collectmushrooms) C++17
46 / 100
818 ms 22828 KB
/*
no more temmy :(
*/

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
// #include<icecream.hpp>
// using namespace icecream;
#define ll long long
#define int ll
#define ld long double
#define y1 cheza
// mt19937 rng(1983413);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N=5e5+100;
const int M=1e6;
const int B=317;
const int mod=998244353;
const int INF=1e18;
const int lg=64;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
const double eps=1e-9;
int n,m,d,k;
int dist(pair<int,int>x,pair<int,int>y){
    return max(abs(x.first-y.first),abs(x.second-y.second));
}
int pref[N];
vector<ordered_set<int>>t;
void upd(int v,int tl,int tr,int x,int y){
    if(tl==tr){
        t[v].insert(y);
        return;
    }
    int mid=(tl+tr)>>1ll;
    if(x<=mid){
        upd(v*2,tl,mid,x,y);
    }
    else{
        upd(v*2+1,mid+1,tr,x,y);
    }
    t[v].insert(y);
}
int get(int v,int tl,int tr,int lx,int rx,int ly,int ry){
    if(v==1){
        // cout<<lx<<' '<<rx<<' '<<ly<<' '<<ry<<'\n';
    }

    if(tl>rx||tr<lx||t[v].size()==0)return 0;
    if(lx<=tl&&tr<=rx){
        t[v].insert(m+1);
        int res=(int)t[v].order_of_key(ry+1)-(int)t[v].order_of_key(ly);
        t[v].erase(m+1);
        return res;
    }
    int mid=(tl+tr)>>1ll;
    return get(v*2,tl,mid,lx,rx,ly,ry)+get(v*2+1,mid+1,tr,lx,rx,ly,ry);
}
void test(){
    cin>>n>>m>>d>>k;
    t.resize((n+100)*4);
    for(auto &i:t){
        i={};
    }
    vector<pair<int,int>>a,b;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            char x;
            cin>>x;
            if(x=='M'){
                a.push_back({i,j});
            }
            if(x=='S'){
                b.push_back({i,j});
            }
        }
    }

    if(b.size()<k){
        cout<<0<<'\n';
        return;
    }
    int ans=0;
    for(auto [x,y]:b){
        upd(1,1,n,x,y);
        // cout<<x<<' '<<y<<'\n';
    }
    for(auto [x,y]:a){
        int res=get(1,1,n,max(x-d,1ll),min(x+d,n),max(y-d,1ll),min(y+d,m));
        if(res>=k){
            ans++;
        }
    }
    cout<<ans<<'\n';
}
/*

*/  
 
signed main(){
    // ic.prefix("debug->| ");
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    long long t2=1;
    //  cin>>t2;
    for(int i=1;i<=t2;i++){
        test();
    }
    
    return 0;
 
}

Compilation message

mushrooms.cpp: In function 'void test()':
mushrooms.cpp:84:16: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   84 |     if(b.size()<k){
      |        ~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 1116 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 1116 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 238 ms 11444 KB Output is correct
2 Correct 332 ms 9160 KB Output is correct
3 Correct 245 ms 8900 KB Output is correct
4 Correct 818 ms 22828 KB Output is correct
5 Correct 488 ms 13744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 1116 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -