QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#781588#9802. Light Up the GridqilouWA 77ms3656kbC++233.7kb2024-11-25 16:34:042024-11-29 22:52:27

Judging History

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

  • [2024-11-29 22:52:27]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:77ms
  • 内存:3656kb
  • [2024-11-25 16:34:07]
  • 评测
  • 测评结果:0
  • 用时:77ms
  • 内存:3652kb
  • [2024-11-25 16:34:04]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n';
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const int N=5e5+10,inf=1e9+10,M=3e6+10,mod=1e9+7;
int n,m,k,minn=inf;
int p[5];
map<vector<int>,int> mp;
vector<int> np;
void dfs3(int now,int v){
    if(mp[np]==0){
        if(now!=-1){
            mp[np]=inf;
        }
    }
    mp[np]=min(mp[np],v);
    for(int j=0;j<=3;j++){
        if(np[j]){
            np[j]=0;
        }else np[j]=1;
    }
    mp[np]=min(mp[np],v+p[4]);
    for(int j=0;j<=3;j++){
        if(np[j]){
            np[j]=0;
        }else np[j]=1;
    }
}
void dfs2(int now,int v){

    for(int i=max(now,0ll);i<=1;i++){
        for(int j=0;j<=3;j+=2){
            if(np[i+j]){
                np[i+j]=0;
            }else np[i+j]=1;
        }
        dfs3(0,v+p[3]);
        dfs2(i+1,v+p[3]);
        for(int j=0;j<=3;j+=2){
            if(np[i+j]){
                np[i+j]=0;
            }else np[i+j]=1;
        }
    }
    dfs3(-1,v);

}
void dfs1(int now,int v){
    for(int i=max(now,0ll);i<=1;i++){
        for(int j=0;j<=1;j++){
            if(np[i*2+j]){
                np[i*2+j]=0;
            }else np[i*2+j]=1;
        }
        dfs2(0,v+p[2]);
        dfs1(i+1,v+p[2]);
        for(int j=0;j<=1;j++){
            if(np[i*2+j]){
                np[i*2+j]=0;
            }else np[i*2+j]=1;
        }
    }
    dfs2(-1,v);
}
void dfs(int now,int v){
    for(int i=max(now,0ll);i<=3;i++){
        np[i]=1;
        dfs1(0,v+p[1]);
        dfs(i+1,v+p[1]);
        np[i]=0;
    }
    dfs1(-1,v);
}
void ini(){
    // dfs(0,0);
    // for(auto t : mp){
    //     t.second=inf;
    // }
    vector<int> tt;
    for(int i=1;i<=4;i++){
        tt.push_back(1);
    }
    mp[tt]=p[4];
    dfs(-1,0);
}
vector<vector<pii>> g(20);
int dist[20];
void solve(){
    cin>>n;
    vector<vector<int>> ns;
    vector<int> tt;
    for(int i=1;i<=4;i++){
        tt.push_back(1);
    }

    ns.push_back(tt);
    for(int i=1;i<=n;i++){
        string s,s1;
        cin>>s>>s1;
        vector<int> t;
        t.push_back(s[0]-'0');
        t.push_back(s[1]-'0');
        t.push_back(s1[0]-'0');
        t.push_back(s1[1]-'0');
        ns.push_back(t);
    }
    
    int nz=ns.size();
    for(int i=0;i<=nz;i++){
        g[i].clear();
        dist[i]=inf;
    }
    // if(n==1&&tt==ns[1]){
    //     cout<<minn*2<<endl;
    //     return ;
    // }
    for(int i=0;i<nz;i++){
        for(int j=0;j<nz;j++){
            if(i==j)continue;
            vector<int> t(4);
            for(int k=0;k<=3;k++){
                t[k]=abs(ns[i][k]-ns[j][k]);
            }
            g[i].push_back({mp[t],j});
        }
        sort(g[i].begin(),g[i].end());
    }
    int num=0;
    dist[0]=0;
    int idx=0;
    int ans=0;
    while(num<n){
      //  cout<<"idx: "<<idx<<endl;
        int gz=g[idx].size();
        for(int i=0;i<gz;i++){
            int st=g[idx][i].second,v=g[idx][i].first;
            if(dist[st]!=inf)continue;
            if(dist[st]>dist[idx]+v){
                dist[st]=dist[idx]+v;
             //   cout<<st<<" "<<dist[st]<<endl;
                idx=st;
                ans=dist[st];
                num++;
                // cout<<q.front().second<<" "<<q.size()<<endl;
                break;
            }
        }
    }
    cout<<ans<<endl;

}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T=1;
    cin>>T;
    for(int i=1;i<=4;i++){
        cin>>p[i];
        minn=min(minn,p[i]);
        np.push_back(0);
    }
    ini();
    mp[np]=minn*2;
    while(T--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3508kb

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: 1ms
memory: 3620kb

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: 1ms
memory: 3656kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 77ms
memory: 3580kb

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

result:

wrong answer 6th numbers differ - expected: '36', found: '38'