QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#187712#5741. Triterminant275307894aWA 5ms6552kbC++141.4kb2023-09-24 21:04:022023-09-24 21:04:02

Judging History

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

  • [2023-09-24 21:04:02]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:6552kb
  • [2023-09-24 21:04:02]
  • 提交

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=(1<<18)+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,m,A[N],B[N],ans,w[N][2];
void Solve(int l,int r){
	if(r-l+1==2) return;
	if(r-l+1==4){
		cerr<<w[l][0]<<' '<<w[l][1]<<'\n';
		ans+=min(w[l][0],w[l][1])+min(w[l+2][0],w[l+2][1]);
		return;
	}
	int m=l+r>>1;
	for(int i=m+1;i<r-1;i+=2){
		if(i==m/2*3-1) w[i-m][0]+=w[i][1],w[i-m][1]+=w[i][0];
		else w[i-m][0]+=w[i][0],w[i-m][1]+=w[i][1];
	} 
	Solve(l,m);
}
void Solve(){
	int i,j;scanf("%d",&n);ans=0;
	m=1<<__lg(n)+1;
	for(i=1;i<=m;i++) Me(w[i],0);
	for(i=1;i<=n;i++) scanf("%d",&A[i]);
	for(i=1;i<n;i+=2){
		if(A[i]==A[i+1]) ans++;
		else if(A[i]==1) w[i][0]=2;
		else w[i][1]=2;
	}
	if(n&1) A[n+1]=-A[n],n++,w[n-1][A[n-1]^1?1:0]=1;
	Solve(1,m);printf("%d\n",ans);
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Test #1:

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

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: 6552kb

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:

11963
24585
6264

result:

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