QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#791005#9802. Light Up the GridOneWan#WA 122ms4488kbC++235.2kb2024-11-28 16:26:152024-11-28 16:26:15

Judging History

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

  • [2024-11-28 16:26:15]
  • 评测
  • 测评结果:WA
  • 用时:122ms
  • 内存:4488kb
  • [2024-11-28 16:26:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int long long
unordered_map<string, int> mp;
unordered_map<int, string> mp1;
const int N = 17, M = 10 + 1;
int a[30];
int t, a0, a1, a2, a3;
int dist[1ll<<16];
bool vis[1ll<<16];

void sol() {
    int m;
    cin >> m;

    vector<string>s(m);
    int state=0;
    for (int i = 0; i < m; i++) {
        string p;
        cin >> s[i] >> p;
        s[i] += p;
        state|=(1ll<<mp[s[i]]); 
    }
    
  //  cout<<state<<'\n';
     auto upd = [&](string& p, int i) -> void {
        int x = 1 - (p[i] - '0');
        p[i] = (char)(x + '0');
    };

    auto tr = [&](const string& s, int op) -> string { 
            if(op<=4){
                string p=s;
                upd(p,op-1);
                return p;
            }else if(op==5||op==6){
                if(op==5){
                    string p = s;
                    upd(p, 0), upd(p, 1); 
                    return p;
                }else if(op==6){
                    string p = s;
                    upd(p, 1), upd(p, 0); 
                    return p;
                }
            }else if(op==7||op==8){
                if(op==7){
                    string p = s;
                    upd(p, 3), upd(p, 1); 
                    return p;
                }else{
                    string p = s;
                    upd(p, 0), upd(p, 2); 
                    return p;
                }
            }else if(op==9){
                string p = s;
                upd(p, 2), upd(p, 1);  
                upd(p, 0), upd(p, 3);
                return p;
            }
               
    };


    if(state>>15&1){
        int ans=1e18;
          for(int i=1;i<=9;i++){
            int k=0;
            for(int j=0;j<=15;j++){
                if(1ll&(state>>j)){
                    string xx=tr(mp1[j],i);
                    int numnum=mp[xx];
                    k|=(1ll<<numnum);
                }
            }
            if(k>>15&1){
                k^=(1ll<<15);
            }
            ans=min(ans,a[i]+dist[k]);
        }
        cout<<ans<<'\n';

    }else{
        cout<<dist[state]<<'\n';
    }
}

struct node{
    int state;
    int cost;
    bool operator < (const node other)const{
        return cost>other.cost;
    }
};

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

    
    cin >> t >> a0 >> a1 >> a2 >> a3;
    a1 = min(a1, 2 * a0);
    a2 = min(a2, 2 * a0);
    a3 = min({a3, 4 * a0, 2 * a1, 2 * a2});
    a[1]=a[2]=a[3]=a[4]=a0;
    a[5]=a[6]=a1;
    a[7]=a[8]=a2;
    a[9]=a3;
    for (int i = 0; i < 16; i++) {
        int x = i;
        string s = "";
        for (int j = 0; j < 4; j++) {
            s += (char)(x % 2 + '0');
            x /= 2;
        }
        reverse(s.begin(), s.end());
        mp[s] = i; 
        mp1[i] = s;
    }

    auto upd = [&](string& p, int i) -> void {
        int x = 1 - (p[i] - '0');
        p[i] = (char)(x + '0');
    };

    auto tr = [&](const string& s, int op) -> string { 
            if(op<=4){
                string p=s;
                upd(p,op-1);
                return p;
            }else if(op==5||op==6){
                if(op==5){
                    string p = s;
                    upd(p, 0), upd(p, 1); 
                    return p;
                }else if(op==6){
                    string p = s;
                    upd(p, 1), upd(p, 0); 
                    return p;
                }
            }else if(op==7||op==8){
                if(op==7){
                    string p = s;
                    upd(p, 3), upd(p, 1); 
                    return p;
                }else{
                    string p = s;
                    upd(p, 0), upd(p, 2); 
                    return p;
                }
            }else if(op==9){
                string p = s;
                upd(p, 2), upd(p, 1);  
                upd(p, 0), upd(p, 3);
                return p;
            }
               
    };

    string s = "1111";
    
    memset(dist,0x3f3f3f3f,sizeof dist);
    dist[0]=0;
    priority_queue<node>tp;
    tp.push({0,0});
    while(tp.size()){
        auto [state,cost]=tp.top();
        tp.pop();

        

        if(vis[state]){
            continue;
        }
        vis[state]=true;
        for(int i=1;i<=9;i++){
            int k=0;
            for(int j=0;j<15;j++){
                if(1ll&(state>>j)){
                    string xx=tr(mp1[j],i);
                    int numnum=mp[xx];
                    k|=(1ll<<numnum);
                }
            }
            if(k>>15&1){
                k^=(1ll<<15);
            }
            if(dist[k]>dist[state]+a[i]){
                
                dist[k]=dist[state]+a[i];
                tp.push({k,dist[k]});
            }
            string p="1111";
            k|=(1ll<<mp[tr(p,i)]);
            if(k>>15&1){
                k^=(1ll<<15);
            }
            if(dist[k]>dist[state]+a[i]){

                dist[k]=dist[state]+a[i];
                tp.push({k,dist[k]});
            }
        }
        
    }
    while(t--) {
        sol();
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 95ms
memory: 4316kb

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: 90ms
memory: 4488kb

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: 93ms
memory: 4268kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 122ms
memory: 4324kb

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:

38
44
42
44
46
42
52
40
42
50
38
50
36
38
40
38
37
41
40
46
40
46
50
48
35
38
42
41
40
39
36
48
42
50
46
46
48
40
40
40
37
40
40
46
49
39
45
50
46
43
46
35
48
50
40
50
48
40
48
36
46
42
42
39
40
42
42
44
48
44
40
38
35
36
38
42
40
44
38
44
48
50
37
44
42
40
42
46
40
42
44
46
45
45
42
39
36
44
44
38
...

result:

wrong answer 1st numbers differ - expected: '34', found: '38'