제출 #652952

#제출 시각아이디문제언어결과실행 시간메모리
652952aryan12순열 (APIO22_perm)C++17
91.33 / 100
4 ms340 KiB
#include "perm.h" #include <bits/stdc++.h> using namespace std; vector<int> construct_permutation(long long k) { k--; long long cnt = 0; while(true) { if((1LL << (cnt + 1)) - 1 <= k) { cnt++; } else { break; } } k -= (1LL << cnt) - 1; // cout << "cnt = " << cnt << endl; vector<int> ans; int omk = 1; for(int i = 0; i < cnt; i++) { ans.push_back(omk); omk += 3; } omk -= 4; // cout << "k = " << k << endl; for(long long i = cnt - 1; i >= 0; i--) { if((1LL << i) <= k) { k -= (1LL << i); // cout << "i = " << i << endl; ans.push_back(omk); if((1LL << i) <= k) { k -= (1LL << i); // cout << "i = " << i << endl; ans.push_back(omk - 1); } } // cout << "k = " << fixed << setprecision(0) << k << endl; omk -= 3; } map<int, int> cc; for(int i = 0; i < ans.size(); i++) { cc[ans[i]]++; } int ccc = 0; for(auto i: cc) { cc[i.first] = ccc++; } for(int i = 0; i < ans.size(); i++) { ans[i] = cc[ans[i]]; // cout << ans[i] << " "; } // cout << "k = " << k << endl; // cout << "perm\n"; return ans; }

컴파일 시 표준 에러 (stderr) 메시지

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:50:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for(int i = 0; i < ans.size(); i++)
      |                 ~~^~~~~~~~~~~~
perm.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for(int i = 0; i < ans.size(); i++)
      |                 ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...