QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#740238 | #5415. Ropeway | Zawos# | WA | 2ms | 3788kb | C++14 | 2.8kb | 2024-11-13 06:22:39 | 2024-11-13 06:22:40 |
Judging History
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(i!= (n+1) &&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(i >0 && 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;
}
}
cout <<ans<<'\n';
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
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 214 0 100
result:
ok 4 number(s): "206 214 0 100"
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3628kb
input:
500 19 6 285203460 203149294 175739375 211384407 323087820 336418462 114884618 61054702 243946442 19599175 51974474 285317523 222489944 26675167 300331960 1412281 324105264 33722550 169011266 1111111110110100011 18 3 127056246 5 100630226 14 301161052 2 331781882 5 218792226 2 190274295 12 49227476 ...
output:
2472886431 2299111966 2796055445 2650202148 2417273966 2508694561 2285479513 1765265336 2494894393 2240907690 2577284958 2494894393 2766700195 2511807344 2494894393 2438434986 2669077215 2682112324 470735446 674307759 211705888 564509290 715543137 492281467 341886459 18 19 19 19 20 18 54 15465560 15...
result:
wrong answer 8th numbers differ - expected: '2521569560', found: '1765265336'