QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187688 | #5741. Triterminant | 275307894a | WA | 6ms | 6532kb | C++14 | 1.4kb | 2023-09-24 20:38:41 | 2023-09-24 20:38:41 |
Judging History
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==m/4*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: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';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5860kb
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: 6532kb
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:
11797 24513 6284
result:
wrong answer 1st numbers differ - expected: '13567', found: '11797'