제출 #334624

#제출 시각아이디문제언어결과실행 시간메모리
334624beksultan04Gift (IZhO18_nicegift)C++14
100 / 100
829 ms143672 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define OK puts("OK"); #define fr first #define sc second #define ret return #define scan1(a) scanf("%lld",&a); #define scan2(a,b) scanf("%lld %lld",&a, &b); #define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c); #define all(s) s.begin(),s.end() #define pb push_back #define endi puts(""); const int N = 1e6+12,INF=1e18+7; vector <pii> v[N]; vector <int> ans[N]; int q[N]; main(){ int n,k,i,j,sum=0,cnt=0,mx=0,aa=0; scan2(n,k) for (i=0;i<n;++i) scan1(q[i]); for (i=0;i<n;++i){ mx = max(mx,q[i]); sum+=q[i]; } if (mx*k > sum || sum%k > 0){ cout <<-1; ret 0; } else { int sz = sum/k,c=0; for (i=0;i<n;++i){ if (c+q[i] >= sz){ int x = c+q[i]-sz; v[cnt++].pb({q[i]-x,i+1}); c = (q[i]-(q[i]-x)); v[cnt].pb({c,i+1}); } else { c+=q[i]; v[cnt].pb({q[i],i+1}); } } bool f=1; while (f){ f=0; int mn = INF; for (i=0;i<k;++i){ mn = min(mn,v[i].back().fr); } ans[aa].pb(mn); for (i=0;i<k;++i){ pii x = v[i].back(); v[i].pop_back(); x.fr -= mn; ans[aa].pb(x.sc); if (x.fr > 0){ v[i].pb(x); } } f |= !v[0].empty(); aa++; } cout <<aa<<"\n"; for (i=0;i<aa;++i){ for (j=0;j<ans[i].size();++j){ cout <<ans[i][j]<<" "; } endi } } }

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

nicegift.cpp:20:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   20 | main(){
      |      ^
nicegift.cpp: In function 'int main()':
nicegift.cpp:70:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for (j=0;j<ans[i].size();++j){
      |                      ~^~~~~~~~~~~~~~
nicegift.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
nicegift.cpp:22:5: note: in expansion of macro 'scan2'
   22 |     scan2(n,k)
      |     ^~~~~
nicegift.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
nicegift.cpp:24:9: note: in expansion of macro 'scan1'
   24 |         scan1(q[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...