#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 );
}
컴파일 시 표준 에러 (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 time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |