QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#782828 | #5415. Ropeway | lfyszy | RE | 2ms | 3892kb | C++14 | 1.9kb | 2024-11-25 21:44:02 | 2024-11-25 21:44:02 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define SP << " " <<
#define fish signed
using namespace std;
mt19937 rnd(1209);
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 3e3 + 10;
int n, k, dp[2][N];
int mn[N];
int q[N], a[N];
void solve()
{
cin >> n >> k;
for(int i = 1; i <= n; i ++) cin >> a[i];
string s; cin >> s; s = "Y" + s;
int hh = 1, tt = 1; q[1] = 0;
for(int i = 1; i <= n; i ++)
{
while(hh <= tt && q[hh] < i - k) hh ++;
dp[0][i] = dp[0][q[hh]] + a[i]; if(s[i] == '1') hh = tt + 1;
while(hh <= tt && dp[0][q[tt]] >= dp[0][i]) tt --; q[++ tt] = i;
}
hh = 1, tt = 1; q[1] = n + 1; dp[1][n + 1] = 0;
for(int i = n; i; i --)
{
while(hh <= tt && q[hh] > i + k) hh ++;
dp[1][i] = dp[1][q[hh]] + a[i]; if(s[i] == '1') hh = tt + 1;
while(hh <= tt && dp[1][q[tt]] >= dp[1][i]) tt --; q[++ tt] = i;
}
// for(int i = 1; i <= n; i ++) cerr << dp[0][i] SP dp[1][i] << "\n";
int t; cin >> t;
while(t --)
{
int pos, x; cin >> pos >> x;
int up = min(n + 1, pos + k), ans = INF;
mn[pos] = dp[1][pos] - a[pos] + x;
for(int i = pos; i <= pos + k && i <= n + 1; i ++)
{
if(i != pos) mn[i] = min(mn[i - 1], dp[1][i]);
if(s[i] == '1') {up = i; break;}
// cerr << i SP mn[i] << "!!!\n";
}
for(int i = pos - 1; i >= pos - k && i >= 0; i --)
{
chmin(ans, dp[0][i] + mn[min(i + k, up)]);
if(s[i] == '1') break;
}
cout << ans << "\n";
}
// cerr << "------------------\n";
}
fish main()
{
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while(t --) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3884kb
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: 0
Accepted
time: 2ms
memory: 3652kb
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 2521569560 2521569560 2240907690 2577284958 2521569560 2766700195 2511807344 2521569560 2438434986 2669077215 2682112324 470735446 470735446 211705888 564509290 715543137 470735446 470735446 18 19 19 19 20 19 54 849950346 8...
result:
ok 5277 numbers
Test #3:
score: 0
Accepted
time: 2ms
memory: 3892kb
input:
50 183 160 22617237 21369258 39718669 4582413 28629717 25947766 1690897 19844235 35568283 42909820 21829213 70588436 8472484 53107624 21547259 11440081 6630789 5896457 19770793 30204510 29796593 27689811 39350369 21646987 36362667 38164292 13428410 54681069 24526477 58941286 70890011 43730474 388615...
output:
5303746210 5262479222 5346682277 5299354906 5290045662 5350552810 5343191051 5268759163 5299354906 5340227887 5299354906 5253956732 5289945955 5230918240 5287812187 5299354906 5299354906 5273800386 5299354906 5299354906 5353471727 5283662384 5230330060 5319166005 5338060400 5304825609 5268929476 526...
result:
ok 9541 numbers
Test #4:
score: -100
Runtime Error
input:
3 500000 891 806445768 895003544 461699845 184479965 853541910 593542573 667984604 465354540 303586741 243665567 285056069 294245042 675066412 456713460 215929340 756894934 773828574 317143965 451366539 891390118 436168373 633752416 78781758 298770626 35280548 226923750 96421159 523108871 265102517 ...