Submission #1003400

# Submission time Handle Problem Language Result Execution time Memory
1003400 2024-06-20T09:46:00 Z AdamGS medians (balkan11_medians) C++17
100 / 100
66 ms 11344 KB
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7;
int T[LIM], odw[LIM], czy[LIM];
set<int>S;
int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  rep(i, 2*n-1) S.insert(i+1);
  rep(i, n) cin >> T[i];
  vector<int>ans;
  ans.pb(T[0]);
  S.erase(T[0]);
  rep(i, n-1) {
    if(T[i]==T[i+1]) {
      auto it=S.begin();
      auto a=*it;
      it=S.end(); --it;
      auto b=*it;
      ans.pb(a);
      ans.pb(b);
      S.erase(a);
      S.erase(b);
    } else if(T[i]<T[i+1]) {
      auto it=S.end(); --it;
      auto a=*it;
      ans.pb(a);
      S.erase(a);
      if(S.find(T[i+1])!=S.end()) {
        ans.pb(T[i+1]);
        S.erase(T[i+1]);
      } else {
        it=S.end(); --it;
        a=*it;
        ans.pb(a);
        S.erase(a);
      }
    } else {
      auto it=S.begin();
      auto a=*it;
      ans.pb(a);
      S.erase(a);
      if(S.find(T[i+1])!=S.end()) {
        ans.pb(T[i+1]);
        S.erase(T[i+1]);
      } else {
        it=S.begin();
        a=*it;
        ans.pb(a);
        S.erase(a);
      }
    }
  }
  for(auto i : ans) cout << i << " ";
  cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 4 ms 1208 KB Output is correct
4 Correct 12 ms 2268 KB Output is correct
5 Correct 19 ms 3864 KB Output is correct
6 Correct 44 ms 7504 KB Output is correct
7 Correct 66 ms 11344 KB Output is correct