이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "gondola.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
vector<int> Make(int n, int a[]) {
vector<int> b(n);
int ind = 0;
for (int i = 0; i < n; i++) {
if (a[i] <= n) ind = (i + n + 1 - a[i]) % n;
}
for (int i = ind; i < ind + n; i++) {
b[i % n] = i - ind + 1;
}
return b;
}
int valid(int n, int a[]) {
map<int, int> mp;
for (int i = 0; i < n; i++) {
if (mp[a[i]] == 1) return 0;
mp[a[i]]++;
}
vector<int> v = Make(n, a);
for (int i = 0; i < n; i++) {
if (a[i] <= n && a[i] != v[i]) return 0;
}
return 1;
}
int replacement(int n, int a[], int b[]) {
vector<int> v = Make(n, a);
vector<pair<int, int>> all;
for (int i = 0; i < n; i++) {
if (a[i] > n) all.push_back({a[i], v[i]});
}
sort(all.begin(), all.end());
vector<int> ans;
int prv = n + 1;
for (int i = 0; i < all.size(); i++) {
ans.push_back(all[i].second);
for (int j = prv; j < all[i].first; j++) ans.push_back(j);
prv = all[i].first + 1;
}
for (int i = 0; i < ans.size(); i++) b[i] = ans[i];
return ans.size();
}
int mod = 1e9 + 9;
int Mul(int a, int b) {
ll c = a; c *= b; c %= mod;
return c;
}
int Exp(int a, int b) {
int ans = 1;
while (b > 0) {
if (b & 1) ans = Mul(ans, a);
a = Mul(a, a);
b >>= 1;
}
return ans;
}
int countReplacement(int n, int a[]) {
if (!valid(n, a)) return 0;
vector<int> v;
v.push_back(n);
for (int i = 0; i < n; i++) {
if (a[i] > n) v.push_back(a[i]);
}
sort(v.begin(), v.end());
int ans = 1;
int x = v.size();
if (x == n + 1) ans = n;
for (int i = 1; i < x; i++) {
ans = Mul(ans, Exp(x - i, v[i] - v[i - 1] - 1));
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 0; i < all.size(); i++) {
| ~~^~~~~~~~~~~~
gondola.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < ans.size(); i++) b[i] = ans[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... |