Submission #40570

#TimeUsernameProblemLanguageResultExecution timeMemory
40570Just_Solve_The_ProblemGift (IZhO18_nicegift)C++11
7 / 100
979 ms159264 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair < ll, ll > #define fr first #define sc second #define mk make_pair const int N = (int)1e6 + 7; ll sum = 0; ll a[N]; vector < vector < pii > > block; vector < vector < ll > > ans; vector < ll > ans1; int pointer[N]; main() { int n; ll k; scanf("%d %I64d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%I64d", &a[i]); sum += a[i]; } if (sum % k != 0) { puts("-1"); return 0; } sum /= k; vector < pii > vec; vector < ll > v; int in = 1; ll res = 0; while (in <= n) { if (res + a[in] > sum) { vec.pb(mk(a[in] - (res + a[in] - sum), in)); a[in] = res + a[in] - sum; res = sum; } else { vec.pb(mk(a[in], in)); res += a[in]; in++; } if (res == sum) { res = 0; pointer[block.size()] = vec.size() - 1; block.pb(vec); vec.clear(); } } sum *= k; while (sum > 0) { ll mn = 2e18; for (int i = 0; i < k; i++) { mn = min(mn, block[i][pointer[i]].fr); v.pb(block[i][pointer[i]].sc); } sum -= k * mn; for (int i = 0; i < k; i++) { block[i][pointer[i]].fr -= mn; if (block[i][pointer[i]].fr == 0) { pointer[i]--; } } ans.pb(v); v.clear(); ans1.pb(mn); } printf("%d\n", ans.size()); for (int i = 0; i < ans.size(); i++) { printf("%I64d ", ans1[i]); for (int j = 0; j < ans[i].size(); j++) { printf("%I64d ", ans[i][j]); } printf("\n"); } }

Compilation message (stderr)

nicegift.cpp:21:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
nicegift.cpp: In function 'int main()':
nicegift.cpp:22:40: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   int n; ll k; scanf("%d %I64d", &n, &k);
                                        ^
nicegift.cpp:24:25: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
     scanf("%I64d", &a[i]);
                         ^
nicegift.cpp:71:28: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::vector<long long int> >::size_type {aka long unsigned int}' [-Wformat=]
   printf("%d\n", ans.size());
                            ^
nicegift.cpp:72:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < ans.size(); i++) {
                     ^
nicegift.cpp:73:29: 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 ", ans1[i]);
                             ^
nicegift.cpp:74:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < ans[i].size(); j++) {
                       ^
nicegift.cpp:75:33: 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:22:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int n; ll k; scanf("%d %I64d", &n, &k);
                                         ^
nicegift.cpp:24:26: 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...