Submission #321231

#TimeUsernameProblemLanguageResultExecution timeMemory
321231prasanth30Collecting Mushrooms (NOI18_collectmushrooms)C++14
79 / 100
2085 ms15832 KiB
#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; auto l=lower_bound(sprinc.begin(), sprinc.end(),max(musc[i]-d,0LL)); auto r=upper_bound(sprinc.begin(),sprinc.end(),max(musc[i]+d,0LL)); if((int)(r-l)>=k)ans++; //cout<<(r-l)<<"\n"; } } 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 ....M .M... ..S.. .S... ...M. */

Compilation message (stderr)

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:69:11: warning: unused variable 'c' [-Wunused-variable]
   69 |       int c=0;
      |           ^
mushrooms.cpp:76: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]
   76 |     else{for(int i=0;i<mush.size();i++){
      |                      ~^~~~~~~~~~~~
mushrooms.cpp:78: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]
   78 |      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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...