답안 #419408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
419408 2021-06-07T05:10:16 Z juggernaut Group Photo (JOI21_ho_t3) C++17
5 / 100
6 ms 296 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
typedef long long ll;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef IOI2021SG
    #define printl(args...)printf(args)
#else
    #define printl(args...)((void)0)
#endif
int n,a[10],b[10],c[10];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    iota(b+1,b+1+n,1);
    int mx=2e9;
    do{
        bool valid=true;
        for(int i=1;i<n;i++)if(b[i]>b[i+1]+1)valid=false;
        if(!valid)continue;
        for(int i=1;i<=n;i++)c[i]=b[i];
        int cnt=0;
        for(int i=1;i<=n;i++){
            int id;
            for(int j=i;j<=n;j++)if(c[j]==a[i])id=j;
            while(id>i){
                swap(c[id],c[id-1]);
                id--;
                cnt++;
            }
        }
        umin(mx,cnt);
    }while(next_permutation(b+1,b+1+n));
    printf("%d",mx);
}

Compilation message

Main.cpp: In function 'void usaco(std::string)':
Main.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:23:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     for(int i=1;i<=n;i++)scanf("%d",&a[i]);
      |                          ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 6 ms 288 KB Output is correct
8 Correct 6 ms 204 KB Output is correct
9 Correct 6 ms 204 KB Output is correct
10 Correct 6 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 6 ms 288 KB Output is correct
8 Correct 6 ms 204 KB Output is correct
9 Correct 6 ms 204 KB Output is correct
10 Correct 6 ms 204 KB Output is correct
11 Runtime error 1 ms 296 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 6 ms 288 KB Output is correct
8 Correct 6 ms 204 KB Output is correct
9 Correct 6 ms 204 KB Output is correct
10 Correct 6 ms 204 KB Output is correct
11 Runtime error 1 ms 296 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 6 ms 288 KB Output is correct
8 Correct 6 ms 204 KB Output is correct
9 Correct 6 ms 204 KB Output is correct
10 Correct 6 ms 204 KB Output is correct
11 Runtime error 1 ms 296 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 6 ms 288 KB Output is correct
8 Correct 6 ms 204 KB Output is correct
9 Correct 6 ms 204 KB Output is correct
10 Correct 6 ms 204 KB Output is correct
11 Runtime error 1 ms 296 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -