제출 #668410

#제출 시각아이디문제언어결과실행 시간메모리
668410mdubaisiZalmoxis (BOI18_zalmoxis)C++14
0 / 100
3 ms400 KiB
#include <bits/stdc++.h> #include <array> #include <unordered_set> #define ll long long #define all(v) (v.begin()), (v.end()) #define setall(a, val) for(auto& x : a) x = val clock_t start_time; double get_time() { return (double)(clock() - start_time) / CLOCKS_PER_SEC; } void init() { #ifndef ONLINE_JUDGE FILE* _ = freopen("in.txt", "r", stdin); start_time = clock(); #endif } const ll MOD = 1e9 + 7; const ll N = 5e6 + 7; const ll M = 5e1 + 7; using namespace std; //#################################################################################### int n, k, a[N]; void first_second(stack<int> s, int& x, int& y) { if (s.size() < 2) { y = -1; if (s.size() < 1) x = -1; else x = s.top(); return; } x = s.top(); s.pop(); y = s.top(); } void merge(stack<int>& s) { int x, y; // cur, prev first_second(s, x, y); if (x < 0 || y < 0) return; while (x == y) { s.pop(); s.pop(); s.push(x + 1); first_second(s, x, y); if (x < 0 || y < 0) return; } } vector< pair<int, bool> > v; // print, new void add(stack<int>& s) { int x, y; first_second(s, x, y); // cur, prev if (x < 0) return; s.push(x); v.push_back({ x, 1 }); merge(s); } void print(int x, int t) { if (!t) { cout << x << ' '; return; } else if (x) { print(x - 1, 0); print(x - 1, t - 1); } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); init(); srand(time(0)); cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int sz = n + k; stack<int> s; s.push(a[0]); v.push_back({ a[0], 0 }); for (int i = 1; i < n; i++) { while (a[i] > s.top()) { add(s); k--; } v.push_back({ a[i], 0 }); s.push(a[i]); merge(s); } if (v.size() != sz) { add(s); k--; } for (pair<int, bool> p : v) { int x = p.first; bool f = p.second; print(x, f * k); k *= (!f); } cout << endl; cerr << get_time() << "s" << endl; }

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

zalmoxis.cpp: In function 'void init()':
zalmoxis.cpp:11:8: warning: unused variable '_' [-Wunused-variable]
   11 |  FILE* _ = freopen("in.txt", "r", stdin);
      |        ^
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:99:15: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, bool> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   99 |  if (v.size() != sz) {
      |      ~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...