답안 #971212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971212 2024-04-28T07:16:34 Z Abito Real Mountains (CCO23_day1problem2) C++17
0 / 25
1 ms 2396 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
//#define int long long
#define ll long long
#define y1 YONE
#define free freeee
#define lcm llcm
typedef unsigned long long ull;
using namespace std;
const int N=5e5+5;
int a[N],n,b[N];
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    if (a[1]>a[n]) reverse(a+1,a+1+n);
    int ans=0;
    while (!is_sorted(a+1,a+1+n)){
        int idx=0,mn=INT_MAX;
        for (int i=2;i<n;i++){
            if (a[i]<mn){
                mn=a[i];
                idx=i;
            }
        }
        int hi=INT_MAX,hk=INT_MAX;
        for (int i=1;i<idx;i++) if (a[i]>a[idx]) hi=min(hi,a[i]);
        for (int i=idx+1;i<=n;i++) if (a[i]>a[idx]) hk=min(hk,a[i]);
        a[idx]++;
        ans+=hi+mn+hk;
        for (int i=1;i<=n;i++) cout<<a[i]<<' ';cout<<endl;
    }cout<<ans<<endl;
    return 0;
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:40:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   40 |         for (int i=1;i<=n;i++) cout<<a[i]<<' ';cout<<endl;
      |         ^~~
Main.cpp:40:48: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   40 |         for (int i=1;i<=n;i++) cout<<a[i]<<' ';cout<<endl;
      |                                                ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -