This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx,avx2,sse2,sse3,ssse3,sse4,lzcnt,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define point pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define show(x) cerr << (#x) << " = " << x << '\n'
#define print(x) if (1) {cerr << (#x) << " = "; for (auto it : x) \
cerr << it << ' '; cerr << '\n';}
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0)
const int N = 1 << 19;
const int S = 1e7 + 64;
const int INF = 2e9 + 64;
const ll MAX = 2e18 + 64;
const int LOG = 21;
const int MOD = 1e9 + 7; //998244353;
const int P = 79;
using namespace std;
#include "gondola.h"
int f = -1;
int valid(int n, int a[]) {
unordered_set<int> st;
for (int i = 0; i < n; ++i)
st.insert(a[i]);
for (int i = 0; i < n; ++i) {
if (a[i] <= n) {
f = (n - a[i] % n + 1) % n;
break;
}
}
if (st.size() < n)
return 0;
if (f == -1)
return 1;
for (int i = 0; i < n; ++i)
if (a[i] <= n && a[i] != (i - f + n) % n + 1)
return 0;
return 1;
}
int replacement(int n, int a[], int res[]) {
if (!valid(n, a))
return 0;
if (f == -1)
f = 0;
vector<int> ans(N);
for (int i = 0; i < n; ++i)
if (a[i] > n)
ans[a[i]] = (i - f + n) % n + 1;
int len = 0;
for (int i = 0; i < N; ++i)
if (ans[i]) res[len] = ans[i], ++len;
return len;
}
int countReplacement(int n, int a[]) {
return 0;
}
Compilation message (stderr)
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:46:21: warning: comparison of integer expressions of different signedness: 'std::unordered_set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
46 | if (st.size() < n)
| ~~~~~~~~~~^~~
# | 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... |