답안 #470158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470158 2021-09-03T06:49:25 Z radal Watermelon (INOI20_watermelon) C++14
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i = l; i < r; i++)
#define pb push_back
#define X first
#define Y second
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;

typedef long long ll;
typedef pair<int, int> pll;

const long long int mod = 1e9+7,N = 25;
int n,k;
int b[N],a[N],ind[N],ind2[N];
inline bool check(vector<int> ve){
    vector<pll> ve2,ve3;
    rep(i,0,n) ve2.pb({ve[i],i});
    int sz = n,p = 1;
    memset(a,-1,sizeof a);
    while (ve2.size()){
        rep(i,0,sz-1){
            if (ve2[i].X > ve2[i+1].X) ve3.pb(ve2[i]);
            else{
                a[ve2[i].Y] = p;
                if (b[ve2[i].Y] != a[ve2[i].Y]) return 0;
            }
        }
        ve3.pb(ve2[sz-1]);
        p++;
        if ((int)ve3.size() == sz) break;
        ve2 = ve3;
        sz = ve2.size();
        ve3.clear();
    }
    rep(i,0,n)
        if (a[i] != b[i]) return 0;
    return 1;
}
bool cmp(vector<int> ve,vector<int> ve2){
    rep(i,0,n){
        ind[ve[i]] = i;
        ind2[ve2[i]] = i;
    }
    rep(i,1,n+1) if (ind[i] < ind2[i]) return 1;
    return 0;
}
int main(){
    cin >> n >> k;
    assert((n == 5));
    rep(i,0,n) cin >> b[i];
    vector<vector<int>> ans;
    vector<int> ve;
    rep(i,1,n+1) ve.pb(i);
    if (check(ve)) ans.pb(ve);
    while (next_permutation(ve.begin(),ve.end()))
        if(check(ve)) ans.pb(ve);
    if ((int)ans.size() < k){
        cout << -1;
        return 0;
    }
    sort(ans.begin(),ans.end(),cmp);
    int sz = ans.size();
    rep(i,0,n) cout << ans[sz-k][i] << ' ';
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -