# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
922199 | Isam | Pismo (COCI18_pismo) | C++17 | 15 ms | 1704 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
constexpr int sz = 1e5 + 6;
int n, a[sz];
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for(register int i = 1; i <= n; ++i){
cin >> a[i];
}
int ans = (int)(1e9 + 7);
for(register int i = 1; i <= n; ++i){
int l = i - 1, r = i + 1, mn = (int)(1e9);
while(l || r <= n){
if(a[l] > a[i]) l = 0;
if(a[r] > a[i]) r = n + 1;
if(l && r <= n){
if(a[l] > a[r]){
mn = min(mn, a[l]);
ans = min(ans, a[i] - mn);
--l;
}else{
mn = min(mn, a[r]);
ans = min(ans, a[i] - mn);
++r;
}
}else if(l){
mn = min(mn, a[l]);
ans = min(ans, a[i] - mn);
--l;
}else if(r <= n){
mn = min(mn, a[r]);
ans = min(ans, a[i] - mn);
++r;
}else{
break;
}
}
// cout << i << ' ' << ans << '\n';
}
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |