QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#814438#9802. Light Up the GridYipChip#WA 99ms15060kbC++232.4kb2024-12-14 17:33:502024-12-14 17:33:52

Judging History

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

  • [2024-12-14 17:33:52]
  • 评测
  • 测评结果:WA
  • 用时:99ms
  • 内存:15060kb
  • [2024-12-14 17:33:50]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int head[16],nxt[1000],to[1000],w[1000],tot=0;

void addEdge(int u,int v,int ww) {
    to[tot] = v;
    nxt[tot] = head[u];
    w[tot] = ww;
    head[u] = tot++;
}

int dis[16][1<<16];
int ans[1<<16];

struct Node{
    int no;
    int vis;
    int dis;
};

struct cmp{
    bool operator()(Node &a,Node &b) {
        return a.dis>b.dis;
    }
};

int main() {
    int T,a0,a1,a2,a3;
    
    memset(dis,-1,sizeof(dis));
    memset(head,-1,sizeof(head));
    memset(ans,-1,sizeof(ans));

    scanf("%d%d%d%d%d",&T,&a0,&a1,&a2,&a3);

    for (int i=0;i<16;++i) {
        addEdge(i,i^1,a0);
        addEdge(i,i^2,a0);
        addEdge(i,i^4,a0);
        addEdge(i,i^8,a0);
        addEdge(i,i^3,a1);
        addEdge(i,i^12,a1);
        addEdge(i,i^5,a2);
        addEdge(i,i^10,a2);
        addEdge(i,i^15,a3);
    }

    priority_queue<Node,vector<Node>,cmp> pq;

    dis[15][0] = 0;
    pq.push((Node){15,0,0});
    while (!pq.empty()) {
        int u = pq.top().no;
        int vi = pq.top().vis;
        int dd = pq.top().dis;
        pq.pop();
        if (dd>dis[u][vi]) continue;
        for (int i=head[u];~i;i=nxt[i]) {
            int v = to[i];
            int nvi = vi | (1<<v);
            if (dis[v][nvi] == -1 || dis[v][nvi] > dis[u][vi] + w[i]) {
                dis[v][nvi] = dis[u][vi] + w[i];
                pq.push((Node){v,nvi,dis[v][nvi]});
            }
        }
    }

    for (int i=(1<<16)-1;i>=0;i--) {
        for (int j=0;j<16;++j) {
            if (~dis[j][i]) {
                if (ans[i] == -1 || ans[i] > dis[j][i]) ans[i] = dis[j][i];
            }
        }    
    }

    for (int i=(1<<16)-1;i>=0;i--) {
        for (int j=0;j<16;j++) {
            if (i&(1<<j)) continue;
            if (ans[i|(1<<j)] == -1) continue;
            if (ans[i] == -1 || ans[i] > ans[i|(1<<j)]) ans[i] = ans[i|(1<<j)]; 
        }
    }

    while (T--) {
        int need=0,m;
        scanf("%d",&m);
        char str[10];
        for (int i=1;i<=m;i++) {
            if (i!=1) scanf("%s",str);
            int now=0;
            scanf("%s",str);
            if (str[0]=='1') now|=1;
            if (str[1]=='1') now|=2;
            scanf("%s",str);
            if (str[0]=='1') now|=4;
            if (str[1]=='1') now|=8;
            need|=(1<<now);
        }
        printf("%d\n",ans[need]);
    }   

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 99ms
memory: 15060kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1113
2

result:

wrong answer 1st numbers differ - expected: '1121', found: '1113'