Submission #1115591

# Submission time Handle Problem Language Result Execution time Memory
1115591 2024-11-20T16:41:13 Z staszic_ojuz Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
98 ms 24824 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

struct dat {
    ll a;
    ll i;
    dat(): a(0), i(0) {};
};
bool operator<(dat a, dat b) {
    return a.a < b.a;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n; cin >> n;
    vector<dat> wol(n + 1);
    for(int i = 0; i < n + 1; i++) {
        cin >> wol[i].a;
        wol[i].i = i;
    }
    vector<ll> ma(n);
    for(int i = 0; i < n; i++) {
        cin >> ma[i];
    }
    
    sort(wol.begin(), wol.end());
    sort(ma.begin(), ma.end());

    // cout << "WOL\n";
    // for(int i = 0; i < n + 1; i++) {
    //     cout << wol[i].a << " " << wol[i].i << '\n';
    // }

    // vector<ll> pout(n + 1, 0);
    // for(int i = 0; i < n + 1; i++) {
    //     pout[wol[i].i] = i;
    // }

    vector<dat> par1(n);
    vector<dat> par2(n);
    for(int i = 0; i < n; i++) {
        par1[i].i = wol[i].i;
        par1[i].a = max(wol[i].a - ma[i], (ll)0);
        par2[i].i = wol[i + 1].i;
        par2[i].a = max(wol[i + 1].a - ma[i], (ll)0);
    }
    vector<dat> pref(n + 2);
    vector<dat> suff(n + 2);
    pref[0].a = 0;
    pref[n + 1].a = 0;
    
    suff[0].a = 0;
    suff[n + 1].a = 0;    
    pref[0].i = par2[n - 1].i;
    for(int i = 1; i < n + 1; i++) {
        if(pref[i - 1].a > par1[i - 1].a) {
            pref[i].a = pref[i - 1].a;
        } else {
            pref[i].a = par1[i - 1].a;    
        }

        pref[i].i = par1[i - 1].i;
    }
    suff[n].i = par1[0].i;
    for(int i = n -1;i>=0;i--) {
        if(suff[i + 1].a > par2[i].a) {
            suff[i].a = suff[i + 1].a;
        } else {
            suff[i].a = par2[i].a;    
        }
        suff[i].i = par2[i].i;
    }
    // cout << "PREF\n";
    // for(int i = 0; i < n + 1; i++) {
    //     cout << pref[i].a << " " << pref[i].i << '\n';
    // }
    // cout << "SUFF\n";
    // for(int i = 0; i < n + 1; i++) {
    //     cout << suff[i].a  << " " << suff[i].i << '\n';
    // }

    vector<ll> out(n + 1);

    for(int i = 0; i < n + 1; i++) {
        //cout   << "pout[i]: " << pout[i] <<", i: " << i << "pout: "<< pout[i] << endl;
        ll res = pref[i].a;
        res =max(pref[i].a, suff[i].a);
        out[wol[i].i] = res;
        //cout << wol[i].i << " ";
    }

    // cout << "pout\n";
    // for(int i = 0; i < n + 1; i++) {
    //     cout << out[i] << '\n';
    // }

    for(int i = 0; i < n + 1; i++) {
        cout << out[i] << " ";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 2 ms 524 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 2 ms 592 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 472 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 2 ms 524 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 2 ms 592 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 472 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 82 ms 23448 KB Output is correct
34 Correct 87 ms 24392 KB Output is correct
35 Correct 75 ms 23628 KB Output is correct
36 Correct 80 ms 23828 KB Output is correct
37 Correct 86 ms 24824 KB Output is correct
38 Correct 76 ms 24512 KB Output is correct
39 Correct 78 ms 23384 KB Output is correct
40 Correct 73 ms 23548 KB Output is correct
41 Correct 77 ms 23592 KB Output is correct
42 Correct 80 ms 23660 KB Output is correct
43 Correct 82 ms 23564 KB Output is correct
44 Correct 70 ms 22708 KB Output is correct
45 Correct 73 ms 23112 KB Output is correct
46 Correct 78 ms 22828 KB Output is correct
47 Correct 59 ms 23536 KB Output is correct
48 Correct 60 ms 23644 KB Output is correct
49 Correct 73 ms 24208 KB Output is correct
50 Correct 98 ms 24136 KB Output is correct
51 Correct 84 ms 24088 KB Output is correct
52 Correct 76 ms 24136 KB Output is correct
53 Correct 76 ms 24136 KB Output is correct