# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
243887 |
2020-07-02T04:40:33 Z |
_7_7_ |
Gift (IZhO18_nicegift) |
C++14 |
|
1522 ms |
196232 KB |
#include <bits/stdc++.h>
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
using namespace std;
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e6 + 11;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;
vector < pair < int, vi > > ans;
int n, m, k, a[N], sum;
set < int > pos, q;
vpii add, del;
vi Pos;
void f (int l, int r, int x) {
// cerr << l << ' ' << r << ' ' << x << endl;
pos.insert(l);
pos.insert(r + 1);
add.pb({l, x});
del.pb({r + 1, x});
}
main () {
fastio
scanf("%lld%lld", &n, &k);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
sum += a[i];
}
m = sum / k;
if ((sum % k) || m < *max_element(a + 1, a + 1 + n)) {
cout << -1;
return 0;
}
int cur = 1;
for (int i = 1; i <= n; ++i) {
if (cur + a[i] - 1 > m) {
f(cur, m, i);
f(1, cur + a[i] - 1 - m, i);
} else
f(cur, cur + a[i] - 1, i);
cur += a[i];
if (cur > m)
cur -= m;
}
sort(all(add));
sort(all(del));
int j1 = 0, j2 = 0;
for (auto i : pos)
Pos.pb(i);
for (int j = 0; j < sz(Pos); ++j) {
int i = Pos[j];
while (j2 < sz(del) && del[j2].f == i) {
q.erase(del[j2].s);
++j2;
}
while (j1 < sz(add) && add[j1].f == i) {
q.insert(add[j1].s);
++j1;
}
if (j < sz(Pos) - 1) {
vi tmp;
for (auto x : q)
tmp.pb(x);
ans.pb({Pos[j + 1] - Pos[j], tmp});
// cerr << Pos[j + 1] << ' ' << Pos[j] << endl;
}
}
printf("%lld\n", sz(ans));
for (auto v : ans) {
printf("%lld ", v.f);
for (auto x : v.s)
printf("%lld ", x);
printf("\n");
}
}
Compilation message
nicegift.cpp:55:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
nicegift.cpp: In function 'int main()':
nicegift.cpp:57: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:59: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 |
5 ms |
384 KB |
n=4 |
2 |
Correct |
5 ms |
428 KB |
n=3 |
3 |
Correct |
5 ms |
384 KB |
n=3 |
4 |
Correct |
5 ms |
384 KB |
n=4 |
5 |
Correct |
5 ms |
384 KB |
n=4 |
6 |
Correct |
4 ms |
384 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
n=4 |
2 |
Correct |
5 ms |
428 KB |
n=3 |
3 |
Correct |
5 ms |
384 KB |
n=3 |
4 |
Correct |
5 ms |
384 KB |
n=4 |
5 |
Correct |
5 ms |
384 KB |
n=4 |
6 |
Correct |
4 ms |
384 KB |
n=2 |
7 |
Correct |
4 ms |
384 KB |
n=5 |
8 |
Correct |
5 ms |
384 KB |
n=8 |
9 |
Correct |
4 ms |
384 KB |
n=14 |
10 |
Correct |
5 ms |
384 KB |
n=11 |
11 |
Correct |
58 ms |
8168 KB |
n=50000 |
12 |
Correct |
54 ms |
7912 KB |
n=50000 |
13 |
Correct |
5 ms |
384 KB |
n=10 |
14 |
Correct |
6 ms |
512 KB |
n=685 |
15 |
Correct |
5 ms |
512 KB |
n=623 |
16 |
Correct |
6 ms |
512 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
n=4 |
2 |
Correct |
5 ms |
428 KB |
n=3 |
3 |
Correct |
5 ms |
384 KB |
n=3 |
4 |
Correct |
5 ms |
384 KB |
n=4 |
5 |
Correct |
5 ms |
384 KB |
n=4 |
6 |
Correct |
4 ms |
384 KB |
n=2 |
7 |
Correct |
4 ms |
384 KB |
n=5 |
8 |
Correct |
5 ms |
384 KB |
n=8 |
9 |
Correct |
4 ms |
384 KB |
n=14 |
10 |
Correct |
5 ms |
384 KB |
n=11 |
11 |
Correct |
58 ms |
8168 KB |
n=50000 |
12 |
Correct |
54 ms |
7912 KB |
n=50000 |
13 |
Correct |
5 ms |
384 KB |
n=10 |
14 |
Correct |
6 ms |
512 KB |
n=685 |
15 |
Correct |
5 ms |
512 KB |
n=623 |
16 |
Correct |
6 ms |
512 KB |
n=973 |
17 |
Correct |
6 ms |
512 KB |
n=989 |
18 |
Correct |
6 ms |
512 KB |
n=563 |
19 |
Correct |
7 ms |
588 KB |
n=592 |
20 |
Correct |
7 ms |
640 KB |
n=938 |
21 |
Correct |
7 ms |
640 KB |
n=747 |
22 |
Correct |
7 ms |
640 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1130 ms |
129272 KB |
n=1000000 |
2 |
Correct |
588 ms |
71932 KB |
n=666666 |
3 |
Correct |
333 ms |
37540 KB |
n=400000 |
4 |
Correct |
580 ms |
75284 KB |
n=285714 |
5 |
Correct |
18 ms |
1788 KB |
n=20000 |
6 |
Correct |
467 ms |
58240 KB |
n=181818 |
7 |
Correct |
11 ms |
1148 KB |
n=10000 |
8 |
Correct |
44 ms |
5144 KB |
n=6666 |
9 |
Correct |
7 ms |
640 KB |
n=4000 |
10 |
Correct |
225 ms |
25848 KB |
n=2857 |
11 |
Correct |
6 ms |
512 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
n=4 |
2 |
Correct |
5 ms |
428 KB |
n=3 |
3 |
Correct |
5 ms |
384 KB |
n=3 |
4 |
Correct |
5 ms |
384 KB |
n=4 |
5 |
Correct |
5 ms |
384 KB |
n=4 |
6 |
Correct |
4 ms |
384 KB |
n=2 |
7 |
Correct |
4 ms |
384 KB |
n=5 |
8 |
Correct |
5 ms |
384 KB |
n=8 |
9 |
Correct |
4 ms |
384 KB |
n=14 |
10 |
Correct |
5 ms |
384 KB |
n=11 |
11 |
Correct |
58 ms |
8168 KB |
n=50000 |
12 |
Correct |
54 ms |
7912 KB |
n=50000 |
13 |
Correct |
5 ms |
384 KB |
n=10 |
14 |
Correct |
6 ms |
512 KB |
n=685 |
15 |
Correct |
5 ms |
512 KB |
n=623 |
16 |
Correct |
6 ms |
512 KB |
n=973 |
17 |
Correct |
6 ms |
512 KB |
n=989 |
18 |
Correct |
6 ms |
512 KB |
n=563 |
19 |
Correct |
7 ms |
588 KB |
n=592 |
20 |
Correct |
7 ms |
640 KB |
n=938 |
21 |
Correct |
7 ms |
640 KB |
n=747 |
22 |
Correct |
7 ms |
640 KB |
n=991 |
23 |
Correct |
1130 ms |
129272 KB |
n=1000000 |
24 |
Correct |
588 ms |
71932 KB |
n=666666 |
25 |
Correct |
333 ms |
37540 KB |
n=400000 |
26 |
Correct |
580 ms |
75284 KB |
n=285714 |
27 |
Correct |
18 ms |
1788 KB |
n=20000 |
28 |
Correct |
467 ms |
58240 KB |
n=181818 |
29 |
Correct |
11 ms |
1148 KB |
n=10000 |
30 |
Correct |
44 ms |
5144 KB |
n=6666 |
31 |
Correct |
7 ms |
640 KB |
n=4000 |
32 |
Correct |
225 ms |
25848 KB |
n=2857 |
33 |
Correct |
6 ms |
512 KB |
n=2000 |
34 |
Correct |
33 ms |
4612 KB |
n=23514 |
35 |
Correct |
34 ms |
4580 KB |
n=23514 |
36 |
Correct |
6 ms |
512 KB |
n=940 |
37 |
Correct |
5 ms |
384 KB |
n=2 |
38 |
Correct |
165 ms |
21048 KB |
n=100000 |
39 |
Correct |
165 ms |
21064 KB |
n=100000 |
40 |
Correct |
5 ms |
384 KB |
n=10 |
41 |
Correct |
5 ms |
384 KB |
n=100 |
42 |
Correct |
11 ms |
1152 KB |
n=1000 |
43 |
Correct |
1320 ms |
185532 KB |
n=1000000 |
44 |
Correct |
1522 ms |
196232 KB |
n=1000000 |
45 |
Correct |
989 ms |
135508 KB |
n=666666 |
46 |
Correct |
703 ms |
92824 KB |
n=400000 |
47 |
Correct |
229 ms |
25592 KB |
n=2336 |
48 |
Correct |
623 ms |
75424 KB |
n=285714 |
49 |
Correct |
480 ms |
58168 KB |
n=181818 |
50 |
Correct |
293 ms |
34012 KB |
n=40000 |
51 |
Correct |
252 ms |
30216 KB |
n=20000 |
52 |
Correct |
236 ms |
27500 KB |
n=10000 |
53 |
Correct |
232 ms |
26804 KB |
n=6666 |
54 |
Correct |
225 ms |
26064 KB |
n=4000 |
55 |
Correct |
224 ms |
25828 KB |
n=2857 |
56 |
Correct |
258 ms |
24956 KB |
n=2000 |