Submission #1301698

#TimeUsernameProblemLanguageResultExecution timeMemory
1301698maomaoGlobal Warming (NOI13_gw)C++20
23 / 40
171 ms12616 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#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 )
{
	ll ans = 0, cnt=0;
	vector<pii> v;
	rep(i,0,size-1) v.pb({H[i], i});
	sort(v.begin(), v.end(), greater<>());
	vector<bool> active(size, 0);
	rep(i,0,size-1) {
		int id = v[i].se;
		active[id]=1;
		bool l=(id>0&&active[id-1]);
		bool r=(id<size-1 && active[id+1]);
		if(l && r) cnt--;
		else if(!l && !r) cnt++;
		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:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |    scanf ("%d",  &size );
      |    ~~~~~~^~~~~~~~~~~~~~~
gw.cpp:45:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |      {  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...