求助wa
查看原帖
求助wa
1122530
elpsconr楼主2024/8/8 21:13

我这个代码有什么问题吗??我感觉我写的很对啊,但是算上样例只过了10个点,感觉不是精度问题,因为 我用int和double都是只对10个点

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
const int N=3e5+6,yyx=4e9+7;
const long double eps=1e-6;
int n,t,st[N],pre[N];
long double a[N],d;
bool check(int l,int r){
    return a[r]-a[l]-d<eps;
}
void solve(){
  string s;
  cin>>n>>t>>s;
  for(int i=0;i<n;++i) pre[i+1]=pre[i]+(s[i]=='0');
  for(int i=1;i<=n;++i) cin>>a[i];
  sort(a+1,a+1+n);
  int ans=0;
  d=2*t+0.2;
  for(int l=1,r=2;l<=n;++l){
    if(s[l-1]=='1'){
        //cout<<l<<" "<<r<<endl;
        while(check(l,r)&&r<=n){
            r++;
        }
        //cout<<l<<" "<<r<<endl;
        ans+=pre[r-1]-pre[l];
    }
  }
  cout<<ans<<endl;
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int _=1;
    //cin>>_;
    while(_--)
    solve();
    return 0;
}
2024/8/8 21:13
加载中...