Submission #773992

# Submission time Handle Problem Language Result Execution time Memory
773992 2023-07-05T10:30:06 Z ParsaS Watermelon (INOI20_watermelon) C++17
0 / 100
3 ms 596 KB
// In the name of God
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
const int N = 1e6 + 5;
int n, k, p[N];

long double x[N];
int ans[N];

void solve() {
    cin >> n >> k;
    int tmp = 0;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        if (p[i] == -1) {
            x[i] = 1e9;
        }
    }
    if (k > 1 || p[n - 1] != -1) {
        cout << -1 << '\n';
        return;
    }
    stack<int> st;
    st.push(n - 1);
    for (int i = n - 2; i >= 0; i--) {
        long double prv = 0;
        if (p[i] == -1) {
            st.push(i);
            continue;
        }
        int k = p[i] - 1;
        while (!st.empty() && p[st.top()] != -1 && k) {
            prv = p[st.top()];
            k--;
            st.pop();
        }
        if (k) {
            cout << -1 << '\n';
            return;
        }

        x[i] = (x[st.top()] + prv) / 2.;
        st.push(i);
    }
    vector<pair<long double, int> > vec;
    for (int i = 0; i < n; i++) {
        vec.pb(mp(x[i], i));
    }
    sort(vec.begin(), vec.end());
    for (int i = 0; i < n; i++)
        ans[vec[i].se] = i + 1;
    for (int i = 0; i < n; i++) {
        if (p[i] == -1)
            ans[i] = n - tmp, tmp++;
    }
    for (int i = 0; i < n; i++)
        cout << ans[i] << ' ';

}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -