QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#781866 | #9802. Light Up the Grid | IGVA | WA | 89ms | 16308kb | C++14 | 1.9kb | 2024-11-25 17:49:22 | 2024-11-29 22:53:01 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define dep(i,a,b) for(int i=(a),i##_end=(b);i>=i##_end;--i)
using namespace std;
template<class T>inline T mymin(T x,T y){return x<y?x:y;}
template<class T>inline T mymax(T x,T y){return x>y?x:y;}
template <typename T>
inline void read(T &X){
X=0;int w=0; char ch=0;
while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
while(isdigit(ch)) X=X*10+(ch^48),ch=getchar();
if(w) X=-X;
}
const int maxn = 4e5 + 5;
//const double pi = acos(-1.0);
//const double eps = 1e-9;
//const int mo = 1e9 + 7;
int n,m,k;
int a[maxn],c[maxn],d[maxn];
int ans,tmp,cnt;
int flag;
char s[10][10];
bool ok[maxn][16];
int dp[maxn][16];
int jh[] = {1,2,4,8,3,12,5,10,15};
int w[] = {0,0,0,0,1,1,2,2,3};
queue<pair<int,int>>q;
int dfs(int i,int j){
if(ok[i][j]) return dp[i][j];
ok[i][j] = 1;
int ans = inf;
rep(l,0,8){
int nj = j ^ jh[l],ni;
ni = i;
if(ni >> nj & 1) ni ^= (1 << nj);
ans = mymin(ans,a[w[l]] + dfs(ni,nj));
}
rep(l,0,8){
int nj = j ^ jh[l],ni;
ni = i;
if(ni >> nj & 1) ni ^= (1 << nj);
dp[ni][nj] = mymin(dp[ni][nj],a[w[l]] + dp[i][j]);
}
return dp[i][j] = mymin(dp[i][j],ans);
}
void solve(){
read(n);
m = (1 << n) - 1;
int zt = 0;
rep(i,0,n - 1){
rep(j,0,1){
scanf("%s",s[j]);
}
c[i] = (s[0][0] & 1) | ((s[0][1] & 1) << 1) | ((s[1][0] & 1) << 2) | ((s[1][1] & 1) << 3);
c[i] ^= 15;
zt ^= (1 << c[i]);
}
printf("%d\n",dp[zt][0]);
}
int main(){
//cin.tie(0)->sync_with_stdio(false);
int T=1,cas=1;
read(T);
rep(i,0,(1 << 16) - 1) rep(j,0,15) {
dp[i][j] = inf;
ok[i][j] = 0;
}
rep(j,0,15) {
dp[0][j] = 0;
ok[0][j] = 1;
}
rep(i,0,3) read(a[i]);
rep(i,0,(1 << 16) - 1) rep(j,0,15)if(!ok[i][j]){
dfs(i,j);
}
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 82ms
memory: 15916kb
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: 78ms
memory: 14672kb
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: 79ms
memory: 16308kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 89ms
memory: 14376kb
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 36 42 38 40 41 36 44 34 37 37 32 29 39 39 40 38 39 44 37 29 37 37 38 34 34 32 41 34 36 41 40 44 34 37 34 29 36 39 40 42 35 39 37 38 39 41 29 40 41 36 41 43 40 41 34 42 39 37 33 34 38 38 37 42 40 34 36 28 34 32 38 36 39 38 37 36 38 34 34 34 34 42 40 38 38 40 40 37 40 38 29 36 40 36 34 ...
result:
wrong answer 50th numbers differ - expected: '38', found: '39'