Submission #1301705

#TimeUsernameProblemLanguageResultExecution timeMemory
1301705maomaoGlobal Warming (NOI13_gw)C++20
40 / 40
177 ms12620 KiB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i=s;i<=n;i++)
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second

int GW ( int size, int *H )
{
	int ans = 0, cnt=0;
	vector<pii> v;
	rep(i,0,size-1) v.pb({H[i], i});
	sort(v.begin(), v.end());
	vector<bool> active(size, 0);
	while(v.size()) {
		int h = v.back().fi;
		while(v.size() && v.back().fi==h) {
		  active[v.back().se] = 1;
			bool l = (v.back().se>0 && active[v.back().se - 1]),
				 r = (v.back().se<size-1 && active[v.back().se + 1]);
			if(l&&r) cnt--;
			if(!l && !r) cnt++;
			v.pop_back();
		}
		ans = max(ans, cnt);
	}
	return ans;
}


int main()
{
   int  size;
   //int  *H;
   int  i;
   int  NumberOfIslands;

   /*------------------------*/
   /* R e a d    i n p u t   */
   /*------------------------*/
   scanf ("%d",  &size );
   //H = malloc ( size* sizeof(int) );
   int H[size];
   for (i=0; i<size; i++)
     {  scanf ("%d",  &H[i] );  }

   NumberOfIslands =   GW ( size, H );

   printf ( "%d\n", NumberOfIslands );

}

Compilation message (stderr)

gw.cpp: In function 'int main()':
gw.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |    scanf ("%d",  &size );
      |    ~~~~~~^~~~~~~~~~~~~~~
gw.cpp:47:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |      {  scanf ("%d",  &H[i] );  }
      |         ~~~~~~^~~~~~~~~~~~~~~
#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...