이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
const int N = 1e5+5;
int T[N];
// int replacementSeq[N];
int valid(int n, int A[]){
map<int,int> mp;
int pos = -1;
for (int i = 0; i < n; i++){
if (mp[A[i]]++) return 0;
if (A[i] <= n){pos = i;break;}
}
if (pos == -1) return 1;
int x = A[pos];
for (int i = pos; i < n; i++){
if (i > pos and mp[A[i]]++) return 0;
if (A[i] <= n and A[i] != x) return 0;
x++;
if (x == n+1) x = 1;
}
return 1;
}
int replacement(int n, int A[], int replacementSeq[]){
int x = valid(n, A);
for (int i = 0; i < n; i++){
T[i] = i+1;
}
int pos = -1;
for (int i = 0; i < n; i++){
if (A[i] <= n){pos = i;break;}
}
if (pos != -1){
int x = A[pos];
for (int i = pos; i >= 0; i--){
T[i] = x;
x--;
if (!x) x = n;
}
x = A[pos];
for (int i = pos; i < n; i++){
T[i] = x;
x++;
if (x == n+1) x = 1;
}
}
int mx = 0, ind = 0;
map <int,int> idx;
for (int i = 0; i < n; i++){
idx[A[i]] = i+1;
if (mx < A[i]){
mx = A[i];
ind = i;
}
}
for (int i = n+1; i <= mx; i++){
if (idx[i]){
replacementSeq[i-n-1] = T[idx[i]-1];
}else{
replacementSeq[i-n-1] = T[ind];
T[ind] = i;
}
}
return mx-n;
}
int countReplacement(int n, int A[]){
int x = valid(n, A);
if (!x) return 0;
const int mod = 1e9+7;
map<int,int>idx;
int mx = 0, ans = 1, cnt = 0;
for (int i = 0; i < n; i++){
if (A[i] > n){
idx[A[i]] = 1;
cnt++;
}
mx = max(mx, A[i]);
}
int num = 0;
for (int i = n+1; i <= mx; i++){
if (!idx[i]){
ans = (ans*1ll*cnt)%mod;
num++;
// cnt++;
}else{
ans = (ans*1ll*num)%mod;
cnt--;
// cnt -= 2;
}
}
return ans;
}
// int main ()
// {
// ios::sync_with_stdio(false);
// cin.tie(0);
// int n;
// cin >> n;
// int A[n];
// for (int i = 0; i < n; i++) cin >> A[i];
// // int m = replacement(n, A, replacementSeq);
// // for (int i = 0; i < m; i++) cout << replacementSeq[i] << " ";
// cout << countReplacement(n, A);
// }
컴파일 시 표준 에러 (stderr) 메시지
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:34:6: warning: unused variable 'x' [-Wunused-variable]
34 | int x = valid(n, A);
| ^
# | 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... |