# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
92243 |
2019-01-02T07:56:50 Z |
davitmarg |
Gift (IZhO18_nicegift) |
C++17 |
|
2000 ms |
263860 KB |
/*
DEATH-MATCH
Davit-Marg
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>
#include <cassert>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
using namespace std;
LL gcd(LL a, LL b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
LL n,k,a[1000006],d,v,s;
bool hav=1;
priority_queue<pair<LL, int>> q;
vector<pair<LL, int>> ans;
int main()
{
cin >> n >> k;
for (LL i = 0; i < n; i++)
{
scanf("%lld", a + i);
s += a[i];
q.push(MP(a[i],i));
if (i && a[i] != a[i - 1])
hav = 0;
}
if (hav)
{
d = k / gcd(n, k);
if (a[0] % d != 0)
{
cout << -1 << endl;
return 0;
}
cout << d * n / k;
for (LL i = 0; i < d*n; i++)
{
v %= k;
if (v == 0)
cout << endl << a[0] / d << " ";
cout << (i%n) + 1 << " ";
v++;
}
cout << endl;
}
else
{
int step = 0;
vector<pair<LL, int>> st;
while (!q.empty())
{
for (int i = 0; i < k; i++)
{
if (q.empty())
{
cout << -1 << endl;
return 0;
}
st.PB(q.top());
q.pop();
}
LL d = st.back().first;
if (!q.empty())
d = max(st.back().first - q.top().first,1ll);
for (int i = k-1; i >=0 ; i--)
{
ans.PB(MP(d,st[i].second));
if(st[i].first - d > 0)
q.push(MP(st[i].first-d,st[i].second));
st.pop_back();
}
}
if (!q.empty() || !st.empty())
{
cout << -1 << endl;
return 0;
}
else
{
cout << ans.size() / k;
for (int i = 0; i < ans.size(); i++)
{
if (i%k == 0)
cout<< endl << ans[i].first << " ";
cout << ans[i].second+1 << " ";
}
cout << endl;
}
}
return 0;
}
/*
4 2
1 1 4 4
4 3
6 6 6 6
14 7
10 10 10 10 10 10 10 10 10 10 10 10 10 10
*/
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:108:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ans.size(); i++)
~~^~~~~~~~~~~~
nicegift.cpp:74:7: warning: unused variable 'step' [-Wunused-variable]
int step = 0;
^~~~
nicegift.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", a + i);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
504 KB |
n=8 |
9 |
Correct |
25 ms |
1012 KB |
n=14 |
10 |
Correct |
14 ms |
888 KB |
n=11 |
11 |
Correct |
66 ms |
3436 KB |
n=50000 |
12 |
Correct |
93 ms |
3940 KB |
n=50000 |
13 |
Correct |
68 ms |
2540 KB |
n=10 |
14 |
Correct |
79 ms |
2540 KB |
n=685 |
15 |
Correct |
83 ms |
2540 KB |
n=623 |
16 |
Correct |
49 ms |
1532 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
504 KB |
n=8 |
9 |
Correct |
25 ms |
1012 KB |
n=14 |
10 |
Correct |
14 ms |
888 KB |
n=11 |
11 |
Correct |
66 ms |
3436 KB |
n=50000 |
12 |
Correct |
93 ms |
3940 KB |
n=50000 |
13 |
Correct |
68 ms |
2540 KB |
n=10 |
14 |
Correct |
79 ms |
2540 KB |
n=685 |
15 |
Correct |
83 ms |
2540 KB |
n=623 |
16 |
Correct |
49 ms |
1532 KB |
n=973 |
17 |
Correct |
66 ms |
2540 KB |
n=989 |
18 |
Correct |
23 ms |
1520 KB |
n=563 |
19 |
Correct |
28 ms |
2540 KB |
n=592 |
20 |
Correct |
31 ms |
2536 KB |
n=938 |
21 |
Correct |
27 ms |
2536 KB |
n=747 |
22 |
Correct |
28 ms |
2540 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
998 ms |
38084 KB |
n=1000000 |
2 |
Correct |
526 ms |
30652 KB |
n=666666 |
3 |
Correct |
239 ms |
19152 KB |
n=400000 |
4 |
Correct |
670 ms |
27984 KB |
n=285714 |
5 |
Correct |
8 ms |
1396 KB |
n=20000 |
6 |
Correct |
498 ms |
22336 KB |
n=181818 |
7 |
Correct |
5 ms |
888 KB |
n=10000 |
8 |
Correct |
36 ms |
2296 KB |
n=6666 |
9 |
Correct |
3 ms |
504 KB |
n=4000 |
10 |
Correct |
191 ms |
9608 KB |
n=2857 |
11 |
Correct |
3 ms |
376 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
376 KB |
n=3 |
4 |
Correct |
2 ms |
376 KB |
n=4 |
5 |
Correct |
2 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
376 KB |
n=5 |
8 |
Correct |
2 ms |
504 KB |
n=8 |
9 |
Correct |
25 ms |
1012 KB |
n=14 |
10 |
Correct |
14 ms |
888 KB |
n=11 |
11 |
Correct |
66 ms |
3436 KB |
n=50000 |
12 |
Correct |
93 ms |
3940 KB |
n=50000 |
13 |
Correct |
68 ms |
2540 KB |
n=10 |
14 |
Correct |
79 ms |
2540 KB |
n=685 |
15 |
Correct |
83 ms |
2540 KB |
n=623 |
16 |
Correct |
49 ms |
1532 KB |
n=973 |
17 |
Correct |
66 ms |
2540 KB |
n=989 |
18 |
Correct |
23 ms |
1520 KB |
n=563 |
19 |
Correct |
28 ms |
2540 KB |
n=592 |
20 |
Correct |
31 ms |
2536 KB |
n=938 |
21 |
Correct |
27 ms |
2536 KB |
n=747 |
22 |
Correct |
28 ms |
2540 KB |
n=991 |
23 |
Correct |
998 ms |
38084 KB |
n=1000000 |
24 |
Correct |
526 ms |
30652 KB |
n=666666 |
25 |
Correct |
239 ms |
19152 KB |
n=400000 |
26 |
Correct |
670 ms |
27984 KB |
n=285714 |
27 |
Correct |
8 ms |
1396 KB |
n=20000 |
28 |
Correct |
498 ms |
22336 KB |
n=181818 |
29 |
Correct |
5 ms |
888 KB |
n=10000 |
30 |
Correct |
36 ms |
2296 KB |
n=6666 |
31 |
Correct |
3 ms |
504 KB |
n=4000 |
32 |
Correct |
191 ms |
9608 KB |
n=2857 |
33 |
Correct |
3 ms |
376 KB |
n=2000 |
34 |
Execution timed out |
2064 ms |
263860 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |