답안 #168939

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168939 2019-12-17T09:03:23 Z abil Gift (IZhO18_nicegift) C++14
26 / 100
1814 ms 105016 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const int N = (1e6 + 12);
const int mod = (1e9 + 7);
const int INF = (1e18 + 12);

int a[N], b[N];
vector<pair<int,int > > vec[N];
vector<int > ans[N];
int res[N];

main()
{
	int n, k, sum = 0;
	scanf("%lld%lld", &n, &k);
	for(int i = 1;i <= n; i++){
		scanf("%lld", &a[i]);
		sum += a[i];
	}
	if(sum % k != 0){
		cout << -1;
		return 0;
	}
	int cur_sum = 0;
	int sz = 0;
	for(int i = 1;i <= n; i++){
		cur_sum += a[i];
		if(cur_sum >= sum / k){
			int rem = cur_sum - sum / k;
			cur_sum = rem;
			vec[sz].pb({a[i] - rem, i});
			sz++;
			if(rem > 0){
				vec[sz].pb({rem, i});
			}
		}
		else{
			vec[sz].pb({a[i], i});
		}
	}
	int szofans = 1;
	while(1){
		int mn = INF;
		for(int i = 0;i < sz; i++){
			mn = min(mn, vec[i][b[i]].fr);
		}
		res[szofans] = mn;
		bool f = false;
		for(int i = 0;i < sz; i++){
			vec[i][b[i]].fr -= mn;
			ans[szofans].pb(vec[i][b[i]].sc);
			if(vec[i][b[i]].fr == 0){
				b[i]++;
				if(b[i] == vec[i].size()){
					f = true;
				}
			}
		}
		if(f){
			break;
		}
		szofans++;
	}
	cout << szofans << endl;
	for(int i = 1;i <= szofans; i++){
		cout << res[i] << " ";
		for(auto to : ans[i]){
			cout << to << " ";
		}
		cout << endl;
	}
}

Compilation message

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:63:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(b[i] == vec[i].size()){
        ~~~~~^~~~~~~~~~~~~~~~
nicegift.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
nicegift.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &a[i]);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47352 KB n=4
2 Correct 43 ms 47224 KB n=3
3 Correct 43 ms 47352 KB n=3
4 Correct 42 ms 47328 KB n=4
5 Correct 41 ms 47352 KB n=4
6 Correct 43 ms 47352 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47352 KB n=4
2 Correct 43 ms 47224 KB n=3
3 Correct 43 ms 47352 KB n=3
4 Correct 42 ms 47328 KB n=4
5 Correct 41 ms 47352 KB n=4
6 Correct 43 ms 47352 KB n=2
7 Correct 49 ms 47248 KB n=5
8 Incorrect 43 ms 47224 KB Same heap occurs twice
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47352 KB n=4
2 Correct 43 ms 47224 KB n=3
3 Correct 43 ms 47352 KB n=3
4 Correct 42 ms 47328 KB n=4
5 Correct 41 ms 47352 KB n=4
6 Correct 43 ms 47352 KB n=2
7 Correct 49 ms 47248 KB n=5
8 Incorrect 43 ms 47224 KB Same heap occurs twice
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1814 ms 105016 KB n=1000000
2 Correct 911 ms 83152 KB n=666666
3 Correct 412 ms 67556 KB n=400000
4 Correct 1187 ms 96012 KB n=285714
5 Correct 51 ms 48504 KB n=20000
6 Correct 870 ms 96512 KB n=181818
7 Correct 46 ms 47864 KB n=10000
8 Correct 88 ms 53756 KB n=6666
9 Correct 44 ms 47608 KB n=4000
10 Correct 288 ms 79836 KB n=2857
11 Correct 44 ms 47480 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 47352 KB n=4
2 Correct 43 ms 47224 KB n=3
3 Correct 43 ms 47352 KB n=3
4 Correct 42 ms 47328 KB n=4
5 Correct 41 ms 47352 KB n=4
6 Correct 43 ms 47352 KB n=2
7 Correct 49 ms 47248 KB n=5
8 Incorrect 43 ms 47224 KB Same heap occurs twice
9 Halted 0 ms 0 KB -