QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#781302#9802. Light Up the Gridxcxc82WA 55ms24108kbC++231.9kb2024-11-25 15:36:542024-11-29 22:52:02

Judging History

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

  • [2024-11-29 22:52:02]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:55ms
  • 内存:24108kb
  • [2024-11-25 15:36:55]
  • 评测
  • 测评结果:0
  • 用时:49ms
  • 内存:24096kb
  • [2024-11-25 15:36:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = (1<<16)+10;
struct Node {
    int node,T,ans;
    bool operator < (const Node x) const {
        return ans > x.ans;
    }
};

int ans;
int tag[10] = {0,1,2,4,8,3,12,5,10,15};
int f[MAXN][20];//计算答案
int vis[MAXN][20];
int T,a1,a2,a3,a4;
void dfs(int S,int T) {//当前状态为S,异或值为T时的最优解
    ans++;
    vis[S][T] = 1;
    if (S==(1<<16)-1) {
        f[S][T] = 0;
        return;
    }
    for (int i=1;i<=9;i++) {
        int now = tag[i]^T;
        int w = 0;
        int pos = (15^now);
        int Snxt = S;
        if (i<=4) w = a1;
        else if (i<=6) w = a2;
        else if (i<=8) w = a3;
        else w = a4;
        if ((S&(1<<pos))==0) Snxt|=(1<<pos);
        if (!vis[Snxt][now]) dfs(Snxt,now);
        f[S][T] = min(f[S][T],f[Snxt][now]+w);
    }
    for (int i=1;i<=9;i++) {
        int now = tag[i]^T;
        int w = 0;
        int pos = (15^now);
        int Snxt = S;
        if (i<=4) w = a1;
        else if (i<=6) w = a2;
        else if (i<=8) w = a3;
        else w = a4;
        if (!vis[Snxt][now]) dfs(Snxt,now);
        f[S][T] = min(f[S][T],f[Snxt][now]+w);
    }
}
signed main(){
    memset(f,0x3f,sizeof(f));
    cin>>T>>a1>>a2>>a3>>a4;
    for (int i=0;i<(1<<16);i++) {
        if (!vis[i][0]) dfs(i,0);
    }
    while (T--) {//1次单 1次行 2次列 一次全
        int m;
        cin>>m;
        int S = (1<<16)-1;
        for (int i=1;i<=m;i++) {
            char a,b,c,d;
            cin>>a>>b>>c>>d;
            int now = 0;
            if (a=='1') now++;
            if (b=='1') now+=2;
            if (c=='1') now+=4;
            if (d=='1') now+=8;
            S ^= (1<<now);
        }
        cout<<f[S][0]<<endl;
    }
}
/*
2 1000 100 10 1
4
10
00
01
00
00
10
00
01
 */

詳細信息

Test #1:

score: 0
Wrong Answer
time: 55ms
memory: 24108kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1121
2000

result:

wrong answer 2nd numbers differ - expected: '2', found: '2000'