QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#787345#9802. Light Up the GridtilennWA 152ms8168kbC++142.1kb2024-11-27 11:12:482024-11-27 11:13:25

Judging History

你现在查看的是测评时间为 2024-11-27 11:13:25 的历史记录

  • [2024-11-29 22:56:32]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:161ms
  • 内存:8172kb
  • [2024-11-27 11:13:25]
  • 评测
  • 测评结果:0
  • 用时:152ms
  • 内存:8168kb
  • [2024-11-27 11:12:48]
  • 提交

answer

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

#define endl '\n';
typedef long long LL;
typedef unsigned long long ULL;

vector<LL> a(4);
vector<pair<ULL,LL>> md;
vector<LL> dist(1 << 16,1e9);

struct Node{
    ULL f,g;
    bool operator<(Node a) const {
        return g < a.g;
    }
    bool operator>(Node a) const {
        return g > a.g;
    }
bool operator==(Node a) const {
        return f == a.f && g == a.g;
    }
};

void init(){
    priority_queue<pair<LL,Node>,vector<pair<LL,Node>>,greater<pair<LL,Node>>> q;
    map<Node,LL> mp;
    Node tmp;
    tmp.f = tmp.g = 0;
    for(int i = 0;i < 16;i++){
        tmp.f |= ULL(i) << (4 * i);
    }
    q.push({0,tmp});

    int co = 0;

    while(q.size()){
        auto [w,s] = q.top();
        q.pop();
        if(mp[s] < w)continue;
        for(int i = s.g;i > 0;i = (i - 1) & s.g){
            dist[i] = min(dist[i],w);
        }
        for(auto [t,c] : md){
            auto mk = s;
            for(int i = 0;i < 16;i++){
                mk.f ^= t << (4 * i);
                if((mk.f >> (4 * i) & 15) == 15){
                    mk.g |= 1LL << i;
                }
            }
            if(!mp.count(mk) || mp[mk] > w + c){
                mp[mk] = w + c;
                q.push({w + c,mk});
            }
        }
    }   

}

void solve(){
    int n;
    cin >> n;
    int s = 0;
    for(int i = 1;i <= n;i++){
        string x,y;
        cin >> x >> y;
        int z = 0;
        z += 8 * (x[0] - '0');
        z += 4 * (x[1] - '0');
        z += 2 * (y[0] - '0');
        z += (y[1] - '0');
        s += 1 << z;
    }
    cout << dist[s] << endl;



}   

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t = 1;
    cin >> t;
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    for(int i = 0;i < 4;i++){
        md.push_back({1 << i,a[0]});
    }
    md.push_back({12,a[1]});
    md.push_back({3,a[1]});
    md.push_back({10,a[2]});
    md.push_back({5,a[2]});
    md.push_back({15,a[3]});
    init();
    while(t--){
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 151ms
memory: 8168kb

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: 126ms
memory: 7696kb

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: 125ms
memory: 7760kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 152ms
memory: 7904kb

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
37
42
36
42
38
40
42
36
44
34
37
38
32
29
39
40
40
38
40
46
38
31
38
37
38
34
35
32
41
34
36
41
40
45
34
38
34
29
36
40
40
43
35
40
38
38
38
42
29
41
41
36
42
44
40
42
35
42
40
38
33
34
39
38
37
42
40
34
36
29
34
34
38
36
40
38
37
36
38
35
34
36
34
42
40
38
40
40
40
38
42
38
29
36
40
36
36
...

result:

wrong answer 4th numbers differ - expected: '36', found: '37'