답안 #760133

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
760133 2023-06-17T08:20:57 Z roCatalyst Fruits (NOI22_fruits) C++14
5 / 100
230 ms 9424 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) {
                vector<int> basket;
                ll revenue = 0;
                int max_t = *perm.begin();
                for (int i = 0; i < N ; i++) {
                    if (perm[i] < max_t) {
                        continue;
                    } else {
                        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 - 1; i++) {
            cout << ans[i] << ' ';
        }
        cout << ans[N-1] << endl;
    } else {
        ll revenue = 0;
        for (auto p = C.rbegin(); p + 1 != C.rend(); p++) {
            revenue += *p;
            cout << revenue << ' ';
        }
        revenue += C.front();
        cout << revenue << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 10 ms 776 KB Output is correct
4 Correct 122 ms 4868 KB Output is correct
5 Correct 230 ms 9424 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 153 ms 6508 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 -