Submission #239032

# Submission time Handle Problem Language Result Execution time Memory
239032 2020-06-14T07:35:16 Z VEGAnn Vrtić (COCI18_vrtic) C++14
0 / 160
5 ms 640 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define i2 array<int,2>
#define PB push_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 210;
const ll OO = 1e18;
const int md = int(1e9) + 7;
int n, nt[N], ans[N], a[N], sum = 0;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> nt[i];

        if (i == n)
            assert(nt[i] == 1);
        else assert(nt[i] == i + 1);
    }

    for (int i = 1; i <= n; i++)
        cin >> a[i];

    sort(a + 1, a + n + 1);

    for (int it = 0, loc = 1; it < n; it++){
        ans[loc] = a[1 + it];
        loc = nt[loc];
    }

    for (int i = 1; i <= n; i++)
        sum += abs(ans[i] - ans[nt[i]]);

    cout << sum << '\n';

    for (int i = 1; i <= n; i++)
        cout << ans[i] << " ";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB the dissatisfaction value doesn't match with your answer
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB the dissatisfaction value doesn't match with your answer
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -