Submission #781340

# Submission time Handle Problem Language Result Execution time Memory
781340 2023-07-13T03:50:09 Z gg123_pe Cheerleaders (info1cup20_cheerleaders) C++14
0 / 100
2000 ms 12052 KB
#include <bits/stdc++.h>
using namespace std; 

#define f(i,a,b) for(int i = a; i < b; i++)
const int inf = 2e9; 

int n, k; 
int ans = inf; 
vector <int> res; 
map <vector <int>, bool> on; 

void go(vector <int> v, vector <int> &curr){
    int inver = 0; 
    f(i,0,n) f(j,i+1,n) if(v[i] > v[j]) inver++; 
    on[v] = 1; 

    if(inver < ans){
        ans = inver;  
        res = curr; 
    } 
    if(curr.size() == 2*k) return; 
    f(i,1,3){
        if(i == 1 and curr.size() != 0 and curr.back() == 1) continue; 
        curr.push_back(i); 
        vector <int> aux; 

        if(i == 1){
            f(j,n/2,n) aux.push_back(v[j]); 
            f(j,0,n/2) aux.push_back(v[j]); 
        }
        else{
            f(j,0,n) if(j%2 == 0) aux.push_back(v[j]); 
            f(j,0,n) if(j%2 != 0) aux.push_back(v[j]); 
        }
        if(!on[aux]) go(aux, curr); 
        curr.pop_back(); 
    }
}
int main(){
    vector <int> v, curr; 
    cin >> n; 
    k = n; 
    n = (1<<n); 

    f(i,0,n){
        int x; 
        cin >> x; 
        v.push_back(x); 
    }
    
    go(v, curr); 

    cout << ans << "\n"; 
    for(int x: res) cout << x; 
    if(res.size()) cout << "\n"; 

    return 0; 
}

Compilation message

cheerleaders.cpp: In function 'void go(std::vector<int>, std::vector<int>&)':
cheerleaders.cpp:21:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |     if(curr.size() == 2*k) return;
      |        ~~~~~~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Correct!
2 Incorrect 1 ms 212 KB Wrong number of inversions
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Correct!
2 Correct 4 ms 468 KB Correct!
3 Incorrect 7 ms 468 KB Wrong number of inversions
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2059 ms 12052 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2066 ms 3016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2062 ms 1348 KB Time limit exceeded
2 Halted 0 ms 0 KB -