QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#285292#7940. Impossible Numbersucup-team2112#WA 1ms3968kbC++204.2kb2023-12-16 17:45:472023-12-16 17:45:48

Judging History

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

  • [2023-12-17 13:41:15]
  • hack成功,自动添加数据
  • (/hack/501)
  • [2023-12-16 17:45:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3968kb
  • [2023-12-16 17:45:47]
  • 提交

answer

#include <bits/stdc++.h>

template<class T>
struct Dinic {
    const int n;
    struct edge {
        int to;
        T cap;
        edge(int to, T cap) : to(to), cap(cap) {}
    };
    std::vector<edge> e;
    std::vector<std::vector<int> > adj;
    std::vector<int> cur, h;
    Dinic(int n) : n(n), adj(n) {}
    
    bool bfs(int s, int t) {
        h.assign(n, -1);
        std::queue<int> que;
        h[s] = 0;
        que.push(s);
        while (!que.empty()) {
            const int u = que.front();
            que.pop();
            for (int i : adj[u]) {
                auto [v, c] = e[i];
                if (c > 0 && h[v] == -1) {
                    h[v] = h[u] + 1;
                    if (v == t) {
                        return true;
                    }
                    que.push(v);
                }
            }
        }
        return false;
    }
    
    T dfs(int u, int t, T f) {
        if (u == t) {
            return f;
        }
        auto r = f;
        for (int &i = cur[u]; i < int(adj[u].size()); ++i) {
            const int j = adj[u][i];
            auto [v, c] = e[j];
            if (c > 0 && h[v] == h[u] + 1) {
                auto a = dfs(v, t, std::min(r, c));
                e[j].cap -= a;
                e[j ^ 1].cap += a;
                r -= a;
                if (r == 0) {
                    return f;
                }
            }
        }
        return f - r;
    }
    void addedge(int u, int v, T c) {
        assert(u < n && v < n);
        adj[u].push_back(e.size());
        e.emplace_back(v, c);
        adj[v].push_back(e.size());
        e.emplace_back(u, 0);
    }
    T maxflow(int s, int t) {
        T ans = 0;
        while (bfs(s, t)) {
            cur.assign(n, 0);
            ans += dfs(s, t, std::numeric_limits<T>::max());
        }
        return ans;
    }
};

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int n, k;
    std::cin >> n >> k;
    std::vector<int> number(100);
    std::vector<std::array<int, 6> > cube(n);
    Dinic<int> dinic(n + 10 + 1);
    for (int i = 0; i < n; i += 1) {
        for (int j = 0; j < 6; j += 1) {
            std::cin >> cube[i][j];
            dinic.addedge(i, n + cube[i][j], 1);
        }
        dinic.addedge(0, i + 1, 1);
    }
    std::vector<int> cnt(10);

    std::map<std::vector<int>, int> mp;
    auto check = [&](std::vector<int> &go) {
        if (mp.count(go)) {
            return mp[go];
        }
        auto cur = dinic;
        for (int i = 0; i < 10; i += 1) {
            cur.addedge(n + i, n + 10, go[i]);
        }
        int ans = cur.maxflow(0, n + 10);
        // if (go[3] == 2) {
        //     std::cout << "!!!xx: " << ans << " " << (ans == std::accumulate(go.begin(), go.end(), 0)) << "\n";
        // }
       
        int x = (ans == int(std::accumulate(go.begin(), go.end(), 0)));
        return mp[go] = x;
    };
    
    std::function<void(int, bool)> dfs = [&](int u, bool lead) {
        if (k == 0) {
            return;
        }
        if (u == number.size()) {
            k -= 1;
            bool first = true;
            for (int i = 0; i < number.size(); i += 1) {
                if (number[i] == 0 && first) continue;
                first = false;
                std::cout << number[i];
            }
            std::cout << " ";
            return;
        }
        for (int i = 0; i < 10; i += 1) {
            number[u] = i;
            if (!lead || i > 0) {
                cnt[i] += 1;
            }
            
            bool nice = true;
            for (int j = 0; j < 10; j += 1) {
                if (lead && i == 0 && j == 0) continue;
                cnt[j] += number.size() - 1 - u;
                if (!check(cnt)) {
                    nice = false;
                }
                cnt[j] -= number.size() - 1 - u;
                if (!nice) break;
            }
            if (!nice) {
                dfs(u + 1, lead && i == 0);
            }
            if (!lead || i > 0) {
                cnt[i] -= 1;
            }
        }
    };
    dfs(0, true);
    std::cout << "\n";
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3968kb

input:

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

output:

33 34 35 

result:

ok single line: '33 34 35 '

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3732kb

input:

1 10
1 5 2 2 6 4

output:

3 7 8 9 11 13 17 18 19 23 

result:

wrong answer 1st lines differ - expected: '3 7 8 9 10 11 12 13 14 15', found: '3 7 8 9 11 13 17 18 19 23 '