답안 #856774

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856774 2023-10-04T14:21:31 Z Tenis0206 Secret Permutation (RMI19_permutation) C++14
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>
#ifndef home
#include "permutation.h"
#endif // home

using namespace std;

const int nmax = 256;

int n;

#ifdef home

vector<int> p;

void debug(vector<int> c)
{
    for(auto it : c)
    {
        cerr<<it<<' ';
    }
    cerr<<'\n';
}

void answer(vector<int> rez)
{
    for(auto it : rez)
    {
        cout<<it<<' ';
    }
    cout<<'\n';
}

int query(vector<int> v)
{
    int sum = 0;
    for(int i=1;i<n;i++)
    {
        sum += abs(p[v[i - 1] - 1] - p[v[i] - 1]);
    }
    return sum;
}

#endif // home

vector<int> find_rev(vector<int> r)
{
    vector<int> rez(n);
    for(int i=0;i<n;i++)
    {
        rez[r[i] - 1] = i + 1;
    }
    return rez;
}

void solve(int N)
{
    n = N;
    vector<int> r(n);
    for(int i=0;i<n;i++)
    {
        r[i] = i + 1;
    }
    int val = query(r);
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            swap(r[i - 1], r[j - 1]);
            int cur = query(r);
            if(cur < val)
            {
                val = cur;
            }
            else
            {
                swap(r[i - 1], r[j - 1]);
            }
        }
    }
    vector<int> rez = find_rev(r);
    answer(rez);
}

#ifdef home

int main()
{
    freopen("nr.in","r",stdin);
    freopen("nr.out","w",stdout);
    int nn;
    cin>>nn;
    p.resize(nn);
    for(int i=1;i<=nn;i++)
    {
        cin>>p[i - 1];
    }
    solve(nn);
    return 0;
}

#endif // home

Compilation message

stub.cpp: In function 'int query(int*)':
stub.cpp:15:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   fscanf(stdin, "%d", &x);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
stub.cpp: In function 'int main(int, char**)':
stub.cpp:48:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   fscanf(stdin, "%d", &N);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -