제출 #92787

#제출 시각아이디문제언어결과실행 시간메모리
92787VardanyanGift (IZhO18_nicegift)C++14
30 / 100
1367 ms118932 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1000*1000+5; pair<long long,int> a[N]; int main() { int n,k; scanf("%d%d",&n,&k); long long sum = 0; long long mns = 1; set<pair<long long,int >,greater<pair<long long,int> > > ms; for(int i = 1;i<=n;i++){ scanf("%lld",&a[i].first); a[i].second = i; sum+=a[i].first; ms.insert(a[i]); } sort(a+1,a+1+n); if(sum>1000*100){ long long x = k/__gcd(n,k); if(a[n].first%x){ printf("-1\n"); return 0; } mns = a[n].first/x; } vector<vector<int> > ans; while(1){ int kk = k; vector<int> now; set<pair<long long,int> >::iterator it = ms.begin(); vector<pair<long long,int> > add; for(;it!=ms.end();it++){ pair<long long,int> x = *it; if(x.first-mns<0){ printf("-1\n"); return 0; } //x.first--; sum-=mns; now.push_back(x.second); kk--; add.push_back(x); if(kk == 0) break; } for(int i = 0;i<add.size();i++){ ms.erase(ms.find(add[i])); add[i].first-=mns; ms.insert(add[i]); } ans.push_back(now); if(sum == 0) break; } printf("%d\n",ans.size()); for(int i = 0;i<ans.size();i++){ printf("%d ",mns); for(int j = 0;j<ans[i].size();j++){ printf("%lld ",ans[i][j]); } printf("\n"); } return 0; }

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

nicegift.cpp: In function 'int main()':
nicegift.cpp:47:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0;i<add.size();i++){
                       ~^~~~~~~~~~~
nicegift.cpp:55:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::vector<int> >::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n",ans.size());
                   ~~~~~~~~~~^
nicegift.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<ans.size();i++){
                   ~^~~~~~~~~~~
nicegift.cpp:57:25: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
         printf("%d ",mns);
                         ^
nicegift.cpp:58:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0;j<ans[i].size();j++){
                       ~^~~~~~~~~~~~~~
nicegift.cpp:59:37: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' [-Wformat=]
             printf("%lld ",ans[i][j]);
                                     ^
nicegift.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~
nicegift.cpp:14:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld",&a[i].first);
             ~~~~~^~~~~~~~~~~~~~~~~~~~
#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...