답안 #970682

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970682 2024-04-27T04:56:13 Z huutuan Cookies (JOI23_cookies) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
 
using namespace std;

#ifdef sus
const int N=100;
#else
const int N=15e3+10;
#endif
bool f[N][N][N];
int n, m, a[N], b[N], pf[N], c[N], _a[N];
 
int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cin >> n;
   for (int i=1; i<=n; ++i) cin >> _a[i];
   cin >> m;
   for (int i=1; i<=m; ++i) cin >> b[i], c[b[i]]=1;
   for (int i=1; i<=n; ++i) a[i]=_a[i];
   int sum=accumulate(a+1, a+n+1, 0);
   sort(a+1, a+n+1, greater<int>());
   for (int i=1, j=n; i<=sum; ++i){
      pf[i]=pf[i-1]+j;
      while (j && a[j]==i) --j;
   }
   for (int i=0; i<=sum; ++i) f[0][i][0]=1;
   vector<int> sz;
   for (int i=1; i<=sum; ++i){
      for (int j=sum/i; j>=0; --j){
         for (int k=i*j; k<=pf[i]; ++k){
            f[i][j][k]|=f[i][j+1][k];
            if (c[j]) f[i][j][k]|=f[i-1][j][k-j];
            if (k==sum && f[i][j][k]){
               while (i){
                  if (c[j] && k>=j && f[i-1][j][k-j]){
                     sz.push_back(j);
                     --i;
                     k-=j;
                  }else ++j;
               }
               goto done;
            }
         }
      }
   }
   cout << -1 << '\n';
   return 0;
done:
   reverse(sz.begin(), sz.end());
   priority_queue<pair<int, int>> pq;
   vector<vector<int>> ans;
   for (int i=1; i<=n; ++i) a[i]=_a[i];
   for (int i=1; i<=n; ++i) pq.emplace(a[i], i);
   for (int i:sz){
      ans.emplace_back();
      for (int j=0; j<i; ++j){
         if (pq.empty()){
            cout << -1 << '\n';
            return 0;
         }
         ans.back().push_back(pq.top().second);
         pq.pop();
      }
      for (int j:ans.back()){
         --a[j];
         if (a[j]) pq.emplace(a[j], j);
      }
   }
   cout << ans.size() << '\n';
   for (auto &i:ans){
      cout << i.size();
      for (int j:i) cout << ' ' << j;
      cout << '\n';
   }
   return 0;
}

Compilation message

/tmp/ccx8ifju.o: in function `main':
cookies.cpp:(.text.startup+0x11): 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+0x45): 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+0x53): 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+0x94): 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+0xb9): 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+0x5ee): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
cookies.cpp:(.text.startup+0x8c7): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
cookies.cpp:(.text.startup+0x922): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
cookies.cpp:(.text.startup+0x939): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
cookies.cpp:(.text.startup+0x984): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(globals_io.o)
cookies.cpp:(.text.startup+0x9d0): 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