이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <complex>
#include <list>
#include <chrono>
#include <random>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;
 
#define endl "\n"
// #define int long long
 
const int INF = 2 * 1e5 + 5;
const int MOD = 1e9 + 7;
 
void solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
 
    int l = 0, r = n-1, h = 0, sol = 0;
    bool turn = 0;
    while(true){
        // cout << a[l] << " " << a[r] << "| " << sol << endl;
        if(l+1 == r) break;
        if(!turn && a[l+1] < a[r-1]){
            l++;
            sol += abs(a[l] - h);
            h = a[l];
        } else {
            r--;
            sol += abs(a[r] - h);
            h = a[r];
        }
    }
 
    cout << sol << endl;
}
 
int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |