답안 #757928

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757928 2023-06-14T02:00:12 Z Dexva Fruits (NOI22_fruits) C++14
6 / 100
84 ms 9344 KB
#include <bits/stdc++.h>
using namespace std;

#define lln long long

void solve() {
    int n; cin >> n;
    int ans[n], ref[n], cost[n];
    for (int i=0;i<n;i++) ans[i] = 0;
    for (int i=0;i<n;i++) cin >> ref[i];
    for (int i=0;i<n;i++) cin >> cost[i];
    
    vector<int> cur; //what we will permutate over
    for (int i=0;i<n;i++) {
        cur.push_back(i);
    }

    if (n<=8) { // do brute force solution
        do {
            bool ok = true;
            for (int i=0;i<n;i++) {
                if (ref[i]!=-1 && ref[i]-1!=cur[i]) {
                    ok = false;
                    break;
                }
            }
            if (!ok) continue;
            // else {
            //     for (int i=0;i<n;i++) cout << cur[i] << " ";
            //     cout << '\n';
            // }

            int cursum = 0, maxtaste = -1;
            for (int k=0;k<n;k++) {
                if (cur[k]>maxtaste) {
                    cursum += cost[cur[k]];
                    maxtaste = cur[k];
                }
                // if (cursum > ans[k]) {
                //     cout << k << " | | " << "current perm: ";
                //     for (int i=0;i<n;i++) cout << cur[i] << " ";
                //     cout << '\n';
                // }
                ans[k] = max(ans[k], cursum);
            }
        } while (next_permutation(cur.begin(),cur.end()));
    } 

    else {
        int cursum = 0;
        for (int k=n-1;k>=0;k--) {
            cursum += cost[k];
            ans[n-k-1] = cursum;
        }
    } //do dumb greedy solution

    for (int k=0;k<n;k++) {
        cout << ans[k] << " ";
    } cout << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    while (t--) solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 84 ms 9344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Incorrect 1 ms 384 KB Output isn't correct
13 Halted 0 ms 0 KB -