Submission #580255

#TimeUsernameProblemLanguageResultExecution timeMemory
580255AlperenTZalmoxis (BOI18_zalmoxis)C++17
5 / 100
651 ms262144 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5; int n, k, arr[N], lftcnt; vector<pair<int, int>> v, v2; vector<int> nums[N], vec, ans; bool req[N]; int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); cin >> n >> k; for(int i = 0; i < n; i++){ cin >> arr[i]; nums[i].push_back(arr[i]); v.push_back({arr[i], i}); } for(int num = 1; num <= 29; num++){ swap(v, v2); v.clear(); for(auto p : v2){ if(v.empty()) v.push_back(p); else{ if(v.back().first == num){ if(p.first == num){ v.back().first = num + 1; v.back().second = p.second; } else{ v.back().first = num + 1; nums[v.back().second].push_back(num); v.push_back(p); } } else v.push_back(p); } } if(v.back().first == num){ v.back().first = num + 1; nums[v.back().second].push_back(num); } } for(int i = 0; i < n; i++){ for(auto j : nums[i]){ vec.push_back(j); } } int ptr = 0; for(int i = 0; i < vec.size(); i++){ if(ptr < n && vec[i] == arr[ptr]) req[i] = true, ptr++; } lftcnt = (n + k) - vec.size(); for(int i = 0; i < vec.size(); i++){ if(!req[i] && lftcnt){ int lftlog = __lg(lftcnt + 1); if(vec[i] - lftlog <= 1){ for(int j = 0; j < (1 << (vec[i] - 1)); j++) ans.push_back(1); lftcnt -= (1 << (vec[i] - 1)) - 1; } else{ vector<int> tmp; for(int j = 0; j < (1 << lftlog); j++) tmp.push_back(vec[i] - lftlog); lftcnt -= (1 << lftlog) - 1; while(lftcnt > 0){ ans.push_back(tmp.back() - 1); ans.push_back(tmp.back() - 1); lftcnt--; tmp.pop_back(); } for(auto j : tmp) ans.push_back(j); } } else ans.push_back(vec[i]); } for(auto i : ans) cout << i << " "; }

Compilation message (stderr)

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