Submission #587200

#TimeUsernameProblemLanguageResultExecution timeMemory
587200M_WSwap (BOI16_swap)C++17
0 / 100
1 ms316 KiB
#include <bits/stdc++.h> #define ar array<int, 3> using namespace std; int a[200002]; ar find_min(int a, int b, int c){ vector<ar> tmp; tmp.push_back({a, b, c}); tmp.push_back({b, a, c}); tmp.push_back({c, a, b}); tmp.push_back({c, b, a}); sort(tmp.begin(), tmp.end()); return tmp[0]; } int main(){ int N; scanf("%d", &N); for(int i = 1; i <= N; i++) scanf("%d", &a[i]); a[N + 1] = INT_MAX; for(int i = 1; i * 2 <= N; i++){ ar tmp; if(i * 2 + 1 > N) tmp = find_min(a[i], a[i * 2], max(a[i], a[i * 2])); else tmp = find_min(a[i], a[i * 2], a[i * 2 + 1]); int nxt1 = min(a[min(N + 1, (i * 2) * 2)], a[min(N + 1, (i * 2) * 2 + 1)]); int nxt2 = min(a[min(N + 1, (i * 2 + 1) * 2)], a[min(N + 1, (i * 2 + 1) * 2 + 1)]); if(tmp[0] == a[i * 2 + 1]){ if(nxt1 < tmp[1] && nxt2 >= tmp[1]) swap(tmp[1], tmp[2]); } a[i] = tmp[0]; a[i * 2] = tmp[1]; a[i * 2 + 1] = tmp[2]; } for(int i = 1; i <= N; i++) printf("%d ", a[i]); }

Compilation message (stderr)

swap.cpp: In function 'int main()':
swap.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
swap.cpp:19:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  for(int i = 1; i <= N; i++) scanf("%d", &a[i]);
      |                              ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...