Submission #535710

# Submission time Handle Problem Language Result Execution time Memory
535710 2022-03-11T01:55:25 Z sam571128 Group Photo (JOI21_ho_t3) C++17
5 / 100
5000 ms 212 KB
#include <bits/stdc++.h>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

signed main(){
    fastio
    int n;
    cin >> n;
    int arr[n];
    for(auto &x : arr) cin >> x;

    int tmp[n];
    iota(tmp,tmp+n,1);

    int ans = 1e18;

    do{
        bool ok = true;
        for(int i = 0;i < n-1;i++){
            if(tmp[i] >= tmp[i+1]+2) ok = false;
        }
        if(!ok) continue;

        int b[n];
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                if(tmp[i]==arr[j]){
                    b[i] = j;
                }
            }
        }

        int cnt = 0;
        for(int i = 0;i < n;i++){
            for(int j = 0;j < i;j++){
                if(b[j] > b[i]){
                    cnt++;
                }
            }
        }
        ans = min(ans,cnt);
    }while(next_permutation(tmp,tmp+n));

    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 4 ms 212 KB Output is correct
8 Correct 4 ms 212 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 5 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 4 ms 212 KB Output is correct
8 Correct 4 ms 212 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 5 ms 212 KB Output is correct
11 Execution timed out 5074 ms 212 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 4 ms 212 KB Output is correct
8 Correct 4 ms 212 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 5 ms 212 KB Output is correct
11 Execution timed out 5074 ms 212 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 4 ms 212 KB Output is correct
8 Correct 4 ms 212 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 5 ms 212 KB Output is correct
11 Execution timed out 5074 ms 212 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 4 ms 212 KB Output is correct
8 Correct 4 ms 212 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 5 ms 212 KB Output is correct
11 Execution timed out 5074 ms 212 KB Time limit exceeded
12 Halted 0 ms 0 KB -