답안 #495362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495362 2021-12-18T14:04:16 Z vinnipuh01 Gift (IZhO18_nicegift) C++17
0 / 100
232 ms 524292 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long

using namespace std;

const long long oo = 1000000000000000000;

long long  sum, ans = 0, mx = 0, mn = 1000000000, num, pos;


/*
    ViHHiPuh

   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))


    cout << fixed << setprecision(6) << x;


    freopen ( "sum.in", "r", stdin )
*/

deque <pair<int, int> > v[ 1000001 ];
vector <vector <int > > v1;
vector <int> vv;

main () {
	int n, m;
	cin >> n >> m;
	int a[ n + 1 ];
	for ( int i = 0; i < n; i ++ ) {
		cin >> a[ i ];
		sum += a[ i ];
		mx = max( mx, a[ i ] );
	}
	if ( sum % m != 0 || mx > sum / m )
		cout << "-1";
	else {
		for ( int i = 0; i < n; i ++ ) {
			num += a[ i ];
			if ( num > sum / m ) {
				num -= a[ i ];
				v[ i / m ].push_back( { ( sum / m ) - num, i } );
				num -= sum / m;
				v[ ( i + 1 ) / m ].push_back( { num, i } );
				num = 0;
			}
			else {
				v[ i / m ].push_back( { a[ i ], i } );
				if ( num == sum / m )
					num = 0;
			}
		}
		while ( true ) {
			num = oo;
			for ( int i = 0; i < m; i ++ ) {
				num = min( num, v[ i ].front().first + 0ll );
			}
			ans += num;
			vv.clear();
			vv.push_back( num );
			for ( int i = 0; i < m; i ++ ) {
				vv.push_back( v[ i ].front().second );
				v[ i ].front().first -= num;
				if ( !v[ i ].front().first )
					v[ i ].pop_front();
			}
			v1.push_back( vv );
			if ( ans == sum / m )
				break;
		}
		cout << v1.size() << "\n";
		for ( auto i : v1 ) {
			cout << i.front() << " ";
			for ( int j = 1; j < i.size(); j ++ )
				cout << i[ j ] + 1 << " ";
			cout << "\n";
		}
	}
}

Compilation message

nicegift.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main () {
      | ^~~~
nicegift.cpp: In function 'int main()':
nicegift.cpp:96: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]
   96 |    for ( int j = 1; j < i.size(); j ++ )
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 211 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 211 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 211 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 232 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 211 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -