이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*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]);
assert(valid(n, gondolaSeq));
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));
sort(all(nxt));
while (!nxt.empty())
{
int pos = nxt.back().second;
nxt.pop_back();
int mn = n;
if (!nxt.empty())
mn = nxt.back().first;
for (int i = a[pos]; i > mn; i--)
ans.PB(pos);
}
reverse(all(ans));
for (int i = 0; i < ans.size(); i++)
replacementSeq[i] = (ans[i] + i) % n + 1;
return ans.size();
}
int countReplacement(int n, int inputSeq[])
{
return 0;
}
#ifdef death
int main()
{
int N, A[10002], B[10002];
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 6 15 9 1
*/
컴파일 시 표준 에러 (stderr) 메시지
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:92: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... |