This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000009ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
#ifndef death
#include "gondola.h"
#endif
int valid(int n, int inputSeq[])
{
vector<int> a, b;
for (int i = 0; i < n; i++)
a.PB(inputSeq[i]);
b = a;
for (int i = 0; i < n; i++)
{
if (a[i] > n)
continue;
for (int j = 0; j < n; j++)
b[(a[i] - 1 + j) % n] = a[(i + j) % n];
break;
}
a = b;
map<int, int> used;
for (int i = 0; i < n; i++)
{
if ((a[i] <= n && i + 1 != a[i]) || used[a[i]])
return 0;
used[a[i]] = 1;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
vector<int> ans;
vector<pair<int, int>> nxt;
vector<int> a, b;
for (int i = 0; i < n; i++)
a.PB(gondolaSeq[i]);
b = a;
for (int i = 0; i < n; i++)
{
if (a[i] > n)
continue;
for (int j = 0; j < n; j++)
b[(a[i] - 1 + j) % n] = a[(i + j) % n];
break;
}
a = b;
for (int i = 0; i < n; i++)
if (a[i] > n)
nxt.PB(MP(a[i], i));
while (!nxt.empty())
{
int pos = nxt.back().second;
nxt.pop_back();
int mn = n;
if (!nxt.empty())
mn = max(nxt.back().first, mn);
for (int i = a[pos]; i > mn; i--)
ans.PB(pos + 1);
}
reverse(all(ans));
for (int i = 0; i < ans.size(); i++)
replacementSeq[i] = ans[i];
return ans.size();
}
int countReplacement(int n, int inputSeq[])
{
return 0;
}
#ifdef death
int main()
{
int N, A[102], B[102];
cin >> N;
for (int i = 0; i < N; i++)
cin >> A[i];
N = replacement(N, A, B);
cout << endl;
for (int i = 0; i < N; i++)
cout << B[i] << " ";
cout << endl;
return 0;
}
#endif
/*
7
5 6 7 1 2 3 4
7
5 6 7 1 2 10 4
5
2 8 9 10 1
*/
Compilation message (stderr)
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:91:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ans.size(); i++)
~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |