답안 #338244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
338244 2020-12-22T20:00:02 Z Kerim Gift (IZhO18_nicegift) C++17
0 / 100
486 ms 75616 KB
#include "bits/stdc++.h"
#define MAXN 1000009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
ll arr[MAXN];
vector<pair<ll,int> >adj[MAXN];
const ll B=2e18;
int main(){
  //  freopen("file.in", "r", stdin);
    int n,k,tmp=0;
    scanf("%d%d",&n,&k);
    ll sum=0,mx=0,cur=0;
    for(int i=1;i<=n;i++)
    	scanf("%lld",arr+i),sum+=arr[i],umax(mx,arr[i]);
	if(sum%k!=0 or mx>sum/k)
		return printf("-1\n")*0;
	for(int i=1;i<=n;i++){
		cur+=arr[i];
		if(cur>=sum/k){
			adj[tmp++].pb(mp(sum/k-cur+arr[i],i));
			if(cur>sum/k)
				adj[tmp].pb(mp(cur-sum/k,i));
			cur=0;
		}
		else
			adj[tmp].pb(mp(arr[i],i));
	}assert(tmp==k);
	for(int i=0;i<k;i++)
		reverse(all(adj[i]));
	while(!adj[0].empty()){
		ll mn=B;
		for(int i=0;i<k;i++)
			umin(mn,adj[i].back().ff);
		printf("%lld ",mn);
		for(int i=0;i<k;i++){
			printf("%d ",adj[i].back().ss);
			if(adj[i].back().ff==mn)
				adj[i].ppb();
			else
				adj[i].back().ff-=mn;
		}puts("");
	}
	return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:28:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   28 |     for(int i=1;i<=n;i++)
      |     ^~~
nicegift.cpp:30:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   30 |  if(sum%k!=0 or mx>sum/k)
      |  ^~
nicegift.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     scanf("%d%d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~
nicegift.cpp:29:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |      scanf("%lld",arr+i),sum+=arr[i],umax(mx,arr[i]);
      |      ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 23788 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 23788 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 23788 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 486 ms 75616 KB Expected int32, but "1000000000000" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 23788 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -