QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#740241#5415. RopewayZawosWA 0ms3540kbC++142.8kb2024-11-13 06:36:252024-11-13 06:36:25

Judging History

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

  • [2024-11-13 06:36:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3540kb
  • [2024-11-13 06:36:25]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using ld=long double;
using vi=vector<int>;
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
//上
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while(t--){
        ll n,k;
        cin >> n >> k;
        vector<ll> v(n+2);
        vector<ll> dp1(n+2,1e18);
        vector<ll> dp2(n+2,1e18);
        dp1[0] =0;
        dp2[n+1] = 0;
        set<pair<ll,ll>> aux;
        FOR(i,1,n+1) cin >> v[i];
        string s;
        cin >> s;
        int last = 0;
        aux.insert({0,0});
        s.push_back('#');
        for(int i = 1; i <= n; i++){
                if(i-last > k){
                    aux.erase({dp1[last],last});
                    last++;
                }
                pair<ll,ll> pa = *aux.begin();
                dp1[i] = pa.first+v[i];
                aux.insert({dp1[i],i});
                if(s[i-1] == '1'){
                    for(int j = last; j <i; j++){
                        aux.erase({dp1[j],j});
                    }
                    last = i;
                }
        }
        // for(ll i = n; i>= max(0LL,n-k);i--) dp1[n+1] = min(dp1[i],dp1[n+1]);
        aux.clear();
        last = n+1;
        aux.insert({0,n+1});
        for(int i = n; i >= 1; i--){
                if(last-i > k){
                    aux.erase({dp2[last],last});
                    last--;
                }
                pair<ll,ll> pa = *aux.begin();
                dp2[i] = pa.first+v[i];
                aux.insert({dp2[i],i});
                if(s[i-1] == '1'){
                    for(int j = last; j >i; j--){
                        aux.erase({dp2[j],j});
                    }
                    last = i;
                }
        }
        // for(ll i = 1; i<= min(n+1,k); i++) dp2[0] = min(dp2[i],dp2[0]);
        aux.clear();
        int q;
        cin >> q;
        for(int i = 0; i < q; i++){
            ll a,b;
            cin >> a >> b;
            ll ans = dp1[a]+dp2[a]-2*v[a]+b;
            if(s[a-1] == '1'){
                cout <<ans<<'\n';
                continue;
            }
            ll mn = dp2[a+1];
            bool ok = true;
            for(int j = max(0LL,a+1-k); j < a; j++){
        
                if(ok && j+k <= n+1) mn = min(mn,dp2[j+k]);
                ans = min(ans,dp1[j]+mn);
                if(s[j+k-1] == '1'){
                    ok = false;
                }
                if(j > 0 &&s[j-1] == '1') break;
            }
            cout <<ans<<'\n';
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3540kb

input:

3
10 3
5 10 7 100 4 3 12 5 100 1
0001000010
2
2 3
6 15
5 6
1 1 1 1 1
00000
1
3 100
5 6
1 1 1 1 1
00100
1
3 100

output:

206
217
0
100

result:

wrong answer 2nd numbers differ - expected: '214', found: '217'