QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#295782#6339. CookiesMax_s_xaM0 1ms4384kbC++144.6kb2023-12-31 22:52:112023-12-31 22:52:11

Judging History

你现在查看的是最新测评结果

  • [2023-12-31 22:52:11]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:4384kb
  • [2023-12-31 22:52:11]
  • 提交

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, (i == a[1]), i, (i ^ a[1] ? a[1] : 0)))
        {
            Write(i, '\n');
            for (int j = 1; j <= a[1]; j++) vans[j].push_back(id[1]);
            int cur = 2, val = (i == a[1]), cnt = i, t = (i ^ a[1] ? a[1] : 0);
            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
Time Limit Exceeded

Test #1:

score: 6
Accepted
time: 1ms
memory: 3720kb

input:

1
1
1
1

output:

1
1 1 

result:

ok good!

Test #2:

score: 0
Accepted
time: 0ms
memory: 3768kb

input:

2
1 1
1
1

output:

2
1 1 
1 2 

result:

ok good!

Test #3:

score: 0
Accepted
time: 1ms
memory: 3844kb

input:

2
1 1
1
2

output:

1
2 1 2 

result:

ok good!

Test #4:

score: 0
Accepted
time: 1ms
memory: 3836kb

input:

2
1 1
2
1 2

output:

1
2 1 2 

result:

ok good!

Test #5:

score: 0
Accepted
time: 0ms
memory: 4016kb

input:

4
1 1 1 1
2
2 3

output:

2
2 1 3 
2 2 4 

result:

ok good!

Test #6:

score: 0
Accepted
time: 1ms
memory: 3836kb

input:

8
1 1 1 1 1 1 1 1
3
1 4 5

output:

2
4 1 3 5 7 
4 2 4 6 8 

result:

ok good!

Test #7:

score: -6
Time Limit Exceeded

input:

500
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:


result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #28:

score: 7
Accepted
time: 1ms
memory: 3848kb

input:

1
15
1
1

output:

15
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 

result:

ok good!

Test #29:

score: 0
Accepted
time: 1ms
memory: 3808kb

input:

1
500
1
1

output:

500
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1...

result:

ok good!

Test #30:

score: 0
Accepted
time: 1ms
memory: 4120kb

input:

1
3000
1
1

output:

3000
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
...

result:

ok good!

Test #31:

score: 0
Accepted
time: 1ms
memory: 4384kb

input:

1
15000
1
1

output:

15000
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 
1 1 ...

result:

ok good!

Test #32:

score: 0
Accepted
time: 1ms
memory: 3792kb

input:

2
2 1
1
1

output:

3
1 1 
1 1 
1 2 

result:

ok good!

Test #33:

score: 0
Accepted
time: 1ms
memory: 4008kb

input:

2
1 2
1
2

output:

-1

result:

ok no solution

Test #34:

score: 0
Accepted
time: 1ms
memory: 3844kb

input:

3
1 2 3
1
2

output:

3
2 3 2 
2 3 2 
2 3 1 

result:

ok good!

Test #35:

score: 0
Accepted
time: 1ms
memory: 4008kb

input:

3
3 2 1
1
3

output:

-1

result:

ok no solution

Test #36:

score: 0
Accepted
time: 1ms
memory: 3844kb

input:

3
2 2 2
1
2

output:

3
2 1 2 
2 1 3 
2 2 3 

result:

ok good!

Test #37:

score: 0
Accepted
time: 1ms
memory: 4020kb

input:

15
50 49 48 47 46 45 44 43 42 41 40 2 1 1 1
1
10

output:

50
10 1 2 3 4 5 6 7 8 9 10 
10 1 2 3 4 5 6 7 8 9 10 
10 1 2 3 4 5 6 7 8 9 10 
10 1 2 3 4 5 6 7 8 9 10 
10 1 2 3 4 5 6 7 8 9 10 
10 1 2 3 4 5 6 7 8 9 11 
10 1 2 3 4 5 6 7 8 9 11 
10 1 2 3 4 5 6 7 8 9 11 
10 1 2 3 4 5 6 7 8 9 11 
10 1 2 3 4 5 6 7 8 9 11 
10 1 2 3 4 5 6 7 8 9 11 
10 1 2 3 4 5 6 7 8 9 1...

result:

ok good!

Test #38:

score: 0
Accepted
time: 1ms
memory: 3788kb

input:

15
51 49 48 47 46 45 44 43 42 41 40 1 1 1 1
1
10

output:

-1

result:

ok no solution

Test #39:

score: 0
Accepted
time: 1ms
memory: 4128kb

input:

10
430 3078 390 349 3750 906 377 3374 1795 551
1
4

output:

3750
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9 
4 5 8 2 9...

result:

ok good!

Test #40:

score: -7
Time Limit Exceeded

input:

500
4 99 56 16 7 39 5 8 3 18 15 30 19 27 46 47 24 55 1 7 21 1 13 5 53 32 12 98 12 121 3 118 25 15 8 32 29 7 13 3 29 94 22 4 12 37 15 52 14 9 59 22 3 16 9 77 5 17 41 22 16 6 3 32 33 34 18 1 28 4 72 4 3 40 21 13 22 16 42 77 2 16 1 1 10 11 3 34 21 28 4 173 24 57 17 9 20 116 21 72 17 165 28 30 6 13 86 1...

output:


result:


Subtask #3:

score: 0
Wrong Answer

Test #45:

score: 12
Accepted
time: 1ms
memory: 3808kb

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: 3744kb

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: 0ms
memory: 4016kb

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: 0ms
memory: 3840kb

input:

4
1 4 5 5
3
1 3 4

output:

5
3 3 4 2 
3 3 4 2 
3 3 4 2 
3 3 4 2 
3 3 4 1 

result:

ok good!

Test #50:

score: 0
Accepted
time: 1ms
memory: 4016kb

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: 4020kb

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: 3836kb

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: 3892kb

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: 1ms
memory: 3844kb

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: 3844kb

input:

6
3 3 3 2 2 2
3
2 4 6

output:

-1

result:

ok no solution

Test #56:

score: 0
Accepted
time: 1ms
memory: 3848kb

input:

6
3 3 3 2 2 2
3
2 5 6

output:

3
5 1 2 3 4 5 
5 1 2 3 4 6 
5 1 2 3 5 6 

result:

ok good!

Test #57:

score: 0
Accepted
time: 1ms
memory: 4024kb

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: 3844kb

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: 3804kb

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: 3788kb

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: 3844kb

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: 1ms
memory: 3844kb

input:

8
3 3 3 2 1 1 1 1
4
4 6 7 8

output:

3
7 1 2 3 4 6 7 8 
4 1 2 3 4 
4 1 2 3 5 

result:

ok good!

Test #63:

score: -12
Wrong Answer
time: 0ms
memory: 3908kb

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%