#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 5e5;
int n;
int a[mxn];
void brute_force(){
bool ok[n];
memset(ok, false, sizeof(ok));
int ans = -1;
int pr[n];
memset(pr, -1, sizeof(pr));
fr(i, 0, n){
ok[i] = true;
if(a[i] > 0){
ans = i;
}
else{
int pos = i;
for(int j = i-1; j >= 0; j --){
if(!ok[j]) continue;
if(a[j] > 0){
pr[pos] = j;
ok[j] = false;
break;
}
else if(a[j] > a[pos]){
pr[pos] = j;
ok[j] = false;
if(pr[j] == -1){
break;
}
else{
pos = pr[j];
pr[j] = -1;
ok[pos] = true;
j = pos;
if(a[pos] >0) break;
}
}
}
}
ans = i;
while(ans >= 0 && (!ok[ans] || a[ans] < 0)){
--ans;
}
if(ans == -1){
cout<<0<<endl;
}
else{
cout<<a[ans] << endl;
}
}
}
void solve(){
cin >> n;
fr(i, 0, n){
cin >> a[i];
}
if(n <= 5000){
brute_force();
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
23 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
42 ms |
484 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
13 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
11 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
2944 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
1920 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
23 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
42 ms |
484 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
13 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
11 ms |
512 KB |
Output is correct |
10 |
Incorrect |
30 ms |
2944 KB |
Unexpected end of file - int32 expected |
11 |
Halted |
0 ms |
0 KB |
- |