# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
414324 |
2021-05-30T10:33:55 Z |
Blagojce |
Swap (BOI16_swap) |
C++11 |
|
844 ms |
262148 KB |
#include <bits/stdc++.h>
#include <cstdio>
#pragma GCC optimize("O3")
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 262144 + 10;
inline int readint(){
int ret=0;
for(char c;;){
c=getchar();
if('0'<=c and c<='9')
ret=ret*10+(c&15);
else
return ret;
}
}
vector<char> digits;
inline void printint(int x){
do{
digits.push_back(x%10|48);
x/=10;
}while(x);
while(not digits.empty())
putchar(digits.back()), digits.pop_back();
}
int n;
int a[mxn];
unordered_map<int, vector<int> > f[mxn];
//vector<int> f[mxn][mxn];
void combine(vector<int> *v1, vector<int> *v2, vector<int> *r){
int p = 0;
int l = 1;
while(p < (int)v1->size()){
fr(k, 0, l){
r->pb((*v1)[p+k]);
}
fr(k, 0, l){
r->pb((*v2)[p+k]);
}
p += l;
l *= 2;
}
}
vector<int> g1;
vector<int> g2;
vector<int> cand;
void solve(){
//cin >> n;
n = readint();
fr(i, 1, n+1){
a[i] = readint();
//cin >> a[i];
}
int orgn = n;
int m = n;
while(m+1 - ((m+1)&-(m+1)) != 0){
++m;
}
fr(i, n+1, m+1){
a[i] = i;
}
n = m;
for(int i = n; i >= 1; i --){
cand.clear();
for(int j = i; j >= 1; j /= 2){
cand.pb(a[j]);
if(j != 1){
if(j % 2){
cand.pb(a[j-1]);
}
else{
cand.pb(a[j+1]);
}
}
}
for(auto j : cand){
if(i*2 > n){
f[i][j] = {j};
}
else{
int mi = min(j, min(a[i*2], a[i*2+1]));
if(j == mi){
combine(&f[i*2][a[i*2]], &f[i*2+1][a[i*2+1]], &f[i][j]);
}
else if(a[i*2] == mi){
combine(&f[i*2][j], &f[i*2+1][a[i*2+1]], &f[i][j]);
}
else{
g1.clear();
combine(&f[i*2][a[i*2]], &f[i*2+1][j], &g1);
g2.clear();
combine(&f[i*2][j],&f[i*2+1][a[i*2]], &g2);
f[i][j] = min(g1, g2);
}
f[i][j].insert(f[i][j].begin(), mi);
}
}
if(i*2 <= n){
f[i*2].clear();
f[i*2+1].clear();
}
}
vector<int> ans = f[1][a[1]];
fr(i, 0, orgn){
printint(ans[i]);
putchar(' ');
//cout<<f[1][a[1]][i]<<' ';
}
}
int main(){
digits.reserve(10);
// freopen("t.in.25", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
//
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14668 KB |
Output is correct |
2 |
Correct |
10 ms |
14668 KB |
Output is correct |
3 |
Correct |
10 ms |
14712 KB |
Output is correct |
4 |
Correct |
10 ms |
14668 KB |
Output is correct |
5 |
Correct |
10 ms |
14668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14668 KB |
Output is correct |
2 |
Correct |
10 ms |
14668 KB |
Output is correct |
3 |
Correct |
10 ms |
14712 KB |
Output is correct |
4 |
Correct |
10 ms |
14668 KB |
Output is correct |
5 |
Correct |
10 ms |
14668 KB |
Output is correct |
6 |
Correct |
10 ms |
14668 KB |
Output is correct |
7 |
Correct |
10 ms |
14692 KB |
Output is correct |
8 |
Correct |
10 ms |
14668 KB |
Output is correct |
9 |
Correct |
11 ms |
14668 KB |
Output is correct |
10 |
Correct |
11 ms |
14624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14668 KB |
Output is correct |
2 |
Correct |
10 ms |
14668 KB |
Output is correct |
3 |
Correct |
10 ms |
14712 KB |
Output is correct |
4 |
Correct |
10 ms |
14668 KB |
Output is correct |
5 |
Correct |
10 ms |
14668 KB |
Output is correct |
6 |
Correct |
10 ms |
14668 KB |
Output is correct |
7 |
Correct |
10 ms |
14692 KB |
Output is correct |
8 |
Correct |
10 ms |
14668 KB |
Output is correct |
9 |
Correct |
11 ms |
14668 KB |
Output is correct |
10 |
Correct |
11 ms |
14624 KB |
Output is correct |
11 |
Correct |
16 ms |
15584 KB |
Output is correct |
12 |
Correct |
15 ms |
15636 KB |
Output is correct |
13 |
Correct |
15 ms |
15564 KB |
Output is correct |
14 |
Correct |
16 ms |
15564 KB |
Output is correct |
15 |
Correct |
15 ms |
15684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14668 KB |
Output is correct |
2 |
Correct |
10 ms |
14668 KB |
Output is correct |
3 |
Correct |
10 ms |
14712 KB |
Output is correct |
4 |
Correct |
10 ms |
14668 KB |
Output is correct |
5 |
Correct |
10 ms |
14668 KB |
Output is correct |
6 |
Correct |
10 ms |
14668 KB |
Output is correct |
7 |
Correct |
10 ms |
14692 KB |
Output is correct |
8 |
Correct |
10 ms |
14668 KB |
Output is correct |
9 |
Correct |
11 ms |
14668 KB |
Output is correct |
10 |
Correct |
11 ms |
14624 KB |
Output is correct |
11 |
Correct |
16 ms |
15584 KB |
Output is correct |
12 |
Correct |
15 ms |
15636 KB |
Output is correct |
13 |
Correct |
15 ms |
15564 KB |
Output is correct |
14 |
Correct |
16 ms |
15564 KB |
Output is correct |
15 |
Correct |
15 ms |
15684 KB |
Output is correct |
16 |
Correct |
828 ms |
114484 KB |
Output is correct |
17 |
Correct |
835 ms |
114356 KB |
Output is correct |
18 |
Correct |
825 ms |
114924 KB |
Output is correct |
19 |
Correct |
844 ms |
117876 KB |
Output is correct |
20 |
Correct |
837 ms |
117828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14668 KB |
Output is correct |
2 |
Correct |
10 ms |
14668 KB |
Output is correct |
3 |
Correct |
10 ms |
14712 KB |
Output is correct |
4 |
Correct |
10 ms |
14668 KB |
Output is correct |
5 |
Correct |
10 ms |
14668 KB |
Output is correct |
6 |
Correct |
10 ms |
14668 KB |
Output is correct |
7 |
Correct |
10 ms |
14692 KB |
Output is correct |
8 |
Correct |
10 ms |
14668 KB |
Output is correct |
9 |
Correct |
11 ms |
14668 KB |
Output is correct |
10 |
Correct |
11 ms |
14624 KB |
Output is correct |
11 |
Correct |
16 ms |
15584 KB |
Output is correct |
12 |
Correct |
15 ms |
15636 KB |
Output is correct |
13 |
Correct |
15 ms |
15564 KB |
Output is correct |
14 |
Correct |
16 ms |
15564 KB |
Output is correct |
15 |
Correct |
15 ms |
15684 KB |
Output is correct |
16 |
Correct |
828 ms |
114484 KB |
Output is correct |
17 |
Correct |
835 ms |
114356 KB |
Output is correct |
18 |
Correct |
825 ms |
114924 KB |
Output is correct |
19 |
Correct |
844 ms |
117876 KB |
Output is correct |
20 |
Correct |
837 ms |
117828 KB |
Output is correct |
21 |
Runtime error |
465 ms |
262148 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |