답안 #146093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
146093 2019-08-22T04:36:02 Z youssan_william Pismo (COCI18_pismo) C++14
40 / 70
1000 ms 4524 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int main()
{
    ll n ;
    cin >> n;
    ll arr[n+1];
    for(int i = 1 ; i <=n ;i++)
        cin >> arr[i];
    ll answer=10000000000 , minimum=10000000000 , maximum=-1 , secMinimum , secMaximum ;
    vector<pair<ll,ll> >maxss,minss;
    for(int i = 1 ; i <= n ;i++)
    {
        maxss.push_back({arr[i],i});
        minss.push_back({arr[i],i});
    }
    sort(minss.begin(),minss.end());
    sort(maxss.begin(),maxss.end());
    reverse(maxss.begin(),maxss.end());
    ll l=1 , r=2;
    for( ;  ; r++)
    {
        if(r>n)
        {
            l++;
            r=l+1;
        }
        if(l>=n)
        {
            break;
        }
        for(int i = 0 ; i < n ;i++)
        {
            if(maxss[i].second<=r&&maxss[i].second>=l)
            {
                maximum=maxss[i].first;
                break;
            }
        }
        for(int i = 0 ; i < n ;i++)
        {
            if(minss[i].second<=r&&minss[i].second>=l)
            {
                minimum=minss[i].first;
                break;
            }
        }
        answer=min(answer,maximum-minimum);
    }
    cout << answer ;
    return 0;
}

Compilation message

pismo.cpp: In function 'int main()':
pismo.cpp:12:64: warning: unused variable 'secMinimum' [-Wunused-variable]
     ll answer=10000000000 , minimum=10000000000 , maximum=-1 , secMinimum , secMaximum ;
                                                                ^~~~~~~~~~
pismo.cpp:12:77: warning: unused variable 'secMaximum' [-Wunused-variable]
     ll answer=10000000000 , minimum=10000000000 , maximum=-1 , secMinimum , secMaximum ;
                                                                             ^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 70 ms 348 KB Output is correct
4 Correct 68 ms 436 KB Output is correct
5 Execution timed out 1078 ms 4524 KB Time limit exceeded
6 Execution timed out 1075 ms 4448 KB Time limit exceeded
7 Execution timed out 1077 ms 4324 KB Time limit exceeded