QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#781302 | #9802. Light Up the Grid | xcxc82 | WA | 55ms | 24108kb | C++23 | 1.9kb | 2024-11-25 15:36:54 | 2024-11-29 22:52:02 |
Judging History
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'