제출 #881301

#제출 시각아이디문제언어결과실행 시간메모리
881301dimashhhGift (IZhO18_nicegift)C++17
7 / 100
569 ms192672 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6 + 1; #define int long long int n,k; ll a[N]; set<pair<ll,ll>> st; vector<pair<vector<int>,int>> res(N * 3); void test(){ cin >> n >> k; for(int i = 1;i <= n;i++){ cin >> a[i]; st.insert({a[i],i}); } int it = 1; while(!st.empty()){ if((int)(it - 1) * k > 3e6||st.size() < k){ cout << -1 << '\n'; return; } vector<int> f; int oo; for(int i = 1;i <= k;i++){ auto [x,y] = *st.rbegin(); st.erase({x,y}); oo = x; f.push_back(y); } res[it] = {f,oo}; it++; for(auto j:f){ a[j] -= oo; if(a[j]){ st.insert({a[j],j}); } } } cout << it - 1 << '\n'; for(int f = 1;f < it;f++){ cout << res[f].second << ' '; for(auto j:res[f].first) cout << j << ' '; cout << '\n'; } } main(){ ios_base::sync_with_stdio(0);cin.tie(0); int T = 1; // cin >> T; while(T--) test(); }

컴파일 시 표준 에러 (stderr) 메시지

nicegift.cpp: In function 'void test()':
nicegift.cpp:18:47: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   18 |         if((int)(it - 1) * k > 3e6||st.size() < k){
      |                                     ~~~~~~~~~~^~~
nicegift.cpp: At global scope:
nicegift.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main(){
      | ^~~~
nicegift.cpp: In function 'void test()':
nicegift.cpp:33:18: warning: 'oo' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |             a[j] -= oo;
      |             ~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...