Submission #932509

# Submission time Handle Problem Language Result Execution time Memory
932509 2024-02-23T14:24:57 Z nguyentunglam Permutation (APIO22_perm) C++17
91.3333 / 100
2 ms 408 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;

const long long inf = 2e18;

long long calc (vector<int> a) {
  vector<long long> f(a.size());
  long long ret = 1;
  for(int i = 0; i < a.size(); i++) {
    f[i] = 1;
    for(int j = 0; j < i; j++) if (a[j] < a[i]) f[i] = min(inf, f[i] + f[j]);
    ret += f[i];
  }
  return ret;
}

vector<int> construct_permutation(long long k) {
  vector<int> p;
  int l = 0, r = 1e9;
  while (k != 1) {
    if (k % 2 == 0) p.push_back(--r);
    else {
      p.push_back(++l);
      p.push_back(--r);
    }
    k /= 2;
  }
  reverse(p.begin(), p.end());
  vector<int> rrh = p;
  sort(rrh.begin(), rrh.end());
  rrh.resize(unique(rrh.begin(), rrh.end()) - rrh.begin());
//  for(int &j : rrh) cout << j << " "; cout << endl;
  auto get = [&] (int x) {
    return lower_bound(rrh.begin(), rrh.end(), x) - rrh.begin();
  };

//  cout << get(1);
//  cout << get(2) << endl;
//  cout << endl;
  for(int &j : p) j = get(j);
  return p;
}

#ifdef ngu
int main() {

  freopen ("task.inp", "r", stdin);
  freopen ("task.out", "w", stdout);

  long long k; cin >> k;

  vector<int> ans = construct_permutation(k);
  for(int &j : ans) cout << j << " "; cout << endl;
  assert(calc(ans) == k);
}
#endif // ngu

Compilation message

perm.cpp: In function 'long long int calc(std::vector<int>)':
perm.cpp:13:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |   for(int i = 0; i < a.size(); i++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Partially correct 1 ms 348 KB Partially correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Partially correct 2 ms 408 KB Partially correct
9 Correct 1 ms 348 KB Output is correct
10 Partially correct 2 ms 348 KB Partially correct
11 Partially correct 2 ms 348 KB Partially correct
12 Partially correct 2 ms 348 KB Partially correct
13 Partially correct 2 ms 344 KB Partially correct