Submission #199798

#TimeUsernameProblemLanguageResultExecution timeMemory
199798zoooma13Pismo (COCI18_pismo)C++14
70 / 70
29 ms764 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...