Submission #523355

#TimeUsernameProblemLanguageResultExecution timeMemory
523355Farhan_HYCheerleaders (info1cup20_cheerleaders)C++14
0 / 100
2090 ms1964 KiB
#include <bits/stdc++.h>
#define int long long
#define float double
#define pb push_back
#define F first
#define S second
#define T int t; cin >> t; while(t--)
#define IOS ios::sync_with_stdio(); cin.tie(0); cout.tie(0);

using namespace std;

const int inf = 8e18;
const int N = 1e6 + 6;
const int M = 1e3 + 3;
const int mod = 1e9 + 7;
const float pi = atan(1) * 4;
int a[N];
int n, m;
vector<int> ans;
int Cnt_Min = inf;
vector<int> v;

bool check()
{
    int cnt = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
            cnt += (a[j] > a[i]);
    }
    if (cnt < Cnt_Min)
        ans = v, Cnt_Min = cnt;
}

void bt(int i, int sum)
{
    if (sum >= 8)
    {
        if (sum == 8)
            check();
        return;
    }
    v.pb(2);
    bt(i + 1, sum + 2);
    v.pop_back();
    v.pb(1);
    bt(i + 1, sum + 1);
    v.pop_back();
}

main()
{
    cin >> n;
    n = (1ll << n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    bt(0, 0);
    cout << 8 << '\n';
    for(auto x: ans)
        cout << x;
}

//3
//2 3 7 6 1 4 5 0
//2 7 1 5 3 6 5 0

Compilation message (stderr)

cheerleaders.cpp: In function 'bool check()':
cheerleaders.cpp:33:1: warning: no return statement in function returning non-void [-Wreturn-type]
   33 | }
      | ^
cheerleaders.cpp: At global scope:
cheerleaders.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   51 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...