Submission #679809

#TimeUsernameProblemLanguageResultExecution timeMemory
679809nguyentunglamSwap (BOI16_swap)C++14
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 1e5 + 10; int a[N], pos[N], b[N], p[N], n; int dfs(int u) { if (!b[u]) return u; int ret = n + 1; if (!p[u * 2]) ret = min(ret, dfs(u * 2)); if (!p[u * 2 + 1]) ret = min(ret, dfs(u * 2 + 1)); return ret; } int main() { #define task "swap" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } cin >> n; for(int i = 1; i <= n; i++) cin >> a[i], pos[a[i]] = i; for(int i = 1; i <= n; i++) { int j = pos[i]; if (j != 1 && !b[j / 2]) b[j / 2] = i; else if (!b[j]) b[j] = i; else { int Start = j == 1 ? j : j / 2; int k = dfs(Start); b[k] = i; int v = k; while (v != Start) p[v] = 1, v /= 2; } } for(int i = 1; i <= n; i++) cout << b[i] << " "; }

Compilation message (stderr)

swap.cpp: In function 'int main()':
swap.cpp:20:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
swap.cpp:21:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
swap.cpp:24:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
swap.cpp:25:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...