提交时间:2024-11-07 18:31:57

运行 ID: 34388

#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define p_b push_back using namespace std; typedef long long ll; const int maxn=1e6+10; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } int n,r[maxn],t[maxn]; int mark[maxn]; string s; void slv(){ n=read();cin>>s;s=" "+s; up(i,1,n)r[i]=read(); up(i,1,n)t[i]=read(); ll res=0; up(i,1,n){ mark[i]^=mark[i-1]; if((s[i]-'0')^mark[i])res+=t[i],mark[i+1]^=1,mark[r[i]+1]^=1; } cout<<res; } int main(){ //freopen("poker.in","r",stdin); //freopen("poker.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }