Submission #760144

# Submission time Handle Problem Language Result Execution time Memory
760144 2023-06-17T08:32:57 Z roCatalyst Fruits (NOI22_fruits) C++14
5 / 100
178 ms 9020 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    int N;
    cin >> N;

    vector<int> A;
    for (int i = 0; i < N; i++) {
        int Ai;
        cin >> Ai;
        A.push_back(Ai);
    }

    vector<int> C;
    for (int i = 0; i < N; i++) {
        int Ci;
        cin >> Ci;
        C.push_back(Ci);
    }

    if (N <= 8) {
        vector<int> perm;
        for (int i = 1; i <= N; i++) {
            perm.push_back(i);
        }

        vector<ll> ans (N,0);
        do {
            bool valid = true;
            for (int i = 0; i < N; i++) {
                if (A[i] != -1) {
                    //check if i is in position A[i]
                    if (perm[i]!=A[i]) {
                        valid = false;
                        break;
                    }
                }
            }

            if (valid) {
                cout << endl;
                vector<int> basket;
                ll revenue = 0;
                int max_t = 0;
                for (int i = 0; i < N ; i++) {
                    if (perm[i] > max_t) {
                        max_t = perm[i];
                        revenue += C[perm[i]-1];
                        ans[i] = max(ans[i],revenue);
                    }
                }
            }
        } while (next_permutation(perm.begin(),perm.end()));

        for (int i = 0; i < N; i++) {
            cout << ans[i];
            if (i < N-1) {
                cout << ' ';
            } else {
                cout << '\n';
            }
        }
    } else {
        ll revenue = 0;
        for (auto p = C.rbegin(); p + 1 != C.rend(); p++) {
            revenue += *p;
            cout << revenue << ' ';
        }
        revenue += C.front();
        cout << revenue << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 9 ms 724 KB Output is correct
4 Correct 94 ms 4664 KB Output is correct
5 Correct 178 ms 9020 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 128 ms 6144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -