# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
48870 |
2018-05-19T11:35:59 Z |
mrtsima22 |
Gift (IZhO18_nicegift) |
C++17 |
|
2000 ms |
232648 KB |
#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
int n,k;
long long a[1000003],sum,p;
set<pair<long long,int> >s;
vector<vector<int> > ans;
int main(){std::ios::sync_with_stdio(false);
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum=sum+a[i];
}
bool ok=1;
for(int i=2;i<=n;i++)
{
ok=ok&(a[i]==a[i-1]);
}
if(sum%k!=0){
cout<<-1<<endl;return 0;}
for(int i=1;i<=n;i++)
{
s.insert(make_pair(a[i],i));
}
p=1;
if(ok){
p=sum/(n*(k/__gcd(n,k)));
}
while(s.size())
{
int t=0;
vector<int>v;
while(s.size()&&t<k)
{
set<pair<long long,int> >::iterator it=s.end();
it--;
int u=(*(it)).second;
s.erase(it);
v.push_back(u);
a[u]-=p;
t++;
}
if(t!=k){cout<<-1<<endl;return 0;
}
for(int i=0;i<v.size();i++)
{
if(a[v[i]]>0)
{
s.insert(make_pair(a[v[i]],v[i]));
}
}
ans.push_back(v);
}
cout<<ans.size()<<endl;
for(int i=0;i<ans.size();i++)
{
cout<<p<<" ";
for(int j=0;j<ans[i].size();j++)
{
cout<<ans[i][j]<<" ";
}
cout<<endl;
}
}
/*
* *
* * * *
* * * *
* * * *
* * * *
* * *
* *
* *
* *
* *
* *
* *
* *
* *
*
*/
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:49:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size();i++)
~^~~~~~~~~
nicegift.cpp:59:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ans.size();i++)
~^~~~~~~~~~~
nicegift.cpp:62:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<ans[i].size();j++)
~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n=4 |
2 |
Correct |
2 ms |
356 KB |
n=3 |
3 |
Correct |
2 ms |
564 KB |
n=3 |
4 |
Correct |
2 ms |
564 KB |
n=4 |
5 |
Correct |
2 ms |
564 KB |
n=4 |
6 |
Correct |
2 ms |
564 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n=4 |
2 |
Correct |
2 ms |
356 KB |
n=3 |
3 |
Correct |
2 ms |
564 KB |
n=3 |
4 |
Correct |
2 ms |
564 KB |
n=4 |
5 |
Correct |
2 ms |
564 KB |
n=4 |
6 |
Correct |
2 ms |
564 KB |
n=2 |
7 |
Correct |
2 ms |
564 KB |
n=5 |
8 |
Correct |
5 ms |
1284 KB |
n=8 |
9 |
Correct |
32 ms |
1500 KB |
n=14 |
10 |
Correct |
20 ms |
1500 KB |
n=11 |
11 |
Correct |
127 ms |
6828 KB |
n=50000 |
12 |
Correct |
136 ms |
6848 KB |
n=50000 |
13 |
Correct |
108 ms |
6848 KB |
n=10 |
14 |
Correct |
100 ms |
6848 KB |
n=685 |
15 |
Correct |
109 ms |
6848 KB |
n=623 |
16 |
Correct |
60 ms |
6848 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n=4 |
2 |
Correct |
2 ms |
356 KB |
n=3 |
3 |
Correct |
2 ms |
564 KB |
n=3 |
4 |
Correct |
2 ms |
564 KB |
n=4 |
5 |
Correct |
2 ms |
564 KB |
n=4 |
6 |
Correct |
2 ms |
564 KB |
n=2 |
7 |
Correct |
2 ms |
564 KB |
n=5 |
8 |
Correct |
5 ms |
1284 KB |
n=8 |
9 |
Correct |
32 ms |
1500 KB |
n=14 |
10 |
Correct |
20 ms |
1500 KB |
n=11 |
11 |
Correct |
127 ms |
6828 KB |
n=50000 |
12 |
Correct |
136 ms |
6848 KB |
n=50000 |
13 |
Correct |
108 ms |
6848 KB |
n=10 |
14 |
Correct |
100 ms |
6848 KB |
n=685 |
15 |
Correct |
109 ms |
6848 KB |
n=623 |
16 |
Correct |
60 ms |
6848 KB |
n=973 |
17 |
Correct |
87 ms |
6848 KB |
n=989 |
18 |
Correct |
30 ms |
6848 KB |
n=563 |
19 |
Correct |
38 ms |
6848 KB |
n=592 |
20 |
Correct |
39 ms |
6848 KB |
n=938 |
21 |
Correct |
33 ms |
6848 KB |
n=747 |
22 |
Correct |
33 ms |
6848 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1977 ms |
85276 KB |
n=1000000 |
2 |
Correct |
1027 ms |
85276 KB |
n=666666 |
3 |
Correct |
508 ms |
85276 KB |
n=400000 |
4 |
Correct |
1549 ms |
85276 KB |
n=285714 |
5 |
Correct |
18 ms |
85276 KB |
n=20000 |
6 |
Correct |
1331 ms |
85276 KB |
n=181818 |
7 |
Correct |
11 ms |
85276 KB |
n=10000 |
8 |
Correct |
168 ms |
85276 KB |
n=6666 |
9 |
Correct |
5 ms |
85276 KB |
n=4000 |
10 |
Correct |
500 ms |
85276 KB |
n=2857 |
11 |
Correct |
4 ms |
85276 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n=4 |
2 |
Correct |
2 ms |
356 KB |
n=3 |
3 |
Correct |
2 ms |
564 KB |
n=3 |
4 |
Correct |
2 ms |
564 KB |
n=4 |
5 |
Correct |
2 ms |
564 KB |
n=4 |
6 |
Correct |
2 ms |
564 KB |
n=2 |
7 |
Correct |
2 ms |
564 KB |
n=5 |
8 |
Correct |
5 ms |
1284 KB |
n=8 |
9 |
Correct |
32 ms |
1500 KB |
n=14 |
10 |
Correct |
20 ms |
1500 KB |
n=11 |
11 |
Correct |
127 ms |
6828 KB |
n=50000 |
12 |
Correct |
136 ms |
6848 KB |
n=50000 |
13 |
Correct |
108 ms |
6848 KB |
n=10 |
14 |
Correct |
100 ms |
6848 KB |
n=685 |
15 |
Correct |
109 ms |
6848 KB |
n=623 |
16 |
Correct |
60 ms |
6848 KB |
n=973 |
17 |
Correct |
87 ms |
6848 KB |
n=989 |
18 |
Correct |
30 ms |
6848 KB |
n=563 |
19 |
Correct |
38 ms |
6848 KB |
n=592 |
20 |
Correct |
39 ms |
6848 KB |
n=938 |
21 |
Correct |
33 ms |
6848 KB |
n=747 |
22 |
Correct |
33 ms |
6848 KB |
n=991 |
23 |
Correct |
1977 ms |
85276 KB |
n=1000000 |
24 |
Correct |
1027 ms |
85276 KB |
n=666666 |
25 |
Correct |
508 ms |
85276 KB |
n=400000 |
26 |
Correct |
1549 ms |
85276 KB |
n=285714 |
27 |
Correct |
18 ms |
85276 KB |
n=20000 |
28 |
Correct |
1331 ms |
85276 KB |
n=181818 |
29 |
Correct |
11 ms |
85276 KB |
n=10000 |
30 |
Correct |
168 ms |
85276 KB |
n=6666 |
31 |
Correct |
5 ms |
85276 KB |
n=4000 |
32 |
Correct |
500 ms |
85276 KB |
n=2857 |
33 |
Correct |
4 ms |
85276 KB |
n=2000 |
34 |
Execution timed out |
2070 ms |
232648 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |