QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#567875 | #7973. 括号 | ASnown | 0 | 0ms | 0kb | C++14 | 1.3kb | 2024-09-16 14:25:34 | 2024-09-16 14:25:35 |
answer
#include<bits/stdc++.h>
#define file(F) freopen(#F".in","r",stdin),freopen(#F".out","w",stdout)
#define lowbit(x) ((x)&-(x))
#define ALL(x) x.begin(),x.end()
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define popcount(x) (__builtin_popcount((x)))
using namespace std;
using ll=long long;
using uint=uint32_t;
template<typename T>
inline bool Max(T &x,T y) { return std::less<T>()(x,y)&&(x=y,true); }
template<typename T>
inline bool Min(T &x,T y) { return std::less<T>()(y,x)&&(x=y,true); }
void Solve();
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e2+12;
int n,Q;
int a[N];
char s[N];
ll f[N][N];
signed main() {
#ifndef ONLINE_JUDGE
#endif
cin.tie(nullptr)->sync_with_stdio(false);
Solve();
}
void Solve() {
cin>>n>>Q,n<<=1;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>s[i];
memset(f,0x3f,sizeof f);
f[0][0]=0;
for(int i=1;i<=n;i++) for(int j=0;j<=n;j++)
f[i][j]=min((j>0?f[i-1][j-1]+(s[i]=='('?0:a[i]):INF)
,(j<n?f[i-1][j+1]+(s[i]==')'?0:a[i]):INF));
printf("%lld\n",f[n][0]);
while(Q--) {
int x,y; cin>>x>>y;
a[x]=y;
for(int i=1;i<=n;i++) for(int j=0;j<=n;j++)
f[i][j]=min((j>0?f[i-1][j-1]+(s[i]=='('?0:a[i]):INF)
,(j<n?f[i-1][j+1]+(s[i]==')'?0:a[i]):INF));
printf("%lld\n",f[n][0]);
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
100 100 655884441 790777510 663667368 332762945 67681448 458058488 445481314 200508190 812326927 374891900 320371513 765529851 490260632 588113266 286392696 888016940 214376080 894477437 944447014 386015667 956960774 692332579 606560669 561835357 887377361 130572961 550186106 193341110 4130416 66982...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #5:
score: 0
Runtime Error
input:
1000 1000 851064227 277152131 421722407 126468670 510326499 619107836 287335428 653386549 173788833 304176934 21753544 293653999 493165671 887566717 813114839 976556173 459946448 939807420 605205411 920860669 545229689 895277168 777349694 126341157 564711820 892644312 314220085 125767094 816813109 9...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Runtime Error
Test #14:
score: 0
Runtime Error
input:
1000 1000 49658 21707 94558 56676 18487 74906 55206 78654 54538 14591 105694 138 3148 106151 90191 67461 90337 86524 39272 78899 111590 3181 67245 47146 1958 34378 6544 74125 93643 44483 2159 16309 41619 24332 1519 85340 25811 55827 51528 89913 71355 103446 97370 44299 107887 105014 44419 62592 1965...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%