# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
92348 |
2019-01-02T14:35:13 Z |
Pajaraja |
Gift (IZhO18_nicegift) |
C++17 |
|
2000 ms |
46076 KB |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b)
{
if(a==0) return b;
return gcd(b%a,a);
}
int main()
{
long long n,k,cnt=0;
long long t,sum=0,mi=1000000000000000000LL;
scanf("%lld%lld",&n,&k);
priority_queue<pair<long long,int> > pq,pq1;
for(int i=0;i<n;i++) {scanf("%lld",&t); pq.push(make_pair(t,i+1)); pq1.push(make_pair(t,i+1)); mi=min(mi,t); sum+=t;}
if(sum%k!=0) {printf("-1"); return 0;}
while(pq.size()>=k && mi!=pq.top().first)
{
stack<pair<long long,int> > st;
for(int i=0;i<k;i++) {st.push(pq.top()); pq.pop();}
long long f=st.top().first;
if(!pq.empty()) f-=pq.top().first;
f=max(f,1LL);
for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq.push(st.top()); mi=min(mi,st.top().first); st.pop();}
cnt++;
}
if(pq.size()%n!=0) {printf("-1"); return 0;}
if(!pq.empty() && pq.top().first%(k/gcd(n,k))!=0) {printf("-1"); return 0;}
if(pq.empty()) printf("%lld\n",cnt);
else printf("%lld\n",cnt+(n*mi)/(k*(mi/(k/gcd(n,k)))));
while(cnt--)
{
stack<pair<long long,int> > st;
for(int i=0;i<k;i++) {st.push(pq1.top()); pq1.pop();}
long long f=st.top().first;
if(!pq1.empty()) f-=pq1.top().first;
f=max(f,1LL);
printf("%lld ",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");
}
long long f=pq.top().first/(k/gcd(n,k));
while(pq.size()>=k)
{
stack<pair<long long,int> > st;
for(int i=0;i<k;i++) {st.push(pq.top()); pq.pop();}
printf("%lld ",f);
for(int i=0;i<k;i++) {st.top().first-=f; if(st.top().first!=0) pq.push(st.top()); printf("%d ",st.top().second); st.pop();}
printf("\n");
}
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:16:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(pq.size()>=k && mi!=pq.top().first)
~~~~~~~~~^~~
nicegift.cpp:42:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(pq.size()>=k)
~~~~~~~~~^~~
nicegift.cpp:12: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:14: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("%lld",&t); pq.push(make_pair(t,i+1)); pq1.push(make_pair(t,i+1)); mi=min(mi,t); sum+=t;}
~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
256 KB |
n=3 |
4 |
Correct |
2 ms |
256 KB |
n=4 |
5 |
Correct |
2 ms |
256 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
256 KB |
n=3 |
4 |
Correct |
2 ms |
256 KB |
n=4 |
5 |
Correct |
2 ms |
256 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
256 KB |
n=8 |
9 |
Correct |
9 ms |
376 KB |
n=14 |
10 |
Correct |
6 ms |
376 KB |
n=11 |
11 |
Correct |
89 ms |
2656 KB |
n=50000 |
12 |
Correct |
52 ms |
2788 KB |
n=50000 |
13 |
Correct |
24 ms |
632 KB |
n=10 |
14 |
Correct |
17 ms |
504 KB |
n=685 |
15 |
Correct |
12 ms |
504 KB |
n=623 |
16 |
Correct |
12 ms |
504 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
256 KB |
n=3 |
4 |
Correct |
2 ms |
256 KB |
n=4 |
5 |
Correct |
2 ms |
256 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
256 KB |
n=8 |
9 |
Correct |
9 ms |
376 KB |
n=14 |
10 |
Correct |
6 ms |
376 KB |
n=11 |
11 |
Correct |
89 ms |
2656 KB |
n=50000 |
12 |
Correct |
52 ms |
2788 KB |
n=50000 |
13 |
Correct |
24 ms |
632 KB |
n=10 |
14 |
Correct |
17 ms |
504 KB |
n=685 |
15 |
Correct |
12 ms |
504 KB |
n=623 |
16 |
Correct |
12 ms |
504 KB |
n=973 |
17 |
Correct |
15 ms |
504 KB |
n=989 |
18 |
Correct |
8 ms |
376 KB |
n=563 |
19 |
Correct |
12 ms |
504 KB |
n=592 |
20 |
Correct |
15 ms |
504 KB |
n=938 |
21 |
Correct |
10 ms |
504 KB |
n=747 |
22 |
Correct |
13 ms |
508 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
580 ms |
46076 KB |
n=1000000 |
2 |
Correct |
382 ms |
29264 KB |
n=666666 |
3 |
Correct |
202 ms |
16944 KB |
n=400000 |
4 |
Correct |
550 ms |
26448 KB |
n=285714 |
5 |
Correct |
10 ms |
1368 KB |
n=20000 |
6 |
Correct |
477 ms |
21324 KB |
n=181818 |
7 |
Correct |
6 ms |
884 KB |
n=10000 |
8 |
Correct |
60 ms |
2296 KB |
n=6666 |
9 |
Correct |
2 ms |
504 KB |
n=4000 |
10 |
Correct |
339 ms |
9692 KB |
n=2857 |
11 |
Correct |
2 ms |
376 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
256 KB |
n=3 |
4 |
Correct |
2 ms |
256 KB |
n=4 |
5 |
Correct |
2 ms |
256 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
256 KB |
n=8 |
9 |
Correct |
9 ms |
376 KB |
n=14 |
10 |
Correct |
6 ms |
376 KB |
n=11 |
11 |
Correct |
89 ms |
2656 KB |
n=50000 |
12 |
Correct |
52 ms |
2788 KB |
n=50000 |
13 |
Correct |
24 ms |
632 KB |
n=10 |
14 |
Correct |
17 ms |
504 KB |
n=685 |
15 |
Correct |
12 ms |
504 KB |
n=623 |
16 |
Correct |
12 ms |
504 KB |
n=973 |
17 |
Correct |
15 ms |
504 KB |
n=989 |
18 |
Correct |
8 ms |
376 KB |
n=563 |
19 |
Correct |
12 ms |
504 KB |
n=592 |
20 |
Correct |
15 ms |
504 KB |
n=938 |
21 |
Correct |
10 ms |
504 KB |
n=747 |
22 |
Correct |
13 ms |
508 KB |
n=991 |
23 |
Correct |
580 ms |
46076 KB |
n=1000000 |
24 |
Correct |
382 ms |
29264 KB |
n=666666 |
25 |
Correct |
202 ms |
16944 KB |
n=400000 |
26 |
Correct |
550 ms |
26448 KB |
n=285714 |
27 |
Correct |
10 ms |
1368 KB |
n=20000 |
28 |
Correct |
477 ms |
21324 KB |
n=181818 |
29 |
Correct |
6 ms |
884 KB |
n=10000 |
30 |
Correct |
60 ms |
2296 KB |
n=6666 |
31 |
Correct |
2 ms |
504 KB |
n=4000 |
32 |
Correct |
339 ms |
9692 KB |
n=2857 |
33 |
Correct |
2 ms |
376 KB |
n=2000 |
34 |
Execution timed out |
2077 ms |
1392 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |