Submission #321224

# Submission time Handle Problem Language Result Execution time Memory
321224 2020-11-11T15:11:44 Z prasanth30 Collecting Mushrooms (NOI18_collectmushrooms) C++14
60 / 100
2000 ms 8656 KB
#include <bits/stdc++.h>
using namespace std;
//actual solution is at bottom//
////<pbds>////
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, 
    rb_tree_tag, tree_order_statistics_node_update>; 
// change null_type for map
// change less to less_equal for multiset
#define ook order_of_key
#define fbo find_by_order*/
///</pbds>///

#define int long long int
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define google(i) cout<<"Case #"<<i<<" :";
///<constants>///
const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5; 
const ll INF = 1e18; 
const ld PI = 4*atan((ld)1); 
const int xd[4] = {0,1,0,-1}, yd[4] = {1,0,-1,0};
///</constants>///

///<IO>/// 
namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        // cin.exceptions(cin.failbit); // ex. throws exception when you try to read letter into int
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
    }
}
 
using namespace io;
///</IO>///

///<execution-time>///
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
/*example for clock usage
    clock_t z = clock();
    debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
*/
///</execution-time>///
signed main(){
    setIO("");
    int r,c,d,k;cin>>r>>c>>d>>k;
    vector<pair<int,int>> mush,sprin;
    vector<int> musc,sprinc;
    for(int i=1;i<=r;i++){
    	for(int j=1;j<=c;j++){
    		char c;cin>>c;
    		if(c=='.')continue;
    		if(c=='M'){mush.pb({i,j});musc.pb(j);}
    		if(c=='S'){sprin.pb({i,j});sprinc.pb(j);}
    	}
    }
    int ans=0;
    if(r==1){
    	for(int i=0;i<musc.size();i++){
    		int c=0;
    		int l=lower_bound(sprinc.begin(), sprinc.end(),max(musc[i]-d,0LL))-sprinc.begin()-1;
    		for(int j=l;j<sprinc.size();j++){
    			if(abs(musc[i]-sprinc[j])>=d)c++;
    			if(sprinc[j]-musc[i]>d)break;
    			if(c>=k)break;
    		}
    		if(c>=k)ans++;
    	}	
    }
    else{for(int i=0;i<mush.size();i++){
    	int c=0;
    	for(int j=0;j<sprin.size();j++){
    		if(max(abs(sprin[j].first-mush[i].first),abs(sprin[j].second-mush[i].second))<=d)c++;
    		if(c>=k)break;
    	}
    	if(c>=k)ans++;
    }}
    cout<<ans<<"\n";
    return 0;
}
/* stuff you should look for
    * check whether you have read the problem correctly
    * int overflow, array bounds
    * special cases (n=1?), slow multiset operations
    * do smth instead of nothing and stay organized
*/

Compilation message

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:68:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |      for(int i=0;i<musc.size();i++){
      |                  ~^~~~~~~~~~~~
mushrooms.cpp:71:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |       for(int j=l;j<sprinc.size();j++){
      |                   ~^~~~~~~~~~~~~~
mushrooms.cpp:79:23: 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]
   79 |     else{for(int i=0;i<mush.size();i++){
      |                      ~^~~~~~~~~~~~
mushrooms.cpp:81:19: 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]
   81 |      for(int j=0;j<sprin.size();j++){
      |                  ~^~~~~~~~~~~~~
mushrooms.cpp: In function 'void io::setIn(std::string)':
mushrooms.cpp:34:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   34 |     void setIn(string s) { freopen(s.c_str(),"r",stdin); }
      |                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp: In function 'void io::setOut(std::string)':
mushrooms.cpp:35:36: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   35 |     void setOut(string s) { freopen(s.c_str(),"w",stdout); }
      |                             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 17 ms 620 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 5 ms 620 KB Output is correct
3 Correct 9 ms 748 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 620 KB Output is correct
2 Correct 4 ms 620 KB Output is correct
3 Correct 5 ms 620 KB Output is correct
4 Correct 4 ms 620 KB Output is correct
5 Correct 4 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2050 ms 8656 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 17 ms 620 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 5 ms 620 KB Output is correct
13 Correct 9 ms 748 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 4 ms 620 KB Output is correct
17 Correct 4 ms 620 KB Output is correct
18 Correct 5 ms 620 KB Output is correct
19 Correct 4 ms 620 KB Output is correct
20 Correct 4 ms 620 KB Output is correct
21 Execution timed out 2050 ms 8656 KB Time limit exceeded
22 Halted 0 ms 0 KB -