제출 #168473

#제출 시각아이디문제언어결과실행 시간메모리
168473achibasadzishviliGift (IZhO18_nicegift)C++14
30 / 100
1629 ms172180 KiB
#include <bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back #define mp make_pair using namespace std; ll n,k,a[2000005],s,las,p,cur,maxi,l,r,mid,can; set<pair<ll,ll> >st; vector<vector<ll> >ans; vector<ll>g; int main(){ scanf("%I64d%I64d",&n,&k); bool ok = 1; for(int i=1; i<=n; i++){ scanf("%I64d",&a[i]); if(a[i] != a[1])ok = 0; s += a[i]; st.insert(mp(-a[i] , i)); } if(s % k){ cout << "-1"; return 0; } ll raod = s / k; ll sum = s; ll ra = 0; while(sum){ if((int)st.size() < k){ cout << "-1"; return 0; } p = 0,cur = 0; g.clear(); maxi = -(*st.begin()).f; for(set<pair<ll,ll> >::iterator it = st.begin(); it != st.end(); it++){ p++; if(p > k){ cur = (*it).s; break; } las = (*it).s; } l = 1 , r = a[las] , mid , can = 1; while(r >= l){ mid = (l + r) / 2; if(max(maxi - mid , a[cur]) * k <= sum - mid * k){ l = mid + 1; can = mid; } else { r = mid - 1; } } sum -= can * k; ra += k; p = 0; g.pb(can); for(set<pair<ll,ll> >::iterator it = st.begin(); it != st.end(); it++){ p++; if(p > k){ cur = (*it).s; break; } g.pb((*it).s); } for(int i=1; i<g.size(); i++){ st.erase(mp(-a[g[i]] , g[i])); a[g[i]]-=can; if(a[g[i]])st.insert(mp(-a[g[i]] , g[i])); } ans.pb(g); } printf("%d\n",(int)ans.size()); for(int i=0; i<ans.size(); i++){ for(int j=0; j<ans[i].size(); j++) printf("%I64d " , ans[i][j]); printf("\n"); } return 0; }

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

nicegift.cpp: In function 'int main()':
nicegift.cpp:13:29: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
     scanf("%I64d%I64d",&n,&k);
                        ~~   ^
nicegift.cpp:13:29: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
nicegift.cpp:16:28: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
         scanf("%I64d",&a[i]);
                       ~~~~~^
nicegift.cpp:46:42: warning: right operand of comma operator has no effect [-Wunused-value]
         l = 1 , r = a[las] , mid , can = 1;
                                          ^
nicegift.cpp:69:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=1; i<g.size(); i++){
                      ~^~~~~~~~~
nicegift.cpp:79:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<ans.size(); i++){
                  ~^~~~~~~~~~~
nicegift.cpp:80:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0; j<ans[i].size(); j++)
                      ~^~~~~~~~~~~~~~
nicegift.cpp:81:40: warning: format '%d' expects argument of type 'int', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type {aka long long int}' [-Wformat=]
             printf("%I64d " , ans[i][j]);
                                        ^
nicegift.cpp:14:10: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
     bool ok = 1;
          ^~
nicegift.cpp:27:8: warning: unused variable 'raod' [-Wunused-variable]
     ll raod = s / k;
        ^~~~
nicegift.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%I64d%I64d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~~~
nicegift.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%I64d",&a[i]);
         ~~~~~^~~~~~~~~~~~~~~
#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...