Submission #199798

# Submission time Handle Problem Language Result Execution time Memory
199798 2020-02-03T13:03:04 Z zoooma13 Pismo (COCI18_pismo) C++14
70 / 70
29 ms 764 KB
#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;
}

Compilation message

pismo.cpp: In function 'int solve(std::vector<int>&)':
pismo.cpp:7:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<a.size(); i++){
                  ~^~~~~~~~~
pismo.cpp: In function 'int main()':
pismo.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
pismo.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&i);
         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 27 ms 632 KB Output is correct
6 Correct 29 ms 636 KB Output is correct
7 Correct 28 ms 764 KB Output is correct