This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define int long long
#define pb push_back
#define s second
#define f first
#define pf push_front
#define inf 100000000000000000
#define bitebi __builtin_popcountll
#define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
#define YES cout <<"YES\n"
#define NO cout << "NO\n"
#define debug cout << "Here Fine" << endl ;
#define pr pair < int , int >
#define fbo find_by_order // returns iterator
#define ook order_of_key // returns strictly less numbers than key
using namespace std ;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template<class T> using ordered_set =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
const double Pi=acos(-1.0);
const double EPS=1E-8;
const int mod = 1000000007 ;
const int mod1 = 998244353 ;
const int N = 2e6 + 10 ;
mt19937 R(time(0));
map < int , int > ma , ma1 ;
int n , sl , sc , el , ec ;
int a[ N ] ;
set < int > se ;
void solve1(){
int x = a[ 0 ] + 1 ;
int ans = abs( sl - el ) ;
int tt1 = 0 , tt2 = 0 ;
if( el <= sl ) tt1 = 1 ;
if( el >= sl ) tt2 = 1 ;
if( sl == n ){
assert(0) ;
}
ans = ans + min(
{
x - sc + ec + tt1 ,
abs( sc - ec ) + tt2 ,
sc + ( x - ec )
}) ;
cout << ans ;
return ;
}
void solve(){
cin >> n >> sl >> sc >> el >> ec ;
FOR( i , n ){
cin >> a[ i ] ;
if( i != n - 1 )
se.insert( a[ i ] ) ;
}
if( se.size() == 1 ){
solve1() ;
return ;
}
}
signed main() {
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int t = 1 ; // cin >> t ;
while( t -- ){
solve() ;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |