QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#121401#1156. RobotsQwerty1232#0 0ms5856kbC++173.5kb2023-07-08 02:56:402024-07-04 00:29:46

Judging History

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

  • [2024-07-04 00:29:46]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:5856kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-08 02:56:40]
  • 提交

answer

#include "robots.h"

#include <bits/stdc++.h>

struct Flow {
    struct Edge {
        int to, id;
        int fl, cp;
    };

    int n, S, T;
    std::vector<std::vector<Edge>> gr;
    std::vector<int> dist, used;
    int flow;

    void add_edge(int u, int v, int cp) {
        int a = gr[u].size();
        int b = gr[v].size();
        gr[u].push_back(Edge{v, b, 0, cp});
        gr[v].push_back(Edge{u, a, cp, cp});
    }

    Flow(int n, int S = 0, int T = 1) : n(n), S(S), T(T), gr(n), dist(n), used(n), flow(0) {
        ;
    }

    void bfs(int f) {
        dist.assign(n, n);
        std::deque<int> deque;
        deque.push_back(f);
        dist[f] = 0;
        while (deque.size()) {
            int v = deque.front();
            deque.pop_front();
            for (auto& e : gr[v]) {
                if (e.cp != e.fl) {
                    if (dist[e.to] > dist[v] + 1) {
                        dist[e.to] = dist[v] + 1;
                        deque.push_back(e.to);
                    }
                }
            }
        }
    }

    void push(Edge& e, int dlt) {
        e.fl += dlt;
        gr[e.to][e.id].fl -= dlt;
    }

    int dfs(int v, int min) {
        if (v == T || min == 0) {
            return min;
        }
        for (int& i = used[v]; i < gr[v].size(); i++) {
            auto& e = gr[v][i];
            if (e.fl != e.cp && dist[e.to] == dist[v] + 1) {
                int res = dfs(e.to, std::min(min, e.cp - e.fl));
                if (res > 0) {
                    push(e, res);
                    return res;
                }
            }
        }
        return 0;
    }

    int findMaxFlow() {
        bfs(S);
        while (dist[T] != n) {
            used.assign(n, 0);
            int val = 0;
            while (val = dfs(S, 1e9)) {
                flow += val;
                assert(flow < 1e7);
            }
            bfs(S);
        }
        return flow;
    }
};

int putaway(int n, int m, int q, int X[], int Y[], int W[], int S[]) {
    std::vector<std::pair<int, int>> toys(q);
    for (int i = 0; i < q; i++) {
        toys[i] = {W[i], S[i]};
    }
    std::vector<int> x(X, X + n);
    std::vector<int> y(Y, Y + m);

    std::sort(x.begin(), x.end());
    std::sort(y.begin(), y.end());
    // x.erase(std::unique(x.begin(), x.end()), x.end());
    // y.erase(std::unique(y.begin(), y.end()), y.end());

    for (auto [w, s] : toys) {
        if (w >= x.back() && s >= y.back()) {
            return -1;
        }
    }

    Flow fl(2 + n + m + q);
    for (int i = 0; i < q; i++) {
        fl.add_edge(2 + n + m + i, 1, 1);

        int it_x = std::lower_bound(x.begin(), x.end(), toys[i].first + 1) - x.begin();
        int it_y = std::lower_bound(y.begin(), y.end(), toys[i].second + 1) - y.begin();
        if (it_x != x.size())
            fl.add_edge(2 + it_x, 2 + n + m + i, 1);
        if (it_y != y.size())
            fl.add_edge(2 + n + it_y, 2 + n + m + i, 1);
    }
    for (int i = 1; i < n; i++) {
        fl.add_edge(2 + i, 2 + i - 1, 1e9);
    }
    for (int i = 1; i < m; i++) {
        fl.add_edge(2 + n + i, 2 + n + i - 1, 1e9);
    }

    int ans = 0;
    do {
        for (int i = 0; i < n; i++) {
            fl.add_edge(0, 2 + i, 1);
        }
        for (int i = 0; i < n; i++) {
            fl.add_edge(0, 2 + n + i, 1);
        }
        ans++;
        assert(ans <= q);
    } while (fl.findMaxFlow() < q);
    return ans;
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 14
Accepted
time: 0ms
memory: 5856kb

input:

1 1 2
13
13
5 6
13 13

output:

-1

result:

ok single line: '-1'

Test #2:

score: -14
Runtime Error

input:

0 2 2

20 10
7 10
13 10

output:


result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #8:

score: 0
Time Limit Exceeded

input:

50000 0 500000
1957680000 64280000 235160000 1384760000 1279320000 1005400000 1481760000 1129920000 1774640000 494160000 763120000 419640000 1742880000 1083000000 278360000 64040000 576880000 1479760000 1872320000 158480000 1183880000 81320000 249920000 30920000 1909240000 870920000 842280000 445640...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%