比赛 |
20241024 |
评测结果 |
AAAAAAAAAA |
题目名称 |
费解的开关 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
0.099 s |
代码语言 |
C++ |
内存使用 |
3.53 MiB |
提交时间 |
2024-10-24 08:34:52 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 1e5+10;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n;
int a[10],b[10],s,ss = 7;
void modify(int x,int y){
s++;
if(x > 0)b[x-1] ^= (1 << y);
b[x] ^= (1 << y);
if(y < 4)b[x] ^= (1 << (y+1));
if(y > 0)b[x] ^= (1 << (y-1));
b[x+1] ^= (1 << y);
}
int main(){
freopen("switch.in","r",stdin);
freopen("switch.out","w",stdout);
cin>>n;
for(int i = 1;i <= n;i++){
ss = 7,s = 0;
memset(a,0,sizeof a);
memset(b,0,sizeof b);
for(int j = 0;j < 5;j++){
for(int k = 4;k >= 0;k--){
char x;
cin>>x;
a[j] = a[j] + ((x - '0') << k);
}
}
for(int j = 0;j <= 31;j++){
s = 0;
for(int k = 0;k < 5;k++)b[k] = a[k];
for(int k = 0;k < 5;k++)
if(j >> k & 1)modify(0,k);
for(int k = 0;k < 4;k++)
for(int l = 0;l < 5;l++)
if((b[k] >> l & 1) == 0)modify(k+1,l);
if(b[4] == 31 && s < ss)ss = s;
}
if(ss == 7)printf("-1\n");
else printf("%d\n",ss);
}
return 0;
}