답안 #761841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761841 2023-06-20T10:23:51 Z sysia Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
84 ms 15484 KB
//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;

void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << "'" << x << "'";}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long
typedef pair<int, int> T;
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;

void solve(){
    int n; cin >> n;
    vector<T>a(n+1);
    for (int i = 0; i<=n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    vector<int>b(n);
    for (auto &x: b) cin >> x;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    debug(a);
    debug(b);
    vector<int>pref(n+1), suf(n+2);
    for (int i = 0; i<n; i++){
        pref[i] = max((i ? pref[i-1] : 0), max(a[i].first - b[i], 0ll));
    }
    for (int i = n; i>0; i--){
        suf[i] = max((i == n ? 0 : suf[i+1]), max(a[i].first - b[i-1], 0ll));
    }
    debug(pref);
    debug(suf);
    vector<int>ans(n+1);
    for (int i = 0; i<=n; i++){
        ans[a[i].second] = max((i ? pref[i-1] : 0ll), suf[i+1]);
    }
    for (int i = 0; i<=n; i++) cout << ans[i] << " ";
    cout << "\n";
}

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

    int t = 1;
    //cin >> t;
    while (t--) solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 316 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 316 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 456 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 316 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 456 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 84 ms 14360 KB Output is correct
34 Correct 74 ms 15052 KB Output is correct
35 Correct 71 ms 14508 KB Output is correct
36 Correct 84 ms 14956 KB Output is correct
37 Correct 74 ms 15484 KB Output is correct
38 Correct 74 ms 15284 KB Output is correct
39 Correct 71 ms 14284 KB Output is correct
40 Correct 71 ms 14212 KB Output is correct
41 Correct 72 ms 14460 KB Output is correct
42 Correct 71 ms 14372 KB Output is correct
43 Correct 70 ms 14232 KB Output is correct
44 Correct 69 ms 13736 KB Output is correct
45 Correct 77 ms 13928 KB Output is correct
46 Correct 69 ms 13756 KB Output is correct
47 Correct 66 ms 14092 KB Output is correct
48 Correct 67 ms 14064 KB Output is correct
49 Correct 73 ms 14668 KB Output is correct
50 Correct 72 ms 14668 KB Output is correct
51 Correct 72 ms 14676 KB Output is correct
52 Correct 72 ms 14668 KB Output is correct
53 Correct 73 ms 14652 KB Output is correct