QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#295778 | #6339. Cookies | Max_s_xaM | 0 | 1ms | 6092kb | C++14 | 4.6kb | 2023-12-31 22:43:07 | 2023-12-31 22:43:08 |
answer
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
typedef long long ll;
typedef double lf;
// #define DEBUG 1
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
#endif
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
#define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
template <typename T>
void Read(T &x)
{
#if DEBUG
std::cin >> x;
#else
bool sign = 0; char ch = gc(); x = 0;
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
if (sign) x = -x;
#endif
}
void Read(char *s)
{
#if DEBUG
std::cin >> s;
#else
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
#endif
}
void Read(char &c) {for (c = gc(); blank(c); c = gc());}
void Push(const char &c)
{
#if DEBUG
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <typename T>
void Write(T x)
{
if (x < 0) x = -x, Push('-');
static T sta[35];
int top = 0;
do sta[top++] = x % 10, x /= 10; while (x);
while (top) Push(sta[--top] ^ 48);
}
template <typename T>
void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)
using namespace std;
const int MAXN = 15010;
int n, m, a[MAXN], b[MAXN], id[MAXN];
bool avl[MAXN];
vector <int> vans[MAXN];
struct Data
{
int x1, x2, x3, x4;
bool operator < (const Data u) const {return x1 == u.x1 ? x2 == u.x2 ? x3 == u.x3 ? x4 < u.x4 : x3 < u.x3 : x2 < u.x2 : x1 < u.x1;}
};
map <Data, bool> mp;
map <Data, int> pre;
bool Solve(int i, int val, int cnt, int t)
{
// cout << i << " " << val << " " << cnt << " " << t << "\n";
if (i == n + 1)
{
if (avl[val] && (!t || avl[val + 1])) return 1;
return 0;
}
Data sta = (Data){i, val, cnt, t};
if (mp.count(sta)) return mp[sta];
if (!avl[val])
{
if (a[i] > cnt) return mp[sta] = 0;
pre[sta] = min(a[i], cnt - t);
return mp[sta] = Solve(i + 1, val + (a[i] >= cnt - t), cnt, (a[i] >= cnt - t ? a[i] - cnt + t : t + a[i]));
}
int nval, ncnt, nt; bool cur;
for (int x = max(a[i] - t, 0); x <= a[i] && x <= cnt - t; x++)
{
if (x == 0 && a[i] == t) nval = val + 2, ncnt = t, nt = 0;
else if (a[i] != x || t + x == cnt) nval = val + 1, ncnt = t + x, nt = a[i] - x;
else nval = val, ncnt = cnt, nt = t + x;
cur = Solve(i + 1, nval, ncnt, nt);
if (cur) {pre[sta] = x; return mp[sta] = 1;}
}
return mp[sta] = 0;
}
int main()
{
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
Read(n);
int sum = 0;
for (int i = 1; i <= n; i++) Read(a[i]), id[i] = i, sum += a[i];
Read(m);
for (int i = 1; i <= m; i++) Read(b[i]), avl[b[i]] = 1;
sort(id + 1, id + n + 1, [&](int x, int y) {return a[x] > a[y];});
sort(a + 1, a + n + 1, [&](int x, int y) {return x > y;});
for (int i = a[1]; i <= sum / b[1]; i++)
if (Solve(2, 0, i, a[1]))
{
Write(i, '\n');
for (int j = 1; j <= a[1]; j++) vans[j].push_back(id[1]);
int cur = 2, val = 0, cnt = i, t = a[1];
while (cur <= n)
{
int x = pre[Data{cur, val, cnt, t}];
for (int j = t + 1; j <= t + x; j++) vans[j].push_back(id[cur]);
for (int j = 1; j <= a[cur] - x; j++) vans[j].push_back(id[cur]);
if (x == 0 && a[cur] == t) val += 2, cnt = t, t = 0;
else if (a[cur] != x || t + x == cnt) val++, cnt = t + x, t = a[cur] - x;
else t += x;
cur++;
}
for (int j = 1; j <= i; j++)
{
Write(vans[j].size(), ' ');
for (auto x : vans[j]) Write(x, ' ');
Put('\n');
}
return 0;
}
Write(-1, '\n');
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3960kb
input:
1 1 1 1
output:
-1
result:
wrong answer you didn't find a solution but jury did
Subtask #2:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 1ms
memory: 3916kb
input:
1 15 1 1
output:
-1
result:
wrong answer you didn't find a solution but jury did
Subtask #3:
score: 0
Wrong Answer
Test #45:
score: 12
Accepted
time: 1ms
memory: 4000kb
input:
2 7 8 2 1 2
output:
8 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 1 2
result:
ok good!
Test #46:
score: 0
Accepted
time: 1ms
memory: 3976kb
input:
3 5 4 6 2 2 3
output:
6 3 3 1 2 3 3 1 2 3 3 1 2 2 3 1 2 3 1 2 3 2
result:
ok good!
Test #47:
score: 0
Accepted
time: 1ms
memory: 3976kb
input:
3 4 2 9 3 1 2 3
output:
9 3 3 1 2 3 3 1 2 2 3 1 2 3 1 1 3 1 3 1 3 1 3 1 3
result:
ok good!
Test #48:
score: 0
Accepted
time: 1ms
memory: 4036kb
input:
4 3 5 4 3 2 3 4
output:
5 3 2 3 1 3 2 3 1 3 2 3 4 3 2 3 4 3 2 1 4
result:
ok good!
Test #49:
score: 0
Accepted
time: 1ms
memory: 3980kb
input:
4 1 4 5 5 3 1 3 4
output:
5 4 3 4 2 1 3 3 4 2 3 3 4 2 3 3 4 2 2 3 4
result:
ok good!
Test #50:
score: 0
Accepted
time: 1ms
memory: 4112kb
input:
4 3 3 6 3 3 2 3 4
output:
6 3 3 1 4 3 3 1 4 3 3 1 4 2 3 2 2 3 2 2 3 2
result:
ok good!
Test #51:
score: 0
Accepted
time: 1ms
memory: 6068kb
input:
5 4 3 3 3 1 3 2 4 5
output:
4 4 1 2 3 4 4 1 2 3 4 4 1 2 4 5 2 1 3
result:
ok good!
Test #52:
score: 0
Accepted
time: 1ms
memory: 3972kb
input:
5 4 3 3 3 2 3 3 4 5
output:
4 5 1 2 3 4 5 4 1 2 3 5 3 1 2 4 3 1 3 4
result:
ok good!
Test #53:
score: 0
Accepted
time: 0ms
memory: 4024kb
input:
5 4 4 4 2 1 3 2 4 5
output:
5 5 1 2 3 4 5 4 1 2 3 4 2 1 2 2 1 3 2 2 3
result:
ok good!
Test #54:
score: 0
Accepted
time: 0ms
memory: 4036kb
input:
5 3 3 3 3 3 3 1 2 4
output:
5 4 1 2 4 5 4 1 3 4 5 4 1 3 4 5 2 2 3 1 2
result:
ok good!
Test #55:
score: 0
Accepted
time: 1ms
memory: 5928kb
input:
6 3 3 3 2 2 2 3 2 4 6
output:
-1
result:
ok no solution
Test #56:
score: 0
Accepted
time: 0ms
memory: 5868kb
input:
6 3 3 3 2 2 2 3 2 5 6
output:
3 6 1 2 3 4 5 6 6 1 2 3 4 5 6 3 1 2 3
result:
ok good!
Test #57:
score: 0
Accepted
time: 1ms
memory: 3972kb
input:
6 4 4 3 2 1 1 3 1 3 5
output:
5 5 1 2 3 4 5 5 1 2 3 4 6 3 1 2 3 1 1 1 2
result:
ok good!
Test #58:
score: 0
Accepted
time: 1ms
memory: 4016kb
input:
6 7 2 2 2 1 1 5 2 3 4 5 6
output:
7 3 1 2 6 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 2 1 5
result:
ok good!
Test #59:
score: 0
Accepted
time: 1ms
memory: 4088kb
input:
7 3 3 3 2 2 1 1 3 1 4 6
output:
4 6 1 2 3 4 6 7 4 1 2 3 5 4 1 3 4 5 1 2
result:
ok good!
Test #60:
score: 0
Accepted
time: 1ms
memory: 6092kb
input:
7 4 4 3 1 1 1 1 3 1 4 6
output:
6 4 1 2 3 5 4 1 2 3 6 4 1 3 4 7 1 1 1 2 1 2
result:
ok good!
Test #61:
score: 0
Accepted
time: 1ms
memory: 4056kb
input:
8 2 2 2 2 2 2 2 1 6 1 2 3 4 6 7
output:
3 7 1 2 3 4 5 6 7 7 1 3 4 5 6 7 8 1 2
result:
ok good!
Test #62:
score: 0
Accepted
time: 0ms
memory: 6068kb
input:
8 3 3 3 2 1 1 1 1 4 4 6 7 8
output:
3 8 1 2 3 4 5 6 7 8 4 1 2 3 4 3 1 2 3
result:
ok good!
Test #63:
score: -12
Wrong Answer
time: 1ms
memory: 3976kb
input:
8 4 3 3 1 1 1 1 1 4 1 6 7 8
output:
9 7 1 3 4 5 6 7 8 1 1 1 1 1 1 1 2 1 2 1 2 1 3 1 3
result:
wrong answer you used more buckets than jury
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%