Submission #660565

# Submission time Handle Problem Language Result Execution time Memory
660565 2022-11-22T10:27:04 Z 600Mihnea medians (balkan11_medians) C++17
10 / 100
300 ms 2324 KB
bool home = 0;

#include <bits/stdc++.h>

using namespace std;

const int N = 200000 + 7;
int n;
int b[N];
int a[N];
bool lib[N];

int nxt_up(int i)
{
  for (int j = i; j <= 2 * n - 1; j++)
  {
    if (lib[j] == 1)
    {
      lib[j] = 0;
      return j;
    }
  }
  assert(0);
}

int nxt_down(int i)
{
  for (int j = i; j >= 1; j--)
  {
    if (lib[j] == 1)
    {
      lib[j] = 0;
      return j;
    }
  }
  assert(0);
}

int main()
{
  if (home == 0)
  {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  }
  else
  {
    freopen ("input.txt", "r", stdin);
  }

  cin >> n;
  for (int i = 1; i <= 2 * n - 1; i++)
  {
    lib[i] = 1;
  }
  for (int i = 1; i <= n; i++)
  {
    cin >> b[i];
  }
  a[1] = nxt_up(b[1]);
  for (int i = 2; i <= n; i++)
  {
    if (i == 5)
    {
      ///break;
    }
    if (b[i] == b[i - 1])
    {
      a[2 * i - 2] = nxt_up(1);
      a[2 * i - 1] = nxt_down(2 * n - 1);
      ///cout << "a\n";
      continue;
    }
    if (b[i] < b[i - 1])
    {
      if (lib[b[i]])
      {
        a[2 * i - 2] = b[i];
        a[2 * i - 1] = nxt_up(1);
      }
      else
      {
        a[2 * i - 2] = nxt_up(1);
        a[2 * i - 1] = nxt_up(1);
      }
     /// cout << "b\n";
      continue;
    }
    if (b[i] > b[i - 1])
    {
      if (lib[b[i]])
      {
        a[2 * i - 2] = b[i];
        a[2 * i - 1] = nxt_down(2 * n - 1);
      }
      else
      {
        a[2 * i - 2] = nxt_down(2 * n - 1);
        a[2 * i - 1] = nxt_down(2 * n - 1);
      }
///cout << "c\n";
      continue;
    }
    assert(0);
  }
  for (int i = 1; i <= 2 * n - 1; i++)
  {
    cout << a[i] << " ";
  }
  cout << "\n";
  return 0;
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:47:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen ("input.txt", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Not a permutation
3 Incorrect 1 ms 340 KB Not a permutation
4 Incorrect 1 ms 332 KB Not a permutation
5 Incorrect 0 ms 212 KB Not a permutation
6 Correct 1 ms 340 KB Output is correct
7 Incorrect 1 ms 340 KB Not a permutation
8 Incorrect 0 ms 340 KB Not a permutation
9 Incorrect 0 ms 340 KB Not a permutation
10 Incorrect 1 ms 340 KB Not a permutation
11 Incorrect 1 ms 340 KB Not a permutation
12 Incorrect 1 ms 340 KB Not a permutation
13 Incorrect 1 ms 340 KB Not a permutation
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Not a permutation
2 Incorrect 5 ms 340 KB Not a permutation
3 Incorrect 21 ms 464 KB Not a permutation
4 Incorrect 68 ms 720 KB Not a permutation
5 Incorrect 263 ms 1224 KB Not a permutation
6 Execution timed out 1058 ms 2324 KB Time limit exceeded
7 Execution timed out 1077 ms 2180 KB Time limit exceeded