QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#787300#9802. Light Up the Gridticking_away#WA 51ms3840kbC++204.0kb2024-11-27 10:58:272024-11-27 10:58:28

Judging History

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

  • [2024-11-27 10:58:28]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:3840kb
  • [2024-11-27 10:58:27]
  • 提交

answer

#include <bits/stdc++.h>
#define con const
using namespace std;

using i32 = int32_t;
using i64 = int64_t;
#define i128 __int128_t
using u32 = uint32_t;
using u64 = uint64_t;
using f64 = long double;

template<class T>
using lque = priority_queue<T, vector<T>, greater<T>>;
template<class T>
using gque = priority_queue<T>;

template<class T>
void mes(T * arr, int sz=1, int val=0) {
    memset(arr, val, sz*sizeof(T));
}

// constexpr u32 IBUF_LEN = 1 << 16;
// char ibuf[1<<16], *ifr = ibuf, *ied = ibuf;
// #define fread() (ied=(ifr=ibuf)+fread(ibuf,1,IBUF_LEN,stdin),ifr==ied) // 单次fread不会等待输入
// #define ischar(c) (!isspace(c)&&c!=EOF)
// char gc() { return (ifr==ied && fread()) ? EOF : *(ifr++); } // 读取并弹出字符(类似getchar)
// char gr() { return (ifr==ied && fread()) ? EOF : *ifr; } // 读取字符
// char fit() { while(isspace(gr())) ++ifr; return gr(); } // 将空字符丢弃,并返回第一个非空字符或EOF
// #undef fread
 
// template<class T> T &fin(T &v) {
//     i32 c = v = 0; bool f = fit()=='-'; ifr += f;
//     while(isdigit(c=gc())) v = v*10 + (c ^ 48);
//     return f ? (v=-v) : v;
// }
 
// template<class T> void fin(T arr[], u32 n) {
//     for(u32 i=0; i<n; ++i) fin(arr[i]);
// }
 
// // 读取非空字符(建议手动gc(),这个只是简写)
// template<> char &fin(char &v) { return fit(), v = gc(); }
template<u32 LEN>
struct DSU {
    u32 far[LEN] = {0}, rnk[LEN] = {0};
    void init(u32 l, u32 r) {
        mes(rnk+l, r-l);
        for(; l<r; ++l) far[l] = l;
    }
    u32 find(u32 u) {
        if(far[u]==u) return u;
        else return far[u] = find(far[u]);
    }
    bool same(u32 l, u32 r) { return find(l) == find(r); }
    bool merge(u32 l, u32 r) {
        if((l=find(l)) == (r=find(r))) return 0;
        if(rnk[l]<rnk[r]) swap(l, r); // WARN: l',r'与l,r无一一对应关系
        else if(rnk[l]==rnk[r]) ++rnk[l];    // 按高度度合并
        // rnk[l] += rnk[r] + 1;           // 按大小
        return far[r]=l, 1;
    }
};
// -------------------
con u32 MX = 2e6 + 7;
con u64 MOD = 998244353;
// con u64 MOD = 1e9+7;

u32 n, cst[4], gip[16];
u32 w[16][16], w0;

// 完全图最小生成树
vector<array<u32, 3>> edges;
DSU<17> dsu;

void solve() {
    edges.clear();
    for(u32 i=0; i<n; ++i) {
        edges.push_back({gip[i]?w[0][gip[i]]:w0, i, n});
    }
    for(u32 u=0; u<n; ++u)
        for(u32 v=0; v<n; ++v)
            edges.push_back({w[gip[u]][gip[v]], u, v});
    sort(edges.begin(), edges.end());
    u32 ans = 0;
    dsu.init(0, n+1);
    for(auto [dw, u, v]:edges) {
        if(dsu.merge(u, v)) {
            ans += dw;
        }
    }
    cout << ans << '\n';
}

void pre() {
    cin >> n;
    string ip;
    for(u32 i=0; i<n; ++i) {
        gip[i] = 0;
        cin >> ip;
        for(char ch:ip)
            gip[i] = (gip[i]<<1)|(ch=='1');
        cin >> ip;
        for(char ch:ip)
            gip[i] = (gip[i]<<1)|(ch=='1');
        gip[i] ^= 15;
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    u32 _t = 1;
    cin >> _t;
    for(u32 i=0; i<4; ++i) cin >> cst[i];

    memset(w, -1, sizeof(w));
    for(u32 u=0; u<16; ++u) {
        for(u32 i=0; i<4; ++i) {
            u32 v = u^(1<<i);
            w[u][v] = min(w[u][v], cst[0]);
        }
        for(u32 i=0; i<2; ++i) {
            u32 v = u^(3<<(i*2));
            w[u][v] = min(w[u][v], cst[1]);
        }
        for(u32 i=0; i<2; ++i) {
            u32 v = u^(5<<i);
            w[u][v] = min(w[u][v], cst[2]);
        }
        w[u][u^15] = min(w[u][u^15], cst[3]);
    }

    for(u32 k=0; k<16; ++k) {
        for(u32 u=0; u<16; ++u) {
            if(!~w[u][k]) continue;
            for(u32 v=0; v<16; ++v) {
                if(!~w[k][v]) continue;
                w[u][v] = min(w[u][v], w[u][k]+w[k][v]);
            }
        }
    }

    w0 = w[0][0];
    for(u32 i=0; i<16; ++i) w[i][i] = 0;

    for(;_t--;) {
        pre();
        solve();
    }
}

详细

Test #1:

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

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1121
2

result:

ok 2 number(s): "1121 2"

Test #2:

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

input:

2 1 1 1 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

5
2

result:

ok 2 number(s): "5 2"

Test #3:

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

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 51ms
memory: 3688kb

input:

10000 8 2 7 8
8
00
01

00
11

00
10

11
11

10
10

01
10

01
00

10
11
8
11
01

11
00

01
10

11
11

00
01

01
01

01
00

11
10
9
00
00

01
01

10
11

00
01

11
10

11
00

11
11

00
11

01
10
9
11
11

10
00

11
00

11
01

00
10

01
11

00
01

01
01

10
01
11
00
01

01
01

10
10

00
11

11
11

11
10
...

output:

34
32
36
36
38
36
42
36
38
38
36
44
34
34
36
32
29
36
36
38
34
38
42
36
27
34
36
36
32
33
32
40
34
36
38
40
42
34
36
32
29
36
38
40
40
34
39
36
38
36
40
29
38
40
36
38
42
40
40
34
41
38
34
32
34
38
36
36
40
36
34
34
27
34
32
38
36
38
36
36
36
36
31
34
34
34
38
38
38
38
40
40
36
36
36
27
32
36
36
34
...

result:

wrong answer 5th numbers differ - expected: '40', found: '38'