QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187639#5741. Triterminant275307894aWA 5ms4228kbC++141.1kb2023-09-24 19:31:212023-09-24 19:31:22

Judging History

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

  • [2023-09-24 19:31:22]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:4228kb
  • [2023-09-24 19:31:21]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=2e5+5,M=N*20+5,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(263082);
int n,A[N],ans,B[N];
void dfs(int x,int y,int z,int w){
	if(abs(y)>1||abs(z)>1) return;
	if(x==n+1){ans=min(ans,w);return;}
	B[x]=1;dfs(x+1,y+1,z+(x^1?y-B[x-1]:0),w+(B[x]!=A[x]));
	B[x]=-1;dfs(x+1,y-1,z-(x^1?y-B[x-1]:0),w+(B[x]!=A[x]));
}
void Solve(){
	int i,j;scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&A[i]);
	if(n>10){puts("-1");return;}
	ans=1e9+7;dfs(1,0,0,0);
	printf("%d\n",ans>n?-1:ans);
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4008kb

input:

3
4
1 1 1 1
2
1 -1
5
-1 1 1 1 -1

output:

2
0
2

result:

ok 3 number(s): "2 0 2"

Test #2:

score: -100
Wrong Answer
time: 5ms
memory: 4228kb

input:

3
27354
-1 -1 1 -1 1 1 1 1 -1 -1 1 1 -1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 1 -1 -1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 -1 1 -1 1 -1 1 1 -1 1 1 1 -1 1 1 1 1 -1 -1 -1 -1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 1 1 -1 1 1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 1 1 1 -1 -1 -1 1 1 1 -1 1 -1 -1 -1 ...

output:

-1
-1
-1

result:

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