답안 #789270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789270 2023-07-21T08:44:58 Z 이동현(#10044) Cookies (JOI23_cookies) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define int long long
#define mi(x, y) (x = min(x, y))
#define ma(x, y) (x = max(x, y))
using namespace std;

const int NS = 15004;
const int SZ = 504;
int n, m;
int a[NS], b[NS];
int mn[NS];
bool dp[NS][SZ][SZ];
pair<int, int> srt[NS];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    int asum = 0;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        srt[i] = {a[i], i};
        asum += a[i];
    }
    cin >> m;
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
    }

    sort(b + 1, b + m + 1);
    reverse(b + 1, b + m + 1);

    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            mn[i] += min(i, a[j]);
        }
        mn[i] = min(mn[i], 500ll);
    }

    dp[0][0][0] = 1;
    for(int i = 1; i <= m; ++i){
        for(int j = 0; j <= SZ - 4; ++j){
            for(int k = 0; k <= mn[j]; ++k){
                if(dp[i - 1][j][k]){
                    dp[i][j][k] = 1;
                }
                if(j && k >= b[i] && dp[i][j - 1][k - b[i]]){
                    dp[i][j][k] = 1;
                }
            }
        }
    }

    int ans = -1;
    for(int i = 1; i <= SZ - 4; ++i){
        if(dp[m][i][asum]){
            ans = i;
            break;
        }
    }

    cout << ans << '\n';
    if(ans == -1){
        return 0;
    }
    vector<int> lst;
    auto makelst = [&](auto&&self, int i, int j, int k)->void{
        if(!i) return;
        if(dp[i - 1][j][k]){
            self(self, i - 1, j, k);
        }
        else{
            self(self, i, j - 1, k - b[i]);
            lst.push_back(b[i]);
        }
    };
    makelst(makelst, m, ans, asum);

    for(auto&i:lst){
        cout << i << ' ';
        sort(srt + 1, srt + n + 1);
        reverse(srt + 1, srt + n + 1);
        while(!srt[n].first){
            --n;
        }

        for(int j = 1; j <= i; ++j){
            assert(srt[j].first >= 1);
            --srt[j].first;
            cout << srt[j].second << ' ';
        }
        cout << '\n';
    }

    assert(srt[0].first == 0);
    
    return 0;
}

Compilation message

/tmp/ccAKtahh.o: in function `void main::{lambda(auto:1&&, long long, long long, long long)#1}::operator()<{lambda(auto:1&&, long long, long long, long long)#1}&>({lambda(auto:1&&, long long, long long, long long)#1}&, long long, long long, long long) const':
cookies.cpp:(.text+0x8f2): relocation truncated to fit: R_X86_64_PC32 against symbol `b' defined in .bss section in /tmp/ccAKtahh.o
/tmp/ccAKtahh.o: in function `main':
cookies.cpp:(.text.startup+0x2c): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccAKtahh.o
cookies.cpp:(.text.startup+0x33): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
cookies.cpp:(.text.startup+0x3a): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
cookies.cpp:(.text.startup+0x4a): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccAKtahh.o
cookies.cpp:(.text.startup+0x61): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccAKtahh.o
cookies.cpp:(.text.startup+0x74): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
cookies.cpp:(.text.startup+0xa4): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccAKtahh.o
cookies.cpp:(.text.startup+0xad): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccAKtahh.o
cookies.cpp:(.text.startup+0xb4): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
cookies.cpp:(.text.startup+0xc0): additional relocation overflows omitted from the output
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status