# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199798 | zoooma13 | Pismo (COCI18_pismo) | C++14 | 29 ms | 764 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int solve(vector <int>&a){
vector <int> mq ,dq;
int ret = INT_MAX;
for(int i=0; i<a.size(); i++){
while(!mq.empty() && a[mq.back()] < a[i])
mq.pop_back();
while(!dq.empty() && a[dq.back()] > a[i])
dq.pop_back();
if(!mq.empty() && (dq.empty() || (a[dq.back()] >= a[i] || dq.back() <= mq.back())))
ret = min(ret ,a[mq.back()]-a[i]);
mq.push_back(i);
dq.push_back(i);
}
return ret;
}
int main()
{
int n;
scanf("%d",&n);
vector <int> a(n);
for(int&i : a)
scanf("%d",&i);
int p = solve(a);
reverse(a.begin() ,a.end());
cout << min(p ,solve(a)) << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |