37行小清新贪心代码求调
查看原帖
37行小清新贪心代码求调
374769
Epi4any楼主2024/7/29 08:58

此题大约为绿题难度,莫名其妙地wa23

调了半个多小时蚌埠住了

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+10;
ll n,k,a[maxn],s,ans;
vector<ll> _pow;
map<ll, ll> mp;
int main() {
    cin>>n>>k;
    if(k==1) {
        _pow.push_back(1ll);
    } else if(k==-1) {
        _pow.push_back(-1ll);
        _pow.push_back(1ll);
    } else {
        ll tmp=1ll;
        while(llabs(tmp)<=1e9) {
            _pow.push_back(tmp);
            tmp*=k;
        }
    }
    mp[0]=1;
    for(ll i=1;i<=n;i++) {
        cin>>a[i];
        s+=a[i];
        mp[s]++;
        for(auto it:_pow) {
            ll tar=s-it;
            ans+=mp[tar];
//            if(mp[tar]>0) {
//                cout<<s<<" "<<tar<<" "<<mp[tar]<<endl;
//            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
2024/7/29 08:58
加载中...