QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#295780#6339. CookiesMax_s_xaM0 1ms5956kbC++144.6kb2023-12-31 22:51:052023-12-31 22:51:06

Judging History

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

  • [2023-12-31 22:51:06]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:5956kb
  • [2023-12-31 22:51:05]
  • 提交

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;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5956kb

input:

1
1
1
1

output:

2 1 1 0
1
1 1 

result:

wrong answer Integer parameter [name=c_i] equals to 0, violates the range [1, 1]

Subtask #2:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 1ms
memory: 4108kb

input:

1
15
1
1

output:

2 1 15 0
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:

wrong answer Integer parameter [name=v_ij] equals to 15, violates the range [1, 1]

Subtask #3:

score: 0
Wrong Answer

Test #45:

score: 0
Wrong Answer
time: 1ms
memory: 4056kb

input:

2
7 8
2
1 2

output:

2 1 8 0
3 1 8 7
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:

wrong answer Integer parameter [name=v_ij] equals to 8, violates the range [1, 2]

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%