답안 #963808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963808 2024-04-15T17:39:48 Z RaresFelix Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
84 ms 10908 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ld = long double;  // or double, if TL is tight
using str = string; 
using ii = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vi B(n);
    vector<pair<int, int> > A(n + 1);
    for(int i = 0; i <= n; ++i) {
        cin >> A[i].first;
        A[i].second = i;
    }
    for(int i = 0; i < n; ++i) {
        cin >> B[i];
    }
    sort(all(A));
    sort(all(B));
    vi DP1(n), DP2(n);
    for(int i = 0; i < n; ++i) {
        DP1[i] = max(0, -B[i] + A[i].first);
        if(i) DP1[i] = max(DP1[i - 1], DP1[i]);
    }
    for(int i = n - 1; i >= 0; --i) {
        DP2[i] = max(0, -B[i] + A[i + 1].first);
        if(i + 1 < n) DP2[i] = max(DP2[i + 1], DP2[i]);
    }
    vi Re(n + 1, 0);
    for(int i = 0; i <= n; ++i) {
        int v = 0;
        if(i) v = DP1[i - 1];
        if(i < n) v = max(v, DP2[i]);
        Re[A[i].second] = v;
    }
    for(auto it : Re)
        cout << it << " ";
    cout << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 516 KB Output is correct
28 Correct 1 ms 360 KB Output is correct
29 Correct 1 ms 524 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 472 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 516 KB Output is correct
28 Correct 1 ms 360 KB Output is correct
29 Correct 1 ms 524 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 472 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 68 ms 9952 KB Output is correct
34 Correct 77 ms 10316 KB Output is correct
35 Correct 84 ms 10064 KB Output is correct
36 Correct 73 ms 10508 KB Output is correct
37 Correct 74 ms 10908 KB Output is correct
38 Correct 73 ms 10668 KB Output is correct
39 Correct 69 ms 9824 KB Output is correct
40 Correct 71 ms 9800 KB Output is correct
41 Correct 69 ms 9808 KB Output is correct
42 Correct 72 ms 9784 KB Output is correct
43 Correct 69 ms 9808 KB Output is correct
44 Correct 68 ms 9436 KB Output is correct
45 Correct 79 ms 9352 KB Output is correct
46 Correct 82 ms 9344 KB Output is correct
47 Correct 64 ms 9532 KB Output is correct
48 Correct 72 ms 9572 KB Output is correct
49 Correct 71 ms 10064 KB Output is correct
50 Correct 77 ms 9976 KB Output is correct
51 Correct 71 ms 10004 KB Output is correct
52 Correct 71 ms 9968 KB Output is correct
53 Correct 81 ms 10092 KB Output is correct