Submission #1353092

#TimeUsernameProblemLanguageResultExecution timeMemory
1353092lukaye_19Art Collections (BOI22_art)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

/*
vector <int> ans = {3,2,1,4,5,6,7,8,12,11,10,9};
vector <int> pos = {3,2,1,4,5,6,7,8,12,11,10,9};

int cnt=0;

void answer(vector <int> v){
    cout<<cnt<<"\n";
    if (v==ans){cout<<"YES";}
    else{for (auto x : v){cout<<x<<' ';}}
}

int publish(vector <int> v){
    cnt++;
    int n=v.size();
    int sm=0;
    for (int i=n-1; i>=1; i--){
        for (int j=i-1; j>=0; j--){
            if (pos[v[j]-1]>pos[v[i]-1]){sm++;}
        }
    }
    return sm;
}
*/

vector<int>switchtwo(int a,int b,vector<int>c)
{
    if (a == b) return c;
    
    int i1,i2;
    
    int n = c.size();
    
    for (int i = 0; i < n; i++)
        if (c[i] == a) i1 = i;
        else if (c[i] == b) i2 = i;
    
    swap(c[i1],c[i2]);
    
    return c;
}

void solve(int N)
{
    vector<int>c(N);
    
    for (int i = 1; i <= N; i++) c[i - 1] = i;
    
    for (int i = 1; i <= N; i++)
    {
        int minsm = INT_MAX;
        vector<int>minc;
        
        for (int j = 1; j <= N; j++)
        {
            vector<int>newc = switchtwo(i,j,c);
            
            int cursm = publish(newc);
            
            if (cursm < minsm) 
            {
                minc = newc;
                minsm = cursm;
            }
            
            if (!minsm) break;
        }
        
        c = minc;
        
        if (!minsm) break;
    }
    
    answer(c);
    
    return;
}

Compilation message (stderr)

art.cpp: In function 'void solve(int)':
art.cpp:61:25: error: 'publish' was not declared in this scope
   61 |             int cursm = publish(newc);
      |                         ^~~~~~~
art.cpp:77:5: error: 'answer' was not declared in this scope
   77 |     answer(c);
      |     ^~~~~~