text
stringlengths 49
983k
|
|---|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100001;
int P[MAX];
int T[MAX];
int D[MAX];
int Curr[MAX];
int n;
int Sort(int low, int high) {
int i = low, j = high;
int p = P[(i + j) / 2];
do {
while (P[i] < p) i++;
while (P[j] > p) j--;
if (i <= j) {
swap(P[i], P[j]);
i++;
j--;
}
} while (i <= j);
if (i < high) Sort(i, high);
if (low < j) Sort(low, j);
return 0;
}
int main() {
int Max = 0;
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%d", &P[i]);
P[i]--;
T[i] = P[i];
Max = max(Max, T[i]);
}
memset(D, 0, sizeof(D));
for (int i = 0; i < n; i++) D[P[i]]++;
for (int i = 0; i < Max; i++) {
if (D[i] < D[i + 1]) {
cout << "-1" << endl;
return 0;
}
}
for (int i = 0; i < n; i++) Curr[i] = 1;
cout << D[0] << endl;
for (int i = 0; i < n; i++) {
printf("%d ", Curr[T[i]]);
Curr[T[i]]++;
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
void solve() {
long long n;
cin >> n;
vector<long long> a(n);
vector<vector<long long> > cnt(100001);
long long me = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]].push_back(i);
me = max(me, a[i]);
}
bool ok = 1;
for (long long i = me; i >= 2; i--) {
if (cnt[i].size() > cnt[i - 1].size()) {
ok = 0;
break;
}
}
if (!ok) {
cout << "-1\n";
return;
}
vector<long long> ans(n);
long long c = 0;
for (long long i = 1; i <= me; i++) {
long long k = 1;
for (auto x : cnt[i]) {
ans[x] = k;
k++;
c = max(c, k);
}
}
cout << c - 1 << "\n";
for (long long i = 0; i < n; i++) {
cout << ans[i] << " ";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long t;
t = 1;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a, b, i, n, maxi = 0, ani = 0;
cin >> n;
vector<int> vec(n);
map<int, int> mp;
for (i = 0; i < n; ++i) {
cin >> a;
ani = (a > ani ? a : ani);
mp[a]++;
maxi = (maxi > mp[a] ? maxi : mp[a]);
vec[i] = mp[a];
}
for (i = 2; i < ani + 1; ++i) {
if (mp[i] > mp[i - 1]) {
cout << -1;
return 0;
}
}
cout << maxi << "\n";
for (i = 0; i < n; ++i) {
cout << vec[i] << " ";
}
}
|
#include <bits/stdc++.h>
int a[100020];
int b[100020];
int c[100020];
int n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", a + i), i[a][c]++;
for (int i = 1; i < 100000; i++)
if (c[i + 1] > c[i]) return puts("-1"), 0;
printf("%d\n", c[1]);
for (int i = 0; i < n; i++) printf("%d ", ++i[a][b]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> a[100000 + 10];
long long b[100000 + 10];
long long c[100000 + 10];
int main() {
ios_base::sync_with_stdio(false);
long long n;
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> a[i].first;
a[i].second = i;
}
a[n + 1].first = 0;
sort(a + 1, a + n + 1);
long long minn = 10000000;
for (long long i = 1; i <= n; i++) {
c[a[i].first]++;
}
for (long long i = 2; i <= 100000; i++)
if (c[i] > c[i - 1]) {
cout << -1;
return 0;
}
long long cc = 2;
b[a[1].second] = 1;
cout << c[1] << endl;
for (long long i = 2; i <= n; i++) {
if (a[i].first != a[i - 1].first) cc = 1;
b[a[i].second] = cc;
cc++;
}
for (long long i = 1; i <= n; i++) cout << b[i] << " ";
}
|
#include <bits/stdc++.h>
using namespace std;
struct node {
int val;
int flag;
int p;
int label;
} arr[100005];
int n;
int cmp1(const node &a, const node &b) { return a.val > b.val; }
int cmp2(const node &a, const node &b) { return a.p < b.p; }
int main() {
int i, ans, total, flag, num1, cur;
while (scanf("%d", &n) != EOF) {
num1 = 0;
for (i = 1; i <= n; i++) {
scanf("%d", &arr[i].val);
if (arr[i].val == 1) num1++;
arr[i].flag = 1;
arr[i].p = i;
arr[i].label = 0;
}
sort(arr + 1, arr + 1 + n, cmp1);
total = 0;
flag = 1;
for (ans = 1; ans <= num1; ans++) {
cur = -1;
for (i = 1; i <= n; i++) {
if (arr[i].flag) {
cur = arr[i].val;
arr[i].flag = 0;
arr[i].label = ans;
total++;
break;
}
}
cur--;
for (; i <= n && cur >= 1; i++) {
if (arr[i].flag && arr[i].val == cur) {
arr[i].flag = 0;
arr[i].label = ans;
total++;
cur--;
}
}
if (cur > 0) {
flag = 0;
break;
}
}
if (total < n) flag = 0;
if (!flag)
cout << "-1" << endl;
else {
sort(arr + 1, arr + 1 + n, cmp2);
cout << num1 << endl;
for (i = 1; i <= n; i++) {
if (i != 1)
cout << " " << arr[i].label;
else
cout << arr[i].label;
}
cout << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct xx {
int id, num;
} a[100005];
int cmp(xx a, xx b) {
if (a.num != b.num) return a.num > b.num;
return a.id < b.id;
}
int n, b[100005];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &b[i]), a[b[i]].num++, a[b[i]].id = b[i];
sort(a + 1, a + 1 + 100001, cmp);
for (int i = 1; a[i].id; i++)
if (a[i].id != i) {
printf("-1\n");
return 0;
}
printf("%d\n", a[1].num);
for (int i = 1; i < n; i++) printf("%d ", a[b[i]].num), a[b[i]].num--;
printf("%d\n", a[b[n]].num);
return 0;
}
|
#include <bits/stdc++.h>
int counts[100000];
std::vector<int> nums;
int main() {
int N;
std::cin >> N;
for (int i = 0; i < N; i++) {
int num;
std::cin >> num;
num--;
counts[num]++;
nums.push_back(counts[num]);
}
for (int i = 1; i < 100000; i++) {
if (counts[i - 1] < counts[i]) {
std::cout << -1 << std::endl;
return 0;
}
}
std::cout << counts[0] << std::endl;
for (int i = 0; i < nums.size(); i++) {
if (i > 0) {
std::cout << " ";
}
std::cout << nums[i];
}
std::cout << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
void calc(vector<int>& v, vector<int>& xs) {
vector<int> tab[N];
int id = 1;
int maxval = *max_element(v.begin(), v.end());
for (int i = maxval; i > 0; i--) {
if (xs[i] == 0) continue;
int n = xs[i];
for (int j = i; j > 0; j--) {
if (xs[j] < n) {
puts("-1");
return;
}
for (int k = 0; k < n; k++) tab[j].push_back(id + k);
xs[j] -= n;
}
id += n;
}
printf("%d\n", id - 1);
for (int i = 0; i < (int)(v.size()); i++) {
assert(!tab[v[i]].empty());
if (i > 0) putchar(' ');
printf("%d", tab[v[i]].back());
tab[v[i]].pop_back();
}
puts("");
}
int main() {
int n;
scanf("%d", &n);
vector<int> v(n), xs(N);
for (int i = 0; i < (int)(n); i++) {
scanf("%d", &v[i]);
xs[v[i]]++;
}
calc(v, xs);
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 20;
int a[N], b[N], ans[N];
int main() {
int n, mx = 0, mxx = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
mxx = max(mxx, x);
ans[i] = b[x] + 1;
b[x]++;
mx = max(mx, b[x]);
}
for (int i = 2; i < N; i++)
if (b[i] > b[i - 1]) return cout << -1, 0;
cout << mx << endl;
for (int i = 0; i < n; i++) {
cout << ans[i] << " ";
}
}
|
#include <bits/stdc++.h>
int num[100002];
int main() {
int max = 0, i, j, n, t;
int a[100002];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
num[a[i]]++;
if (a[i] > max) max = a[i];
}
t = 1;
for (i = max; i > 1; i--)
if (num[i] > num[i - 1]) {
t = 0;
break;
}
if (t) {
printf("%d\n", num[1]);
for (i = 0; i < n; i++) printf("%d ", num[a[i]]--);
} else
printf("-1");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 17;
int N;
pair<int, int> elems[MAXN];
int cnt[MAXN];
int ans[MAXN];
int main() {
scanf("%d", &N);
for (int i = 0; i < (int)(N); ++i) {
int x;
scanf("%d", &x);
elems[i] = make_pair(x, i);
cnt[x]++;
}
for (int i = 2; i < MAXN; i++)
if (cnt[i] > cnt[i - 1]) {
printf("-1\n");
return 0;
}
sort(elems, elems + N);
for (int i = 0, j; i < N; i = j) {
int lvl = 0;
for (j = i; j < N && elems[j].first == elems[i].first; j++)
ans[elems[j].second] = ++lvl;
}
printf("%d\n", *max_element(ans, ans + N));
for (int i = 0; i < (int)(N); ++i) printf("%d ", ans[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> count(100001, 0);
vector<vector<int> > pos(100001);
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
++count[x];
pos[x].push_back(i);
}
int ans = count[1];
vector<int> color(n);
while (true) {
int i = 1;
while (count[i] > 0) {
color[pos[i].back()] = count[i];
pos[i].pop_back();
--count[i];
++i;
}
if (i == 1) break;
}
for (vector<int>::iterator(i) = (count).begin(); (i) < (count).end(); ++(i))
if (*i != 0) {
cout << -1;
return 0;
}
cout << ans << endl;
for (vector<int>::iterator(i) = (color).begin(); (i) < (color).end(); ++(i))
cout << *i << ' ';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, elem, cur_total = 0;
vector<int> shuffle, input, fin;
shuffle.assign((int)1e5 + 1, 0);
fin.assign((int)1e5 + 1, 1);
scanf("%d", &n);
input.assign(n, 0);
for (int i = 0; i < n; ++i) {
scanf("%d", &input[i]);
++shuffle[input[i]];
}
for (int i = 1; i < shuffle.size() - 1; ++i) {
if (shuffle[i] < shuffle[i + 1]) {
printf("-1");
return 0;
}
}
printf("%d\n", shuffle[1]);
for (int i = 0; i < input.size(); ++i) {
printf("%d ", fin[input[i]]);
++fin[input[i]];
}
return 0;
}
|
#include <bits/stdc++.h>
const int mx = 1e6 + 5;
const int inf = 0x3f3f3f3f;
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, c = inf, prev = 0;
scanf("%d", &n);
map<int, vector<int>> mp;
vector<int> v(n), ans(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &v[i]);
mp[v[i]].push_back(i);
}
for (auto e : mp) {
if (c < e.second.size() || e.first - prev != 1) {
puts("-1");
return 0;
}
for (int i = 1; i <= e.second.size(); ++i) {
ans[e.second[i - 1]] = i;
}
c = e.second.size();
prev = e.first;
}
printf("%d\n", int(mp[1].size()));
for (int i = 0; i < n; ++i) printf("%d%c", ans[i], " \n"[i == n - 1]);
return 0;
}
|
#include <bits/stdc++.h>
int n, i, j, k, a[100005], num[100005], pos[100005], mx;
int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
for (i = 0; i < n; i++) {
num[a[i]]++;
pos[i] = num[a[i]];
if (mx < a[i]) mx = a[i];
}
for (i = 1; i < mx; i++) {
if (num[i] < num[i + 1]) {
printf("-1");
return 0;
}
}
printf("%d\n", num[1]);
for (i = 0; i < n; i++) printf("%d ", pos[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void loadData(void);
void proc(void);
void printRes(void);
int max_a;
int n;
int a[100000];
int num[100001];
int num_index[100001];
bool ok(void);
bool lyb_debug = false;
int main(int argc, char** argv) {
loadData();
proc();
return 0;
}
bool ok(void) {
if (lyb_debug) {
for (int i = 1; i <= max_a; i++) printf("%d: num %d\n", i, num[i]);
}
for (int i = 2; i <= max_a; i++)
if (num[i] > num[i - 1]) return false;
return true;
}
void proc(void) {
if (ok()) {
printf("%d\n", num[1]);
for (int i = 0; i < n; i++)
printf("%d%c", ++num_index[a[i]], i == n - 1 ? '\n' : ' ');
} else
printf("-1\n");
return;
}
void loadData(void) {
memset(num, 0, sizeof(num));
memset(num_index, 0, sizeof(num_index));
scanf("%d", &n);
max_a = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
num[a[i]]++;
max_a = max(max_a, a[i]);
}
return;
}
void printRes(void) { return; }
|
#include <bits/stdc++.h>
using namespace std;
vector<long long> dp(1000001, 0LL);
long long n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
long long arr[n + 1];
for (long long i = 1; i <= n; i++) {
cin >> arr[i];
dp[arr[i]]++;
}
for (long long i = 1; i < 1000001 - 1; i++) {
if (dp[i] < dp[i + 1]) {
cout << -1 << endl;
return 0;
}
}
cout << (*max_element(dp.begin(), dp.end())) << endl;
for (long long i = 1; i <= n; i++) {
cout << dp[arr[i]] << " ";
dp[arr[i]]--;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, num[100001], x[100001];
int max_num = 0;
vector<int> pos[100001];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i];
num[x[i]]++;
max_num = max(max_num, x[i]);
pos[x[i]].push_back(i);
}
int cur = 0;
while (num[1] != 0) {
int i = 1;
while (num[i] > 0) i++;
i--;
for (int j = 1; j <= i; j++) num[j]--;
cur++;
for (int j = 1; j <= i; j++) {
x[pos[j][0]] = cur;
pos[j].erase(pos[j].begin());
}
}
for (int i = 2; i <= max_num; i++) {
if (num[i]) {
cout << -1 << endl;
return 0;
}
}
cout << cur << endl;
for (int i = 0; i < n; i++) {
cout << x[i] << " ";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int inf = (int)1e9;
const long long int infll = (long long int)1e18;
const double inf1 = 1e-9;
const int ss = (int)1e6 + 3;
const int base = inf;
bool pred(const pair<int, int>& i, const pair<int, int>& j) {
if (i.first == j.first)
return i.second > j.second;
else
return i.first > j.first;
}
bool pred2(const int& i, const int& j) { return i > j; }
int main() {
int n;
scanf("%d", &n);
vector<int> a(n);
int k = 100001;
vector<vector<int> > b(k);
int mx = -1;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
b[a[i]].push_back(i);
mx = max(a[i], mx);
}
if (mx == 1) {
cout << b[1].size() << endl;
for (int i = 0; i < n; ++i) cout << i + 1 << " ";
return 0;
}
bool t = true;
for (int j = 2; j <= mx; ++j) {
if (b[j].size() > b[j - 1].size()) {
t = false;
break;
}
}
if (!t) {
cout << "-1";
return 0;
}
cout << b[1].size() << endl;
vector<int> c(n);
for (int i = 1; i <= mx; ++i) {
for (int j = 0; j < b[i].size(); ++j) c[b[i][j]] = j + 1;
}
for (int i = 0; i < n; ++i) cout << c[i] << " ";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int res[100001];
int main() {
int n, a[100001];
set<int> s;
set<int>::const_iterator it;
vector<int> v[100001];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s.insert(a[i]);
}
for (int i = 1; i <= n; i++) {
if (a[i] > 100000) {
cout << -1;
return 0;
}
}
it = s.end();
it--;
int mx = *it;
for (int i = 1; i <= n; i++) {
v[a[i]].push_back(i);
}
for (int i = 1; i < mx; i++) {
if (v[i + 1].size() > v[i].size()) {
cout << -1;
return 0;
}
}
for (int i = 1; i <= mx; i++) {
for (int j = 0; j < v[i].size(); j++) {
res[v[i][j]] = j + 1;
}
}
cout << v[1].size() << endl;
for (int i = 1; i <= n; i++) cout << res[i] << " ";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int i, j, k, n, m;
pair<int, int> p[N];
int a[N];
int c[N];
int main() {
cin >> n;
for (i = 0; i < n; ++i) {
cin >> p[i].first;
p[i].second = i;
}
sort(p, p + n);
k = 0;
for (i = 0; i < n; ++i) {
c[p[i].first]++;
k = max(k, p[i].first);
}
for (i = 1; i <= k; ++i)
if (c[i] == 0 || (i > 1 && c[i] > c[i - 1])) {
cout << -1 << endl;
return 0;
}
m = 0;
k = 0;
for (i = 0; i < n; ++i) {
if (!i || p[i].first != p[i - 1].first) {
k = 0;
}
++k;
m = max(m, k);
a[p[i].second] = k;
}
cout << m << endl;
for (i = 0; i < n; ++i) {
cout << a[i] << ' ';
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
long n, j, pnum;
bool good = 1;
scanf("%ld", &n);
std::vector<long> v(n), num(100001, 0);
for (long i = 0; i < n; i++) {
scanf("%ld", &v[i]);
num[v[i]]++;
}
pnum = num[1];
for (j = 2; j < 100001 && num[j] != 0; j++) {
if (num[j - 1] < num[j]) {
good = 0;
break;
}
if (num[j - 1] > pnum) pnum = num[j - 1];
}
for (long i = j + 1; i < 100001; i++)
if (num[i] > 0) {
good = 0;
break;
}
if (good) {
std::vector<long> p(j, 1);
printf("%ld\n", pnum);
for (long i = 0; i < n; i++) {
printf("%ld ", p[v[i]]);
p[v[i]]++;
}
} else
printf("-1");
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, mx = 0;
cin >> n;
vector<int> v(n);
vector<pair<int, int> > b;
for (int i = 0; i < n; i++) {
cin >> v[i];
b.emplace_back(v[i], i);
mx = max(mx, v[i]);
}
sort(v.begin(), v.end());
sort(b.begin(), b.end());
int i = 0;
unordered_map<int, int> occ;
while (i < n) {
auto it = equal_range(v.begin(), v.end(), v[i]);
occ[v[i]] = it.second - it.first;
i = it.second - v.begin();
}
for (int i = mx; i > 1; i--) {
if (occ.find(i) == occ.end() || occ.find(i - 1) == occ.end() ||
occ[i] > occ[i - 1]) {
cout << -1 << "\n";
return 0;
}
}
i = 0;
while (i < n) {
for (int j = 1; j <= occ[b[i].first]; j++) {
v[b[i].second] = j;
i++;
}
}
cout << occ[1] << "\n";
for (auto i : v) cout << i << " ";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> a[100001];
int res[100001];
int main() {
int n, x, k = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == 1) k++;
a[x].push_back(i);
}
for (int i = 100000; i > 0; i--) {
int y = a[i].size();
if (a[i].size() < a[i + 1].size()) {
cout << -1;
return 0;
}
for (int j = 0; j < a[i].size(); j++) {
res[a[i][j]] = y;
y--;
}
}
cout << k << '\n';
for (int i = 0; i < n; i++) {
cout << res[i] << ' ';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
int an[MAX];
int cc[MAX];
int num[MAX];
int ans[MAX];
int main() {
int n;
scanf("%d", &n);
int mm = INT_MIN;
for (int i = 1; i <= n; ++i) {
scanf("%d", &an[i]);
cc[an[i]]++;
mm = std::max(mm, an[i]);
}
bool ok = 1;
int ss;
int cur;
for (int i = 1; i <= mm; i++) {
if (cc[i] < cc[i + 1]) {
ok = 0;
break;
} else {
if (i == 1) {
ss = cc[i], cur = ss;
num[i] = ss - cur + 1;
} else {
cur = cur - (cc[i - 1] - cc[i]);
num[i] = ss - cur + 1;
}
}
}
if (ok) {
printf("%d\n", ss);
for (int i = 1; i <= n; ++i) {
ans[i] = num[an[i]]++;
printf("%d ", ans[i]);
}
printf("\n");
} else
printf("%d\n", -1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> p[111111];
int x, a[111111], i, j, n, it, cur, b[111111];
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &x);
p[x].push_back(i);
++a[x];
}
it = 0;
cur = 0;
while (a[1]) {
i = 1;
++cur;
while (a[i]) {
b[p[i][it]] = cur;
--a[i];
++i;
}
++it;
}
for (i = 1; i <= 100000; i++)
if (a[i]) {
puts("-1");
return 0;
}
printf("%d\n", cur);
for (i = 1; i < n; i++) printf("%d ", b[i]);
printf("%d\n", b[n]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
int cnt[N];
int ans[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int x;
cin >> x;
int y[x];
for (int i = 0; i < x; i++) {
cin >> y[i];
cnt[y[i]]++;
}
for (int i = 2; i <= N - 9; i++) {
if (cnt[i - 1] < cnt[i]) {
cout << -1 << '\n';
return 0;
}
}
cout << cnt[1] << '\n';
for (int i = 0; i < x; i++) {
cout << ans[y[i]] + 1 << " ";
ans[y[i]]++;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100020], n, maxn, b[100020];
bool check;
int main(void) {
int c[100020];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> c[i];
a[c[i]]++;
maxn = maxn > c[i] ? maxn : c[i];
}
for (int i = maxn; i > 1; i--) {
if (a[i] > a[i - 1]) check = true;
}
if (check)
cout << "-1" << endl;
else {
cout << a[1] << endl;
for (int i = 0; i < n; i++) cout << ++b[c[i]] << " ";
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int maxi, i, a[100005], b[100002], g[100002], u, n, maxi1;
int main() {
cin >> n;
maxi1 = 0;
for (i = 1; i <= n; i++) {
cin >> a[i];
maxi1 = max(maxi1, a[i]);
}
for (i = 1; i <= n; i++) {
b[a[i]]++;
maxi = max(maxi, b[a[i]]);
g[i] = b[a[i]];
}
for (i = maxi1; i > 1; i--)
if (b[i] > b[i - 1]) {
u = 9;
break;
}
if (u == 9)
cout << "-1";
else {
cout << maxi << endl;
for (i = 1; i <= n; i++) cout << g[i] << " ";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ar[n + 1];
map<int, int> a;
int m = 0;
for (int i = 0; i < n; i++) {
cin >> ar[i];
a[ar[i]]++;
m = max(m, ar[i]);
}
for (int i = 2; i <= m; i++)
if (a[i] > a[i - 1]) {
cout << -1;
return 0;
}
int col = a[1];
cout << col << endl;
for (int i = 0; i < n; i++) {
cout << a[ar[i]] << ' ';
a[ar[i]]--;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int inp[100010];
int cnt[100010];
int cur[100010];
int main() {
int n, i, j, res = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", inp + i);
cnt[inp[i]]++;
}
for (i = 2; i <= 100000; i++) {
if (cnt[i] > cnt[i - 1]) {
printf("-1");
return 0;
}
res += cnt[i - 1] - cnt[i];
}
printf("%d\n", res);
for (i = 0; i < n; i++) {
printf("%d ", cur[inp[i]] + 1);
cur[inp[i]]++;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int const maxn = 100000 + 5;
int a[maxn];
int cnt[maxn];
int flag[maxn];
int n, N;
bool check() {
if (cnt[1] == 0) return 0;
for (int i = 1; i < N; i++) {
if (cnt[i + 1] > cnt[i]) return 0;
}
return 1;
}
int main(int argc, char** argv) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
cnt[a[i]]++;
N = max(N, a[i]);
}
if (check()) {
int part = 0;
for (int i = 1; i <= n; i++) {
++flag[a[i]];
part = max(part, flag[a[i]]);
}
printf("%d\n", part);
memset(flag, 0, sizeof(flag));
for (int i = 1; i <= n; i++)
printf("%d%c", ++flag[a[i]], i == n ? '\n' : ' ');
} else {
printf("%d\n", -1);
}
return 0;
}
|
#include <bits/stdc++.h>
long a[200005] = {0};
long hash[200005] = {0};
long st[200005] = {0};
int main() {
long n, i;
scanf("%ld", &n);
for (i = 1; i <= n; i++) {
scanf("%ld", &a[i]);
hash[a[i]]++;
}
for (i = 2; i <= 100000; i++) {
if (hash[i] > hash[i - 1]) {
printf("-1");
return 0;
}
}
printf("%ld\n", hash[1]);
for (i = 1; i <= n; i++) {
printf("%ld ", ++st[a[i]]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return a >= b ? a : b; }
void solve() {
long long n;
cin >> n;
vector<long long> a(n);
map<long long, long long> make_pair;
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 0; i < n; i++) make_pair[a[i]]++;
vector<long long> v;
for (auto x : make_pair) v.push_back(x.second);
for (long long i = 1; i < v.size(); i++) {
if (v[i] - v[i - 1] > 0) {
cout << -1;
return;
}
}
vector<long long> b;
for (auto x : make_pair) b.push_back(x.first);
long long c = 0;
for (long long i = 1; i < b.size(); i++)
if (b[i] - b[i - 1] == 1) c++;
if (c != make_pair.size() - 1 || make_pair[1] == 0)
cout << -1;
else {
cout << make_pair[1] << '\n';
for (long long i = 0; i < n; i++) {
cout << make_pair[a[i]] << " ";
make_pair[a[i]]--;
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t = 1;
while (t--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 1e3;
int arr[Maxn];
int num[Maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
num[--arr[i]]++;
}
for (int i = 1; i < Maxn; i++) {
if (num[i] > num[i - 1]) {
cout << -1 << endl;
return 0;
}
}
cout << num[0] << endl;
for (int i = 0; i < n; i++) {
cout << num[arr[i]] << ' ';
num[arr[i]]--;
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100005], c[100005];
int main() {
int i, j, n;
bool can = true;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
c[a[i]]++;
}
for (int i = 0; i < 100005 - 3; i++) {
if (c[i + 1] < c[i + 2]) can = false;
}
if (can) {
cout << c[1] << endl;
for (int i = 0; i < n; i++) {
cout << c[a[i]] << " ";
c[a[i]]--;
}
} else
cout << "-1" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int cnt[100010];
int res[100001];
int main(void) {
memset(cnt, -1, sizeof cnt);
int n, mx = 0;
scanf("%d", &n);
for (register int i = (0); i < (int)n; ++i) {
int x;
scanf("%d", &x);
if (cnt[x] < 0) cnt[x] = 0;
cnt[x]++;
res[i] = cnt[x];
mx = max(x, mx);
}
cnt[0] = 1000000;
for (register int i = (1); i < (int)mx + 1; ++i)
if (cnt[i] > cnt[i - 1] || cnt[i] == -1) {
cout << -1 << endl;
return 0;
}
cout << cnt[1] << endl;
if (cnt[1] != -1)
for (register int i = (0); i < (int)n; ++i) {
if (i) cout << " ";
cout << res[i];
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct edge {
int a, b, fff, pos;
} e[100009];
int flag[100009];
bool cmp1(edge e1, edge e2) { return e1.a < e2.a; }
bool cmp2(edge e1, edge e2) { return e1.pos < e2.pos; }
int main() {
int n;
while (scanf("%d", &n) != EOF) {
int i, j, k, l = 1, max = -1;
for (i = 0; i < n; i++) {
scanf("%d", &e[i].a);
if (e[i].a > max) max = e[i].a;
flag[e[i].a]++;
}
for (i = 0; i < n; i++) e[i].fff = 0, e[i].pos = i;
sort(e, e + n, cmp1);
int temp = flag[1];
int ff = 0;
for (i = 0; i < n; i++) {
if (e[i].a == 1 && e[i].fff == 0) {
int t = 1;
for (j = i; j < n; j++) {
if (e[j].a == t && e[j].fff == 0) {
e[j].fff = 1;
e[j].b = l;
t++;
}
}
l++;
} else
break;
}
sort(e, e + n, cmp2);
for (i = 0; i < n; i++)
if (e[i].fff == 0) break;
if (i != n)
printf("-1\n");
else {
printf("%d\n", temp);
for (i = 0; i < n - 1; i++) printf("%d ", e[i].b);
printf("%d\n", e[i].b);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
std::vector<long long> A(n);
long long mx = 0;
map<long long, long long> make_pair;
std::vector<std::vector<long long>> pos(100002);
for (long long i = 0; i < n; i++) {
cin >> A[i];
if (mx < A[i]) {
mx = A[i];
}
pos[A[i]].push_back(i);
make_pair[A[i]]++;
}
for (long long i = mx; i >= 2; i--) {
if (make_pair[i] > make_pair[i - 1]) {
cout << -1 << endl;
return;
}
}
cout << make_pair[1] << endl;
long long sz;
std::vector<long long> res(n);
long long num;
for (long long i = 1; i <= mx; i++) {
sz = pos[i].size();
num = 1;
for (long long j = 0; j < sz; j++) {
res[pos[i][j]] = num;
num++;
}
}
for (long long a : res) {
cout << a << " ";
}
cout << endl;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
solve();
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
inline int read() {
int x = 0;
char c = getchar();
bool k = false;
for (; !isdigit(c); c = getchar()) k |= c == '-';
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + c - '0';
if (k) x = -x;
return x;
}
void write(int x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
const int maxn = 1e5 + 10;
int n, a[maxn];
vector<int> V[maxn];
int pos = 0, ans[maxn];
signed main() {
n = read();
for (int i = 1; i <= n; i++) {
a[i] = read();
V[a[i]].push_back(i);
if (a[i] > n) {
puts("-1");
return 0;
}
}
while (!V[1].empty()) {
pos++;
int j = 1;
while (!V[j].empty()) {
int k = V[j].back();
V[j].pop_back();
ans[k] = pos;
j++;
}
}
for (int i = 1; i <= n; i++)
if (!V[i].empty()) {
puts("-1");
return 0;
}
printf("%d\n", pos);
for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
|
#include <bits/stdc++.h>
using namespace std;
string lower(string s) {
for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);
return s;
}
vector<string> sep(string s, char c) {
string temp;
vector<string> res;
for (int i = 0; i < s.size(); i++) {
if (s[i] == c) {
if (temp != "") res.push_back(temp);
temp = "";
continue;
}
temp = temp + s[i];
}
if (temp != "") res.push_back(temp);
return res;
}
template <class T>
T toint(string s) {
stringstream ss(s);
T ret;
ss >> ret;
return ret;
}
template <class T>
string tostr(T inp) {
string ret;
stringstream ss;
ss << inp;
ss >> ret;
return ret;
}
template <class T>
void D(T A[], int n) {
for (int i = 0; i < n; i++) cout << A[i] << " ";
cout << endl;
}
template <class T>
void D(vector<T> A, int n = -1) {
if (n == -1) n = A.size();
for (int i = 0; i < n; i++) cout << A[i] << " ";
cout << endl;
}
int A[100001];
int cnt[100001];
int main() {
int n;
memset(cnt, 0, sizeof(cnt));
scanf("%d", &n);
for (int(i) = (0); (i) < (n); (i)++) {
scanf("%d", &A[i]);
cnt[A[i]]++;
}
bool ap = 1;
for (int(i) = (100000); (i) >= (2); (i)--) {
if (cnt[i] > cnt[i - 1]) ap = 0;
}
if (!ap)
printf("-1\n");
else {
printf("%d\n", cnt[1]);
memset(cnt, 0, sizeof(cnt));
printf("%d", 1);
cnt[A[0]] = 1;
for (int(i) = (1); (i) < (n); (i)++) {
printf(" %d", ++cnt[A[i]]);
}
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool umax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
vector<int> adj[100009];
int ans[100009], cnt[100009];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
adj[x].push_back(i);
cnt[x]++;
}
int res = 0;
while (cnt[1]) {
res++;
for (int i = 1; i < 100009; i++) {
if (!cnt[i]) break;
ans[adj[i].back()] = res;
adj[i].pop_back();
cnt[i]--;
}
}
if (*max_element(cnt + 1, cnt + 100009) == 0) {
printf("%d\n", res);
for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
puts("");
} else
puts("-1");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
void inline checkMax(T& a, T b) {
if (a < b) a = b;
};
int arr[123456], cnt[123456];
int main() {
int n;
while (scanf("%d", &n) == 1) {
memset(cnt, 0, (sizeof cnt));
int mm = 0;
for (int n_ = (n), i = 0; i < n_; ++i) {
scanf("%d", arr + i);
cnt[arr[i]]++;
checkMax(mm, arr[i]);
}
bool ok = true;
for (int i = 1; i < mm; ++i) {
if (cnt[i] < cnt[i + 1]) {
ok = false;
break;
}
}
if (!ok) {
puts("-1");
} else {
printf("%d\n", cnt[1]);
for (int n_ = (n), i = 0; i < n_; ++i) {
if (i) putchar(' ');
printf("%d", cnt[arr[i]]--);
}
puts("");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long c[100005], ans;
long long solve() {
long long n;
cin >> n;
vector<long long> v;
for (long long i = 0; i < n; ++i) {
long long a;
cin >> a;
c[a]++;
ans = max(ans, c[a]);
v.push_back(c[a]);
}
for (long long i = 1; i < 100000; ++i) {
if (c[i] < c[i + 1]) {
cout << -1;
return 0;
}
}
cout << ans << "\n";
for (long long i = 0; i < n; ++i) {
cout << v[i] << " ";
}
return 0;
}
signed main() {
ios::sync_with_stdio(0);
long long t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> a[120000];
int n, v[120000];
int main() {
int i, j = 0, k;
scanf("%d", &n);
for (i = 0; i < n; i++) {
int k;
scanf("%d", &k);
a[k].push_back(i);
j = max(j, k);
}
for (i = 2; i <= j; i++) {
if (a[i].size() > a[i - 1].size()) {
puts("-1");
return 0;
}
}
int t = a[1].size();
for (k = 1; k <= t; k++) {
for (i = 1; i <= j; i++) {
if (a[i].empty()) break;
int y = *a[i].begin();
v[y] = k;
a[i].erase(a[i].begin());
}
}
printf("%d\n", t);
for (i = 0; i < n; i++) printf("%d\n", v[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[101000];
int main() {
int n, i, count, el;
cin >> n;
map<int, int> map;
for (i = 0; i < n; i++) {
cin >> a[i];
map[a[i]]++;
}
count = map[1];
if (count == 0)
count = -1;
else
el = map[1];
for (i = 2; map[i] && count > 0; i++) {
if (map[i] > map[i - 1]) {
count = -1;
break;
} else
el += map[i];
map[i - 1] = 0;
}
map[i - 1] = 0;
if (el != n) count = -1;
cout << count << "\n";
if (count > 0) {
cout << ++map[a[0]];
for (i = 1; i < n; i++) cout << " " << ++map[a[i]];
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long int n, i, a, ma = 0;
map<long long int, long long int> m;
vector<long long int> v;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a;
v.push_back(a);
m[a]++;
ma = max(ma, a);
}
for (i = 1; i < ma; i++) {
if (m[i] < m[i + 1]) {
cout << -1;
return 0;
}
}
cout << m[1] << endl;
for (i = 0; i < n; i++) cout << m[v[i]]-- << " ";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int num[100010], cnt[100010], tmt[100010];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", num + i);
for (int i = 0; i < n; i++) cnt[num[i]]++;
for (int i = 2; i < 100010; i++)
if (cnt[i] > cnt[i - 1]) {
puts("-1");
return 0;
}
printf("%d\n", cnt[1]);
for (int i = 0; i < n; i++)
printf("%d%c", ++tmt[num[i]], i == n - 1 ? '\n' : ' ');
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long a;
cin >> a;
map<long long, long long> m2;
vector<long long> v(a), v1, v2;
long long h1 = -1000000000000000000, county = 0;
for (long long i = 0; i < a; i++) {
cin >> v[i];
m2[v[i]]++;
if (v[i] == 1) county++;
h1 = max(h1, v[i]);
}
map<long long, long long> m;
long long flag = 0;
v2 = v;
sort((v2).begin(), (v2).end());
for (long long i = 1; i < h1; i++) {
if (m2[i] < m2[i + 1]) {
flag = 1;
break;
}
}
for (long long i = 0; i < a; i++) {
m[v[i]]++;
v1.push_back(m[v[i]]);
}
if (flag == 0) {
cout << county << '\n';
for (auto i : v1) cout << i << " ";
} else
cout << -1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void c_p_c() {}
const long long M = 1e9 + 7;
long long mod(long long x) { return ((x % M + M) % M); }
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }
bool f(long long x, long long y) { return x > y; }
bool decToOctal(long long n) {
long long octalNum[100];
long long i = 0;
while (n != 0) {
octalNum[i] = n % 8;
n = n / 8;
i++;
}
string s;
for (long long j = i - 1; j >= 0; j--) {
s += (to_string(octalNum[j]));
}
if (s.find('7') != string::npos)
return true;
else
return false;
}
long long ans(long long x) {
long long mini = INT_MAX;
long long maxi = INT_MIN;
while (x) {
long long r = x % 10;
x /= 10;
mini = min(mini, r);
maxi = max(maxi, r);
}
return mini * maxi;
}
long long b[100005];
long long a[100005];
void solve() {
long long n;
cin >> n;
long long i;
map<long long, long long> ma;
for (i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
}
for (i = 2; i < 100005; i++) {
if (b[i] > b[i - 1]) {
cout << "-1\n";
return;
}
}
cout << b[1] << endl;
for (i = 0; i < n; i++) cout << (b[a[i]]--) << " ";
}
int32_t main() {
c_p_c();
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int nums[100005];
int numes[1000005];
int count[100005];
for (int i = 0; i < 100005; ++i) {
nums[i] = 0;
numes[i] = 0;
count[i] = 0;
}
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
++numes[k - 1];
count[i] = numes[k - 1];
}
for (int i = 0; i < 100004; ++i) {
if (numes[i + 1] > numes[i]) {
cout << "-1" << endl;
return 0;
}
}
cout << numes[0] << endl;
for (int i = 0; i < n; ++i) cout << count[i] << ' ';
cout << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
map<int, vector<int>> m;
int result[100001];
int a[100001];
int need[100001];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int k;
cin >> k;
a[i] = k;
if (m.count(k) == 0) m[k] = vector<int>();
m[k].push_back(i);
}
auto it1 = m.begin();
if (it1->first != 1) {
cout << -1;
return 0;
}
it1++;
for (auto it = m.begin(); it != m.end(); it++, it1++) {
if (it1 != m.end()) {
if (it1->first != it->first + 1) {
cout << -1;
return 0;
}
if (it1->second.size() > it->second.size()) {
cout << -1;
return 0;
}
} else
break;
}
cout << m.begin()->second.size() << endl;
for (int i = 1; i <= n; i++) need[i] = 1;
for (int i = 0; i < n; i++) {
cout << need[a[i]]++ << " ";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
queue<int> q[100005];
int num[100005];
int n, a[100005], maxx = -1, k = 0;
bool anss = true;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
maxx = max(maxx, a[i]);
num[a[i]]++;
}
for (int i = maxx; i > 0; --i) {
while (num[i]) {
if (!num[i]) continue;
k++;
for (int j = 1; j <= i; ++j) {
if (!num[j]) {
anss = false;
break;
}
num[j]--;
q[j].push(k);
}
if (!anss) break;
}
if (!anss) break;
}
if (!anss) {
cout << "-1" << endl;
return 0;
}
cout << k << endl;
for (int i = 1; i <= n; ++i) {
printf("%d ", q[a[i]].front());
q[a[i]].pop();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int cnt[maxn];
int a[maxn];
int p[maxn], b[maxn];
int n;
vector<int> pos[maxn];
int cur[maxn];
int main() {
while (cin >> n) {
int i, j;
int ma = 0;
memset(cnt, 0, sizeof cnt);
for (i = 0; i < n; ++i) scanf("%d", a + i), ++cnt[a[i]], ma = max(ma, a[i]);
for (i = 1; i <= ma; ++i) pos[i].clear(), cur[i] = 0;
for (i = 0; i < n; ++i) pos[a[i]].push_back(i);
for (i = 2; i <= ma; ++i)
if (cnt[i] > cnt[i - 1]) break;
if (i <= ma) {
puts("-1");
continue;
}
printf("%d\n", cnt[1]);
for (i = 2; i <= ma; ++i) p[i - 1] = cnt[i - 1] - cnt[i];
p[ma] = cnt[ma];
int id = 1;
for (i = 1; i <= ma; ++i)
if (p[i]) {
while (p[i]--) {
for (j = 1; j <= i; ++j) {
b[pos[j][cur[j]]] = id;
++cur[j];
}
++id;
}
}
for (i = 0; i < n; ++i) printf("%d%c", b[i], i == n - 1 ? '\n' : ' ');
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
iostream::sync_with_stdio(false);
int n;
cin >> n;
vector<int> nums(n);
map<int, int> counts;
for (int i = 0; i < n; i++) {
cin >> nums[i];
counts[nums[i]]++;
}
map<int, int> last;
int k = 0, previous;
for (auto it = counts.begin(); it != counts.end(); it++) {
if (k++ > 0) {
if (previous < it->second) {
cout << -1 << endl;
return 0;
}
}
if (k != it->first) {
cout << -1 << endl;
return 0;
}
previous = it->second;
last[it->first] = 1;
}
int total = 0;
vector<int> ans(n);
for (int i = 0; i < n; i++) {
ans[i] = last[nums[i]]++;
total = max(ans[i], total);
}
cout << total << endl;
for (int i = 0; i < n; i++) {
if (i) cout << " ";
cout << ans[i];
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int mrk[100];
int main() {
map<long long, long long> mp;
long long a;
cin >> a;
long long f[a];
for (int g = 0; g < a; g++) {
cin >> f[g];
mp[f[g]]++;
}
for (int g = 2; g <= 100000; g++)
if (mp[g] > mp[g - 1]) {
cout << -1;
return 0;
}
cout << mp[1] << endl;
long long x = 1;
for (int g = 0; g < a; g++) {
long long z = f[g];
if (f[g] == 1) {
cout << x << ' ';
x++;
} else {
long long s = mp[f[g]];
cout << mp[1] - s + 1 << ' ';
mp[f[g]]--;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn = 100 * 1000 + 10;
const int INF = 1000 * 1000 * 1000;
int ans[maxn];
pair<int, int> a[maxn];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = i;
}
sort(a, a + n);
int c = 0;
bool ok = (a[0].first == 1);
int last = a[0].first;
int lastc = INF;
ans[a[0].second] = ++c;
int count = 1;
for (int i = 1; i < n; i++) {
if (a[i].first == last)
ans[a[i].second] = ++c;
else {
if (c > lastc || last + 1 != a[i].first) ok = false;
lastc = c;
c = 0;
last = a[i].first;
ans[a[i].second] = ++c;
}
if (c > lastc) ok = false;
count = max(count, c);
}
if (ok) {
cout << count << endl;
for (int i = 0; i < n; i++) cout << ans[i] << " ";
cout << endl;
} else
cout << -1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int modpow(long long int a, long long int n, long long int temp) {
long long int res = 1, y = a;
while (n > 0) {
if (n & 1) res = (res * y) % temp;
y = (y * y) % temp;
n /= 2;
}
return res % temp;
}
int main() {
long long int n, maxi = 0;
int a[100006] = {0}, b[100006];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> b[i];
a[b[i]]++;
if (b[i] > maxi) maxi = b[i];
}
for (int i = 1; i < maxi; i++) {
if (a[i + 1] > a[i]) {
cout << "-1" << endl;
return 0;
}
}
cout << a[1] << endl;
for (int i = 0; i < n; i++) {
cout << a[b[i]] << " ";
a[b[i]]--;
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, a[100005], b[100005] = {}, c[100005] = {};
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
}
for (i = 1; i < 100004; i++) {
if (b[i + 1] > b[i]) {
cout << -1;
return 0;
}
}
cout << b[1] << endl;
for (i = 0; i < n; i++) {
c[a[i]]++;
cout << c[a[i]] << " ";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, m, k, t = 1, x, y, p, q, r, i, j, d, f = 0;
long long cnt[100005] = {0};
while (t--) {
cin >> n;
bool flag = true;
long long a[n], maxf = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
maxf = max(maxf, cnt[a[i]]);
}
for (i = 2; i <= 1e5; i++) {
if (cnt[i] > cnt[i - 1]) flag = false;
}
if (!flag)
cout << -1 << "\n";
else {
cout << maxf << "\n";
for (i = 0; i < n; i++) {
cout << cnt[a[i]]-- << " ";
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int mas[MAXN];
int res[MAXN];
map<int, set<int> > numbers;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> mas[i];
numbers[mas[i]].insert(i);
}
map<int, set<int> >::iterator it;
int k = 0;
while (1) {
k++;
int t = 0;
int isOut = true;
for (it = numbers.begin(); it != numbers.end(); it++) {
t++;
if (!it->second.empty()) {
if (t != it->first) {
cout << "-1";
return 0;
}
int current = *(it->second.begin());
res[current] = k;
it->second.erase(it->second.begin());
isOut = false;
} else {
break;
}
}
if (isOut) {
break;
}
}
for (it = numbers.begin(); it != numbers.end(); it++) {
if (!it->second.empty()) {
cout << "-1";
return 0;
}
}
cout << k - 1 << endl;
for (int i = 0; i < n; i++) {
cout << res[i] << " ";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int cnt[100005];
int res[100005];
int main() {
int N, a;
while (~scanf("%d", &N)) {
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < N; i++) {
scanf("%d", &a);
cnt[a]++;
res[i] = cnt[a];
}
bool flag = true;
int cc = cnt[1];
for (int i = 2; i <= N; i++) {
cc += cnt[i];
if (cnt[i] > cnt[i - 1]) {
flag = false;
break;
}
}
if (cc < N) flag = false;
if (!flag)
printf("-1\n");
else {
printf("%d\n", cnt[1]);
for (int i = 0; i < N; i++) {
if (i == N - 1)
printf("%d\n", res[i]);
else
printf("%d ", res[i]);
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int b[100000 + 10];
int flag = 0;
struct node {
int val;
int rank;
int to;
} a[100000 + 10];
bool cmp(node a, node b) { return a.val < b.val; }
bool cmp2(node a, node b) { return a.rank < b.rank; }
void init() {
memset(b, 0, sizeof(b));
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i].val);
a[i].rank = i;
b[a[i].val]++;
}
sort(a, a + n, cmp);
}
bool judge(int b[]) {
for (int i = 2; i <= a[n - 1].val; i++) {
if (b[i] > b[i - 1]) return false;
}
return true;
}
int main(int argc, char const *argv[]) {
init();
if (judge(b)) {
for (int i = 1; i <= a[n - 1].val; i++) {
for (int j = 1; j <= b[i]; j++) {
a[flag].to = j;
flag++;
}
}
sort(a, a + n, cmp2);
cout << b[1] << endl;
for (int i = 0; i < n; i++) cout << a[i].to << ' ';
} else {
cout << -1;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int N, T, M, K;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int freq[100005];
memset(freq, 0, sizeof freq);
cin >> N;
vector<int> V(N);
int maxn = 0, ans = 0;
for (int(i) = 0; (i) < (N); (i)++) {
cin >> V[i];
maxn = max(maxn, V[i]);
freq[V[i]]++;
ans = max(ans, freq[V[i]]);
}
int cur = freq[1];
for (int i = 2; i <= maxn; i++) {
if (freq[i] <= cur) {
cur = freq[i];
} else {
cout << -1 << endl;
return 0;
}
}
int occ[100005];
memset(occ, 0, sizeof occ);
cout << ans << endl;
for (int i = 0; i < N; i++) {
cout << (occ[V[i]]++) + 1 << " ";
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int max_N = 100000 + 20;
int a[max_N], cnt1[max_N], cnt2[max_N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt1[a[i]]++;
cnt2[a[i]]++;
}
for (int i = 1; i <= 100000; i++) {
if (cnt1[i] < cnt1[i + 1]) {
cout << -1;
return 0;
}
cnt2[i]--;
}
cout << cnt1[1] << endl;
for (int i = 0; i < n; i++) {
cout << cnt1[a[i]] - cnt2[a[i]] << " ";
cnt2[a[i]]--;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int d[int(1e5 + 10)], e[int(1e5 + 10)];
bool solve(int a[], int n) {
int b[n], c = 1;
for (int i = 0; i < n; i++) b[i] = a[i];
sort(b, b + n);
if (b[0] != 1) return false;
for (int i = 1; i < n; i++)
if (b[i] == b[i - 1])
c++;
else {
d[b[i - 1]] = c;
if (b[i] > b[i - 1] + 1) return false;
c = 1;
}
d[b[n - 1]] = c;
for (int i = 2; i <= b[n - 1]; i++)
if (d[i] > d[i - 1]) return false;
return true;
}
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
if (solve(a, n)) {
cout << d[1] << endl;
for (int i = 0; i < n; i++) {
cout << e[a[i]] + 1 << " ";
e[a[i]]++;
}
} else
cout << -1 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int MX = 100000;
int n;
int cnt[100000 + 50], arr[100000 + 50];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
cnt[arr[i]]++;
}
for (int i = 1; i < MX; i++)
if (cnt[i] < cnt[i + 1]) {
cout << -1;
return 0;
}
cout << cnt[1] << endl;
for (int i = 0; i < n; i++) {
cout << cnt[arr[i]] << " ";
cnt[arr[i]]--;
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n, Max, a[N], u[N], x;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &x);
++u[x];
a[i] = u[x];
Max = max(x, Max);
}
if (Max > n) puts("-1"), exit(0);
for (int i = 2; i <= Max; ++i)
if (u[i] > u[i - 1]) puts("-1"), exit(0);
printf("%d\n", u[1]);
for (int i = 1; i <= n; ++i) printf("%d ", a[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
long long a[n], b[100001] = {0};
for (long long i = 0; i < n; i++) {
cin >> a[i];
++b[a[i]];
}
bool poss = true;
for (long long i = 2; i < 100001; i++) {
if (b[i - 1] < b[i]) {
cout << "-1\n";
poss = false;
break;
}
}
if (poss) {
cout << b[1] << " ";
for (long long i = 0; i < n; i++) {
cout << b[a[i]] << " ";
--b[a[i]];
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int> > a(n);
vector<int> p(n), ans(n), kol(n + 1, 0);
for (int i = 0; i < n; ++i) {
cin >> a[i].first;
a[i].second = i;
if (a[i].first > n) {
cout << -1 << '\n';
return 0;
}
++kol[a[i].first];
}
sort(a.begin(), a.end());
for (int j = 2; j <= n; ++j)
if (kol[j] > kol[j - 1]) {
cout << -1 << '\n';
return 0;
}
int mx = 1;
for (int i = 0; i < n; ++i) {
int x = 1;
ans[a[i].second] = 1;
while (i + 1 < n && a[i].first == a[i + 1].first) {
++i;
++x;
ans[a[i].second] = x;
}
if (x > mx) mx = x;
}
cout << mx << '\n';
for (int i = 0; i < n; ++i) cout << ans[i] << ' ';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int pos[100001];
int cnt[100001];
int val[100001];
int main() {
int n;
cin >> n;
map<int, int> mp;
map<int, int>::iterator it;
for (int i = 0; i < n; i++) {
cin >> val[i];
mp[val[i]]++;
}
int ind = 1000000;
int nu = 0;
int res = -1;
for (it = mp.begin(); it != mp.end(); it++) {
int v = ((*it).second);
int num = ((*it).first);
res = max(res, v);
if (v > ind || num - nu > 1) {
cout << "-1";
return 0;
}
ind = v;
nu = num;
}
cout << res << endl;
for (int i = 0; i < n; i++) {
cout << mp[val[i]] << " ";
mp[val[i]]--;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int tab[100005], ile[100005], now[100005], n, i, naj;
bool can;
int main() {
scanf("%d", &n);
for (i = 0; i < n; ++i) {
scanf("%d", &tab[i]);
naj = max(naj, tab[i]);
++ile[tab[i]];
}
can = true;
for (i = 1; i < naj; ++i)
if (ile[i + 1] > ile[i]) can = false;
if (!can)
printf("-1\n");
else {
printf("%d\n", ile[1]);
for (i = 0; i < n; ++i) {
++now[tab[i]];
printf("%d ", now[tab[i]]);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int b[100001], a[100001], n, j, i, l, y[100001], k[100001];
bool b1;
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i];
y[i] = a[i];
b[a[i]] = 1;
k[a[i]]++;
}
i = 1;
sort(y + 1, y + n + 1);
while (y[i] == 1) {
l++;
i++;
}
i = 1;
while (k[i] != 0) i++;
b1 = 1;
for (j = 2; j <= 100000; j++)
if (k[j] > k[j - 1]) {
b1 = 0;
break;
}
if (l == 0 || b1 == 0)
cout << -1 << endl;
else {
cout << l << endl;
i = 1;
for (i = 1; i <= n; i++) {
cout << b[a[i]] << " ";
b[a[i]]++;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int num[100010];
int cnt[100010];
int main() {
int n;
cin >> n;
int maxn = 0;
int res = 0;
for (int i = 0; i < (n); i++) {
cin >> num[i];
cnt[num[i]]++;
maxn = max(maxn, num[i]);
res = max(res, cnt[num[i]]);
}
for (int i = 1; i < maxn; i++) {
if (cnt[i] >= cnt[i + 1]) {
continue;
} else {
cout << -1 << endl;
return 0;
}
}
cout << res << endl;
for (int i = 0; i < (n); i++) {
cout << cnt[num[i]]--;
if (i != n - 1) cout << ' ';
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, soln;
pair<int, int> a[100005];
int sol[100005];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i].first);
a[i].second = i;
}
sort(a + 1, a + 1 + n);
int last = 9999999, ovaj = 0;
for (int i = 1; i <= n; i++) {
if (a[i].first != ovaj + 1) {
printf("-1\n");
return 0;
}
ovaj = a[i].first;
int j = 0;
while (a[i + j].first == ovaj) {
sol[a[i + j].second] = j + 1;
j++;
}
i += j - 1;
if (j > last) {
printf("-1\n");
return 0;
}
last = j;
}
while (a[soln + 1].first == 1) soln++;
printf("%d\n", soln);
for (int i = 1; i <= n; i++) {
printf("%d", sol[i]);
if (i < n) printf(" ");
}
printf("\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int n;
int b[MAX_N];
bool used[MAX_N];
int p;
struct node {
int value;
int id;
} a[MAX_N];
int cmp(node x, node y) { return x.value < y.value; }
bool dfs(node num, int i) {
used[i] = true;
if (num.value == 1) {
return true;
}
for (int j = i - 1; j >= 0; j--) {
if (j == 0 && a[j].value != num.value - 1) {
return false;
}
if (!used[j] && a[j].value == num.value - 1) {
used[j] = true;
b[a[j].id] = p;
if (dfs(a[j], j)) {
return true;
} else {
return false;
}
}
}
return false;
}
int main() {
while (~scanf("%d", &n)) {
memset(used, false, sizeof(used));
memset(b, 0, sizeof(b));
for (int i = 0; i < n; i++) {
int tmp;
scanf("%d", &tmp);
a[i].id = i;
a[i].value = tmp;
}
sort(a, a + n, cmp);
p = 1;
bool flag = true;
for (int i = n - 1; i >= 0; i--) {
if (!used[i]) {
used[i] = true;
b[a[i].id] = p;
if (!dfs(a[i], i)) {
flag = false;
break;
}
p++;
}
}
if (flag) {
printf("%d\n", p - 1);
for (int i = 0; i < n; i++) {
if (i == 0) {
printf("%d", b[i]);
} else {
printf(" %d", b[i]);
}
}
printf("\n");
} else {
printf("-1\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int mass[100005];
int mass1[100005];
int n, i;
cin >> n;
for (i = 1; i <= 100003; i++) mass1[i] = 0;
for (i = 0; i < n; i++) {
cin >> mass[i];
mass1[mass[i]]++;
}
for (i = 1; i <= 100002; i++)
if (mass1[i] < mass1[i + 1]) {
cout << -1 << endl;
return 0;
}
cout << mass1[1] << endl;
for (i = 0; i < n; i++) {
cout << mass1[mass[i]] << " ";
mass1[mass[i]]--;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &x) {
x = 0;
int f = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
f |= (ch == '-');
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x = f ? -x : x;
return;
}
const int N = 1e5 + 10;
int n, a[N], cs[N], Msum, wz, sc[N], tot;
int main() {
read(n);
for (register int i = 1; i <= n; i++) {
read(a[i]);
cs[a[i]]++;
Msum = max(Msum, a[i]);
}
for (register int i = Msum; i >= 1; i--) {
if (cs[i] < cs[i + 1]) {
cout << -1;
return 0;
}
}
printf("%d\n", cs[1]);
for (register int i = 1; i <= n; i++) {
sc[a[i]]++;
printf("%d ", sc[a[i]]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ans[100010];
struct P {
int v, id;
int a;
} p[100010];
bool cmp(P p1, P p2) { return p1.v < p2.v; }
bool cmp2(P p1, P p2) { return p1.id < p2.id; }
int main() {
int n;
scanf("%d", &n);
int ma = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &p[i].v);
ans[p[i].v]++;
ma = max(ma, p[i].v);
p[i].id = i;
}
sort(p, p + n, cmp);
bool ok = true;
for (int i = 1; i < ma; i++) {
if (ans[i] < ans[i + 1]) {
ok = false;
break;
}
}
if (!ok)
puts("-1");
else {
int idx = 0;
int cnt = 0;
for (int i = 1; i <= ma; i++) {
cnt = max(cnt, ans[i]);
for (int j = 1; j <= ans[i]; j++) p[idx++].a = j;
}
sort(p, p + n, cmp2);
printf("%d\n", cnt);
for (int i = 0; i < n; i++) printf("%d ", p[i].a);
puts("");
}
}
|
#include <bits/stdc++.h>
int n, m;
int h[100050];
int cnt[100050 + 1] = {0};
int main(void) {
int i;
m = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
int x;
scanf("%d", &x);
h[i] = ++cnt[x];
if (cnt[x] > m) m = cnt[x];
}
for (i = 1; i < 100050; i++)
if (cnt[i] < cnt[i + 1]) break;
if (i < 100050)
puts("-1");
else {
printf("%d\n", m);
for (i = 0; i < n; i++) printf("%d ", h[i]);
puts("");
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, j;
cin >> n;
long long int a[n];
vector<long long int> v[n + 1];
map<long long int, long long int> mp;
long long int maxi = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > maxi) maxi = a[i];
mp[a[i]]++;
}
long long int cnt = mp[1];
for (i = 2; i <= maxi; i++) {
if (mp[i] > mp[i - 1]) {
cout << "-1\n";
return 0;
}
}
cout << cnt << "\n";
for (i = 1; i <= n; i++) {
for (j = mp[i]; j >= 1; j--) v[i].push_back(j);
}
for (i = 0; i < n; i++) {
cout << *(v[a[i]].end() - 1) << " ";
v[a[i]].pop_back();
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXVAL = (int)(1e5 + 2);
int num[MAXVAL], cur[MAXVAL];
int main() {
int n;
vector<int> a;
cin >> n;
a.resize(n);
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) ++num[a[i]];
int mx = -MAXVAL, ans = 0;
for (int i = 0; i < n; ++i) {
mx = max(mx, a[i]);
ans = max(ans, num[i]);
}
if (n == 1 && mx == 1) {
cout << "1\n1";
return 0;
}
for (int i = mx - 1; i >= 1; --i) {
if (num[i] < num[i + 1]) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
for (int i = 0; i < n; ++i) {
cout << ++cur[a[i]] << ' ';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100500], b[100500], num[100500], c, d, e, f, g, h;
vector<int> o[100500];
void ReadSomeData() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
e = max(e, a[i]);
o[a[i]].push_back(i);
}
}
void SolveThisProblemSuccessfully() {
c = 1;
for (int i = 2; i <= e; i++) {
if (b[i] > b[i - 1]) {
c = 0;
}
}
if (c) {
cout << b[1] << endl;
for (int i = 0; i <= e; i++) {
for (int j = 0; j < o[i].size(); j++) {
num[o[i][j]] = j;
}
}
for (int i = 0; i < n; i++) cout << num[i] + 1 << " ";
} else
cout << -1;
}
int main() {
ReadSomeData();
SolveThisProblemSuccessfully();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long double epsylon = 1e-9;
int cnt[100010];
int br[100010];
int main() {
int n;
cin >> n;
vector<int> a(n);
vector<int> brs;
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
cnt[a[i]]++;
}
for (int i = 1; i < 100002; ++i) {
if (cnt[i + 1] > cnt[i]) {
cout << -1 << endl;
return 0;
}
}
cout << cnt[1] << endl;
memset(br, 0, sizeof(br));
for (int i = 0; i < n; ++i) {
printf("%d%c", ++br[a[i]], ((i == n - 1) ? '\n' : ' '));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int cnt[100001];
pair<int, int> p[n];
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; i++) {
cin >> p[i].first;
p[i].second = i;
cnt[p[i].first]++;
}
sort(p, p + n);
for (int i = 2; i <= 1e5; i++) {
if (cnt[i] > cnt[i - 1]) {
cout << -1;
return 0;
}
}
int cur, pr = 0, q;
int a[n], ans = 0;
for (int i = 0; i < n; i++) {
cur = p[i].first;
if (cur != pr) {
q = 1;
}
a[p[i].second] = q++;
ans = max(ans, q - 1);
pr = cur;
}
cout << ans << endl;
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mxN = 2e5;
int main() {
int n;
cin >> n;
int arr[n], mx = 0;
map<int, int> mp;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
mp[arr[i]]++;
mx = max(mx, mp[arr[i]]);
}
for (int i = 0; i <= (int)1e5; ++i) {
if (mp[i + 1] < mp[i + 2]) {
cout << -1;
return 0;
}
}
cout << mx << endl;
for (int i = 0; i < n; ++i) {
cout << mp[arr[i]] << " ";
mp[arr[i]]--;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 101010;
vector<int> List[maxn];
int ans[maxn], now[maxn], n, id;
int main() {
scanf("%d", &n);
for (int i = 1; i < 101010; i++) List[i].clear();
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
List[x].push_back(i);
}
memset(now, 0, sizeof(now));
int tot = 0;
for (id = 1; now[1] < List[1].size(); id++) {
for (int i = 1;; i++)
if (now[i] < List[i].size()) {
ans[List[i][now[i]]] = id;
now[i]++;
tot++;
} else
break;
}
if (tot != n)
cout << -1;
else {
cout << id - 1 << endl;
for (int i = 1; i <= n; i++) cout << ans[i] << " ";
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int m, n, c, d, j, k, l, r, t, y, u, z, i, e, f, g, h, a = 1, b;
int main() {
map<long long int, long long int> mp;
cin >> n;
long long int v[n + 1];
vector<long long int> w, x;
for (i = 1; i <= n; i++) {
cin >> v[i];
mp[v[i]]++;
x.push_back(mp[v[i]]);
d = max(d, v[i]);
}
for (i = 1; i <= d; i++) {
w.push_back(mp[i]);
}
for (i = 1; i < w.size(); i++) {
if (w[i] > w[i - 1]) {
cout << -1;
return 0;
}
}
cout << mp[1] << endl;
for (i = 0; i < x.size(); i++) cout << x[i] << " ";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int num[100010], n, counter[100010], ans[100010], i;
scanf("%d", &n);
for (i = 0; i <= 100000; ++i) {
counter[i] = 0;
ans[i] = 0;
}
for (i = 0; i < n; ++i) {
scanf("%d", &num[i]);
++counter[num[i]];
}
bool status = true;
for (i = 2; i <= 100000; ++i) {
if (counter[i] > counter[i - 1]) status = false;
}
if (!status)
printf("-1\n");
else {
printf("%d\n", counter[1]);
for (i = 0; i < n; ++i) printf("%d ", ++ans[num[i]]);
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> A(n);
for (int i = 0; i < n; ++i) cin >> A[i];
vector<int> P(112345, 1);
vector<int> res(n);
for (int i = 0; i < n; ++i) res[i] = P[A[i] - 1]++;
for (int i = 1; i < P.size(); ++i)
if (P[i] > P[i - 1]) {
cout << "-1\n";
return 0;
}
cout << P[0] - 1 << endl;
for (int i = 0; i < n; ++i) cout << res[i] << " ";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int sol[1000000];
int main() {
ios::sync_with_stdio(false);
cin >> n;
map<int, vector<int> > mapa;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
mapa[x].push_back(i);
}
int valant = 0;
int amountant = 1000000000;
for (map<int, vector<int> >::iterator it = mapa.begin(); it != mapa.end();
it++) {
int val = it->first;
vector<int> &v = it->second;
if (val != valant + 1) {
cout << -1 << endl;
exit(0);
}
int amount = int(v.size());
if (amount > amountant) {
cout << -1 << endl;
exit(0);
}
for (int i = 0; i < int(v.size()); i++) sol[v[i]] = i + 1;
valant = val;
amountant = amount;
}
cout << mapa.begin()->second.size() << endl;
for (int i = 1; i <= n; i++) {
if (i > 1) cout << " ";
cout << sol[i];
}
cout << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
multiset<int> s[N];
int cnt[N];
int main() {
int n;
cin >> n;
int a[n];
int mi = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[i] = x;
mi = max(mi, x);
cnt[x]++;
s[x].insert(i);
}
for (int i = mi; i > 1; i--) {
if (cnt[i] > cnt[i - 1]) return cout << -1, 0;
}
int ans[N];
int ma = 0;
for (int i = 0; i < n; i++) {
ans[i] = s[a[i]].size();
ma = max(ma, ans[i]);
s[a[i]].erase(s[a[i]].find(i));
}
for (int i = 1; i <= n; i++) {
if (s[a[i - 1]].size()) {
return cout << -1, 0;
}
}
cout << ma << endl;
for (int i = 0; i < n; i++) cout << ans[i] << " ";
}
|
#include <bits/stdc++.h>
using namespace std;
int f[111111];
int vis[111111];
int ans[111111];
int num[111111];
int maxnum[111111];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> f[i];
}
for (int i = 1; i <= 100000; i++) vis[i] = 1;
for (int i = 1; i <= n; i++) {
ans[i] = vis[f[i]]++;
num[ans[i]]++;
maxnum[ans[i]] = max(maxnum[ans[i]], f[i]);
}
int box_num = 1;
for (int i = 1; i <= n; i++) box_num = max(box_num, ans[i]);
for (int i = 1; i <= box_num; i++) {
if (num[i] != maxnum[i]) {
printf("-1\n");
return 0;
}
}
printf("%d\n", box_num);
for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 11, mod = 1e9 + 7;
const int MAX = 1e9 + 11;
const int INF1 = 2e9 + 11;
const long long INF2 = 2e18 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-12;
const double PI = acos(-1.0);
int n, ct[N], ans[N], cnt, b[N], a[N];
int main() {
if (fopen("peacefulsets"
".in",
"r"))
freopen(
"peacefulsets"
".in",
"r", stdin),
freopen(
"peacefulsets"
".out",
"w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
set<int> st;
for (int i = 1; i <= n; i += 1) cin >> a[i], st.insert(a[i]), b[i] = a[i];
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i += 1) ++ct[a[i]];
int last = 0;
for (auto& it : st) {
if (last && ct[it] > ct[last] || it - last > 1) return !(cout << -1);
last = it;
}
cout << ct[1] << "\n";
for (auto& it : st) ct[it] = 0;
for (int i = 1; i <= n; i += 1) {
++ct[b[i]];
cout << ct[b[i]] << " ";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 1e5 * 5, maxv = 1e4, mod = 1e17 + 7;
long long int a1[maxn];
long long int dp[maxn];
string s1, s2;
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
long long int n, a, b, m = 0;
cin >> n;
vector<long long int> p;
for (int i = 1; i <= n; i++) {
cin >> a1[i];
dp[a1[i]]++;
p.push_back(dp[a1[i]]);
m = max(m, dp[a1[i]]);
}
for (int i = 1; i <= maxn - 5; i++) {
if (dp[i + 1] > dp[i]) {
cout << -1;
return 0;
}
}
cout << m << "\n";
for (int i = 0; i < p.size(); i++) cout << p[i] << " ";
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long m, long long n) {
long long r;
while (n != 0) {
r = m % n;
m = n;
n = r;
}
return m;
}
int main() {
int n;
cin >> n;
vector<pair<int, int> > a;
for (int i = 0; i < n; i++) {
int k;
cin >> k;
a.push_back(make_pair(k, i));
}
sort(a.begin(), a.end());
int ans[n];
int cnt = 0, pre = 1;
int pre_cnt = 100002;
int flag = 0;
int c = 0;
for (int i = 0; i < n; i++) {
if (a[i].first == 1) c++;
if (a[i].first == pre) {
cnt++;
ans[a[i].second] = cnt;
if (cnt > pre_cnt) {
flag = 1;
break;
}
} else if (a[i].first == pre + 1) {
pre_cnt = cnt;
cnt = 1;
pre++;
ans[a[i].second] = cnt;
} else {
flag = 1;
break;
}
}
if (flag == 1) {
cout << "-1";
return 0;
}
if (c == 0) {
cout << "-1";
return 0;
}
cout << c << endl;
for (int i = 0; i < n; i++) cout << ans[i] << " ";
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000")
int n;
int a[100009];
vector<int> v[100009];
int ans[100009];
int main() {
scanf("%d", &n);
int mm = 0;
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]), mm = max(mm, a[i]), v[a[i]].push_back(i);
for (int i = mm; i > 1; i--) {
if (v[i].size() > v[i - 1].size()) {
printf("-1\n");
return 0;
}
for (int j = 0; j < v[i].size(); j++) ans[v[i][j]] = j + 1;
}
for (int j = 0; j < v[1].size(); j++) ans[v[1][j]] = j + 1;
printf("%d\n", v[1].size());
for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
puts("");
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
int cnt[MAX];
int a[MAX];
int n;
void read() {
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
}
void doit() {
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; i++) {
if (a[i] > n) {
puts("-1");
return;
} else {
cnt[a[i]]++;
}
}
for (int i = 2; i <= n; i++) {
if (cnt[i] > cnt[i - 1]) {
puts("-1");
return;
}
}
printf("%d\n", cnt[1]);
for (int i = 0; i < n; i++) {
if (i) putchar(' ');
printf("%d", cnt[a[i]]--);
}
puts("");
}
int main() {
while (scanf("%d", &n) == 1) {
read();
doit();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int t[100001];
int c[100001];
int main(void) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t[i];
c[t[i]]++;
}
int sum = 0;
if (c[1] == 0) {
cout << "-1\n";
return 0;
}
for (int i = 1;; i++) {
sum += c[i];
if (sum == n) break;
if (c[i] < c[i + 1]) {
cout << "-1\n";
return 0;
}
}
cout << c[1] << endl;
for (int i = 0; i < n - 1; i++) {
cout << c[t[i]] << " ";
c[t[i]]--;
}
cout << c[t[n - 1]] << endl;
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.