编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#49319 #1008. H. 开疆辟土,公司成立 Runtime Error 0 68 ms 6636 K C++ 17 (Clang) / 2.0 K ymz 2021-06-24 0:41:02
显示原始代码
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ulli;
#define F(i, n, m) for (int i = n; i <= m; i++)

inline int read() {
    bool w = 0;
    int s = 0;
    char ch = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
    return w ? -s : s;
}

inline void write(int x) {
    if (x < 0)
        putchar('-'), x = ~x + 1;
    if (x > 9)
        write(x / 10);
    putchar((x % 10) | 48);
}

class Edge {
public:
    int be, ed, co;
    Edge(int i, int j, int k) : be(i), ed(j), co(k){};
    Edge(){};
    friend bool operator>(const Edge &E, const Edge &F) { return E.co > F.co; }
};

int be[50010], n, m;
vector<Edge> edges;

int index(int i, int j);
int kruskal(int n);
int find(int x);

int main() {
    int h, ans;
    for (int t = read(); t; t--) {
        edges.clear();
        ans = 0;
        n = read();
        m = read();
        F(i, 1, n) {
            F(j, 1, m) {
                h = read();
                if (i != n) {
                    ans += h;
                    edges.push_back(Edge(index(i, j), index(i + 1, j), h));
                }
                h = read();
                if (j != m) {
                    ans += h;
                    edges.push_back(Edge(index(i, j), index(i, j + 1), h));
                }
            }
        }
        write(ans - kruskal(index(n, m)));
    }
    return 0;
}

inline int index(int a, int b) { return (a - 1) * m + b; }

int kruskal(int n) {
    F(i, 1, n)
    be[i] = i;
    sort(edges.begin(), edges.end(), greater<Edge>());
    int all = 0, ans = 0;
    Edge e;
    F(i, 0, edges.size() - 1) {
        e = edges[i];
        if (find(e.be) != find(e.ed)) {
            all++;
            ans += e.co;
            be[e.be] = be[e.ed];
            if (all == n - 1)
                break;
        }
    }
    return ans;
}

int find(int x) {
    if (be[x] == x)
        return x;
    be[x] = find(be[x]);
    return be[x];
}
子任务 #1
Runtime Error
得分:0
测试点 #1
Runtime Error
得分:0
用时:19 ms
内存:6620 KiB

输入文件(1.in

17
3 3
1 9
7 8
4 0
2 6
12 5
3 0
0 10
0 11
0 0
5 3
10 10
6 5
8 0
9 2
8 1
5 0
5 1
7 
<2829398 bytes omitted>

答案文件(1.ans

10
20
0
7
0
123
163
244
999
1671
100930
181216
80898
1402126
60776271
1014605
19212781

系统信息

Killed: Segmentation fault
测试点 #2
Runtime Error
得分:0
用时:16 ms
内存:6544 KiB

输入文件(2.in

1
464 491
795 867
164 87
803 106
734 583
278 855
600 628
824 780
992 364
778 598
747 423

<1999727 bytes omitted>

答案文件(2.ans

60198435

系统信息

Killed: Segmentation fault
测试点 #3
Runtime Error
得分:0
用时:16 ms
内存:6576 KiB

输入文件(3.in

1
491 462
33 971
433 904
185 869
103 87
507 127
238 315
994 56
215 73
771 129
430 505
281
<1990927 bytes omitted>

答案文件(3.ans

59997625

系统信息

Killed: Segmentation fault
测试点 #4
Runtime Error
得分:0
用时:17 ms
内存:6636 KiB

输入文件(4.in

1
500 500
613 369
811 452
954 965
32 666
60 515
235 679
26 708
45 831
470 788
371 261
101
<2193863 bytes omitted>

答案文件(4.ans

66160818

系统信息

Killed: Segmentation fault