Submission #596675

# Submission time Handle Problem Language Result Execution time Memory
596675 2022-07-15T00:46:28 Z slime Permutation (APIO22_perm) C++17
Compilation error
0 ms 0 KB
#include "perm.h"
#include "bits/stdc++.h"
using namespace std;

long long count_increasing(const vector<int>& v) {
  vector<long long> dp(v.size() + 1, 0);
  dp[0] = 1;
  for (int x : v)
  {
  	for (int i = 0; i <= x; i++)
  	{
  		dp[x+1] += dp[i];
  		dp[x+1] = min(dp[x+1],MX+1);
  	}
  }
  long long result = 0;
  for (int i = 0; i <= (int)v.size(); i++){
  	result += dp[i];
  	result = min(result,MX+1);
  }
  return result;
}

int fastlog(long long x) {
  return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}

std::vector<int> construct_permutation(long long k)
{
  vector<int> cur = {};
  
  cur.push_back(0); 
  for(int i = 1; ; i++) {
    int lb = 0, rb = cur.size();
    if(count_increasing(cur) == k) {
      return cur;
    }
    while(lb < rb) {
      int mid = (lb + rb + 1) >> 1;
      vector<int> now;
      for(int j=0; j<mid; j++) now.push_back(cur[j]);
      now.push_back(i);
      for(int j=mid; j<cur.size(); j++) now.push_back(cur[j]);
      if(count_increasing(now) <= k) lb = mid;
      else rb = mid - 1;
    }
    vector<int> now;
    for(int j=0; j<lb; j++) now.push_back(cur[j]);
    now.push_back(i);
    for(int j=lb; j<cur.size(); j++) now.push_back(cur[j]);
    cur = now;
  }
  return cur;
 
}

Compilation message

perm.cpp: In function 'long long int count_increasing(const std::vector<int>&)':
perm.cpp:13:27: error: 'MX' was not declared in this scope
   13 |     dp[x+1] = min(dp[x+1],MX+1);
      |                           ^~
perm.cpp:19:24: error: 'MX' was not declared in this scope
   19 |    result = min(result,MX+1);
      |                        ^~
perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |       for(int j=mid; j<cur.size(); j++) now.push_back(cur[j]);
      |                      ~^~~~~~~~~~~
perm.cpp:50:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int j=lb; j<cur.size(); j++) now.push_back(cur[j]);
      |                   ~^~~~~~~~~~~