# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
103737 | ekrem | Zalmoxis (BOI18_zalmoxis) | C++98 | 411 ms | 30568 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;
typedef long long ll;
typedef pair < int , int > ii;
int n, k, m[N], a[N], b[N], bas[N], son[N], u[N], g[35][N];
ii ans;
void sirala(int j){
for(int i = 1; i <= m[j]; i++)
u[g[j][i]]++;
m[j] = 0;
for(int i = 1; i <= n; i++)
while(u[i]){
g[j][++m[j]] = i;
u[i]--;
}
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d %d",&n ,&k);
for(int i = 1; i <= n; i++){
scanf("%d",a + i);
g[a[i]][++m[a[i]]] = i;
bas[i] = i;
son[i] = i;
}
for(int i = 1; i <= 29; i++){
sirala(i);
// cout << i << " -> ";
// for(int j = 1; j <= m[i]; j++)
// cout << g[i][j] << " ";
// cout << endl;
for(int j = 1; j <= m[i]; j++)
if(j < m[i] and son[g[i][j]] + 1 == bas[g[i][j + 1]]){
// cout << " buldum " << g[i][j] << endl;
g[i + 1][++m[i + 1]] = (g[i][j + 1]);
bas[g[i][j + 1]] = bas[g[i][j]];
j++;
} else{
// cout << "EKLEEE" << endl;
ans = mp(g[i][j], i);
g[i + 1][++m[i + 1]] = (g[i][j]);
}
}
for(int i = 1; i <= n; i++){
printf("%d ", a[i]);
if(i == ans.st)
printf("%d ", ans.nd);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |