제출 #1362523

#제출 시각아이디문제언어결과실행 시간메모리
1362523AvianshSequence (BOI23_sequence)C++20
11 / 100
1 ms348 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int w[n+1];
    for(int i = 1;i<=n;i++){
        cin >> w[i];
    }
    set<int>req[n+1];
    req[1].insert(1);
    cout << w[1] << " ";
    for(int i = 2;i<=n;i++){
        vector<set<int>>pos;
        set<int>las;
        for(int z : req[i-1]){
            las.insert(z);
        }
        las.insert(i);
        pos.push_back(las);
        for(int j = 2;j<i;j++){
            if(i%j==0){
                //divides
                int a = j;
                int b = i/j;
                set<int>curr;
                for(int z : req[a]){
                    curr.insert(z);
                }
                for(int z : req[b]){
                    curr.insert(z);
                }
                curr.insert(i);
                pos.push_back(curr);
            }
        }
        int besti = 0;
        int bestcost = 0;
        for(int i : pos[0]){
            bestcost+=w[i];
        }
        for(int i = 1;i<pos.size();i++){
            int curcost = 0;
            for(int j : pos[i]){
                curcost+=w[j];
            }
            if(curcost<bestcost){
                besti=i;
                bestcost=curcost;
            }
        }
        req[i]=pos[besti];
        cout << bestcost << " ";
    }
    return 0;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…