QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187721#5741. Triterminant275307894aWA 6ms6684kbC++141.3kb2023-09-24 21:18:092023-09-24 21:18:11

Judging History

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

  • [2023-09-24 21:18:11]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:6684kb
  • [2023-09-24 21:18:09]
  • 提交

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 w[i][A[i]==1]=1+(i!=n);
	}
	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';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6060kb

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: 6ms
memory: 6684kb

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'