답안 #872967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872967 2023-11-14T07:46:49 Z vjudge1 Climbers (RMI18_climbers) C++17
0 / 100
1 ms 2516 KB
#include <bits/stdc++.h>
#define f first
#define S second
#define pb push_back
#define msk(x , y) ((x >> y) & 1)
#define all(x) x.begin() , x.end()
using namespace std;
typedef long long int ll;
const int N = 2e5 + 7;
const int mod = 1e9 + 7;
const int dx[] = {-1,-1,1,1,2,-2,2,-2};
const int dy[] = {-2,2,2,-2,1,1,-1,-1};

ll n , a[N] , p[N] , s[N];

void solve(){
	cin >> n ;
	int mx = 0 , pos = 0 ;
	for(int i = 1 ;i <= n ; i++){
		cin >> a[i];
		if(mx < a[i]) mx = a[i] , pos = i ;
	}
	vector < pair < int , int > > p , s;
	for(int i = 2 ; i <= pos ; i++){
		p.pb({a[i - 1] , a[i]});
	}	
	for(int i = n - 1 ; i >= pos ; i--){
		s.pb({a[i + 1] , a[i]});
	}
	int l = 0 , r = 0 , ok = 1 , lst = 0;
	ll ans = 0 ;
	while(l < p.size() || r < s.size()){
		pair < int , int > x , y ;
		x = p[l];
		y = s[r];
		if(x.S == y.S){
			ans += abs(x.S - lst); 
			lst = x.S ;
			l++,r++;
			ok^=1 ;
			continue;
		}
		if(!ok){
			ok ^= 1;
			if(x.S < y.S){
				if(x.S >= y.f) ans+=abs(x.S - lst), lst = x.S ,l++,ok^=1;
				else if(x.S >= s[r - 1].f && x.S <= s[r - 1].S) ans+=abs(x.S-lst), lst =x.S,l++,r--,ok^=1;
				else{
					cout << "NO\n";
					return ;	
				}
			}else{
				if(y.S >= x.f) ans += abs(y.S - lst) , lst = y.S, r++,ok^=1;
				else if(y.S >= p[l - 1].f && y.S <= p[l - 1].S) ans += abs(y.S - lst) , lst = y.S ,r++,l--,ok^=1;
				else{
					cout << "NO\n";
					return ;
				}
			}
		}else{
			if(x.S < y.S){
				ans += abs(x.S - lst);
				lst = x.S ;
				l++;
			}else{
				ans+=abs(y.S - lst);
				lst=y.S;
				r++;
			}
			ok ^= 1; 
		}
	}
	cout << ans << "\n"; 
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);  
    cout.tie(0);
    int test=1;
    // cin >> test ;
    for(int i=1;i<=test;i++){
//      cout << "Case " << i << ": ";
        solve();
     }
}

Compilation message

climbers.cpp: In function 'void solve()':
climbers.cpp:32:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  while(l < p.size() || r < s.size()){
      |        ~~^~~~~~~~~~
climbers.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  while(l < p.size() || r < s.size()){
      |                        ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Incorrect 1 ms 2392 KB Output isn't correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Incorrect 1 ms 2396 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2396 KB Output isn't correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Incorrect 0 ms 2396 KB Output isn't correct
4 Incorrect 1 ms 2516 KB Output isn't correct
5 Incorrect 1 ms 2396 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Incorrect 1 ms 2392 KB Output isn't correct
5 Incorrect 1 ms 2396 KB Output isn't correct
6 Incorrect 1 ms 2396 KB Output isn't correct
7 Incorrect 1 ms 2392 KB Output isn't correct
8 Incorrect 1 ms 2396 KB Output isn't correct
9 Incorrect 1 ms 2396 KB Output isn't correct
10 Incorrect 1 ms 2396 KB Output isn't correct