Submission #850041

# Submission time Handle Problem Language Result Execution time Memory
850041 2023-09-15T16:43:28 Z Andrey Permutation (APIO22_perm) C++17
100 / 100
2 ms 348 KB
#include "perm.h"
#include<bits/stdc++.h>
using namespace std;

vector<int> construct_permutation(long long k) {
    vector<int> ans(0);
    vector<int> haha(0);
    while(k > 0) {
        haha.push_back(k%4);
        k/=4;
    }
    reverse(haha.begin(),haha.end());
    bool yeah = false;
    if(haha[0] == 2) {
        ans.push_back(0);
    }
    else if(haha[0] == 3) {
        ans.push_back(1);
        ans.push_back(0);
        yeah = true;
    }
    for(int i = 1; i < haha.size(); i++) {
        if(haha[i] == 0) {
            ans.push_back(ans.size());
            ans.push_back(ans.size());
        }
        else if(haha[i] == 1) {
            ans.push_back(ans.size());
            ans.push_back(ans.size());
            for(int j = 0; j < ans.size(); j++) {
                ans[j]++;
            }
            ans.push_back(0);
        }
        else if(haha[i] == 2) {
            ans.push_back(ans.size());
            for(int j = 0; j < ans.size(); j++) {
                ans[j]++;
            }
            ans.push_back(0);
            ans.push_back(ans.size());
        }
        else {
            if(yeah) {
                ans.push_back(ans.size());
                ans.push_back(ans.size());
                for(int j = 0; j < ans.size(); j++) {
                    if(ans[j] >= 2) {
                        ans[j]++;
                    }
                }
                ans.push_back(2);
            }
            else {
                ans.push_back(ans.size());
                for(int j = 0; j < ans.size(); j++) {
                    ans[j]++;
                }
                ans.push_back(0);
                ans.push_back(ans.size());
                for(int j = 0; j < ans.size(); j++) {
                    ans[j]++;
                }
                ans.push_back(0);
                yeah = true;
            }
        }
    }
	return ans;
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i = 1; i < haha.size(); i++) {
      |                    ~~^~~~~~~~~~~~~
perm.cpp:30:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |             for(int j = 0; j < ans.size(); j++) {
      |                            ~~^~~~~~~~~~~~
perm.cpp:37:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             for(int j = 0; j < ans.size(); j++) {
      |                            ~~^~~~~~~~~~~~
perm.cpp:47:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |                 for(int j = 0; j < ans.size(); j++) {
      |                                ~~^~~~~~~~~~~~
perm.cpp:56:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |                 for(int j = 0; j < ans.size(); j++) {
      |                                ~~^~~~~~~~~~~~
perm.cpp:61:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |                 for(int j = 0; j < ans.size(); j++) {
      |                                ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct