답안 #760149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
760149 2023-06-17T08:35:00 Z roCatalyst Fruits (NOI22_fruits) C++14
5 / 100
182 ms 9016 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) {
                /*
                for (auto p = perm.begin();p!=perm.end();p++) {
                    cout << *p << ' ';
                }

                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';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 9 ms 788 KB Output is correct
4 Correct 109 ms 4700 KB Output is correct
5 Correct 182 ms 9016 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 139 ms 6260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -