답안 #48524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48524 2018-05-15T12:56:36 Z Pajaraja Gift (IZhO18_nicegift) C++17
0 / 100
2000 ms 31596 KB
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,t,cnt=0;
	scanf("%d%d",&n,&k);
	priority_queue<pair<int,int> > pq,pq1;
	for(int i=0;i<n;i++) {scanf("%d",&t); pq.push(make_pair(t,i+1)); pq1.push(make_pair(t,i+1));}
	while(pq.size()>=k)
	{
		stack<pair<int,int> > st;
		for(int i=0;i<k;i++) {st.push(pq.top()); pq.pop();}
		int f=st.top().first-pq.empty()?st.top().first:(pq.top().first-1);
		for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq.push(st.top()); st.pop();}
		cnt++;
	}
	if(!pq.empty()) {printf("-1"); return 0;}
	printf("%d\n",cnt);
	while(pq1.size()>=k)
	{
		stack<pair<int,int> > st;
		for(int i=0;i<k;i++) {st.push(pq1.top()); pq1.pop();}
		int f=st.top().first-pq1.empty()?st.top().first:(pq1.top().first-1);
		printf("%d ",f);
		for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq1.push(st.top()); printf("%d ",st.top().second); st.pop();}
		printf("\n");
	}
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:9:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq.size()>=k)
        ~~~~~~~~~^~~
nicegift.cpp:19:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pq1.size()>=k)
        ~~~~~~~~~~^~~
nicegift.cpp:6:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~
nicegift.cpp:8:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) {scanf("%d",&t); pq.push(make_pair(t,i+1)); pq1.push(make_pair(t,i+1));}
                        ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n=4
2 Execution timed out 2043 ms 492 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n=4
2 Execution timed out 2043 ms 492 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n=4
2 Execution timed out 2043 ms 492 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 922 ms 31596 KB Added number should be positive
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n=4
2 Execution timed out 2043 ms 492 KB Time limit exceeded
3 Halted 0 ms 0 KB -