QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#567890#7973. 括号ASnown15 144ms4812kbC++141.3kb2024-09-16 14:31:112024-09-16 14:31:12

Judging History

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

  • [2024-09-16 14:31:12]
  • 评测
  • 测评结果:15
  • 用时:144ms
  • 内存:4812kb
  • [2024-09-16 14:31:11]
  • 提交

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 = 2e3+23,M = 55;
int n,Q;
int a[N];
char s[N];
ll f[N][M];
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<=50;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<=50;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: 15
Accepted

Test #1:

score: 15
Accepted
time: 2ms
memory: 4808kb

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:

1883520337
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
1938040724
193...

result:

ok 101 lines

Test #2:

score: 15
Accepted
time: 2ms
memory: 4684kb

input:

100 100
833141622 854468469 367770104 350280219 461621010 985561079 287746098 833893180 365597420 618761946 416883128 838478689 419500348 996463737 903782689 176582886 101963967 728502271 222282338 808921916 744579730 171837013 508527221 141613052 233501822 501818380 143462266 206528940 451714614 68...

output:

140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
140782913
...

result:

ok 101 lines

Test #3:

score: 15
Accepted
time: 0ms
memory: 4768kb

input:

100 100
897203289 398741091 737994838 918141180 881683740 708870393 569981059 825462339 575892019 654430241 400748227 892258264 55868417 318639212 157441109 208939722 240809609 552556736 89466637 625250145 859111121 925840769 588412874 550260548 581965340 250456136 598142176 155996841 785774919 7347...

output:

16311332636
16311332636
16483179675
16483179675
16483179675
16891186615
16891186615
16891186615
17128610519
17533284483
17533284483
17533284483
17350707595
17252386332
16872696130
16872696130
16872696130
16854944528
16854944528
16854944528
16455983084
16455983084
16455983084
16450177820
16520502221
...

result:

ok 101 lines

Test #4:

score: 15
Accepted
time: 2ms
memory: 4744kb

input:

100 100
779493178 536060978 737064866 935658454 907027082 236372983 485874770 753814620 129162512 898300287 907325259 965207103 690140842 432022392 406234882 497505669 791961008 755177790 662269254 416752612 983166566 478974131 490379426 835070952 928089802 548072627 191418336 832748183 896922627 38...

output:

10068455511
10068455511
9859559743
9859559743
9832855564
9869366615
9869366615
9869366615
9869366615
9869366615
9869366615
10090141889
10090141889
10090141889
10090141889
10090141889
9921505636
9921505636
9921505636
9921505636
10012459628
10312147623
10678895964
10678895964
10678895964
10621969654
1...

result:

ok 101 lines

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 144ms
memory: 4760kb

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:

2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
2917334069
291...

result:

wrong answer 1st lines differ - expected: '2793453944', found: '2917334069'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 144ms
memory: 4812kb

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:

14300915
14273891
14273891
14273891
14273891
14273891
14273891
14273891
14273891
14312547
14267275
14267275
14267275
14263645
14263645
14263645
14263645
14263645
14238925
14213067
14213067
14213067
14213793
14195864
14226031
14200421
14240157
14243569
14295837
14295837
14295837
14295837
14310653
143...

result:

wrong answer 1st lines differ - expected: '13395019', found: '14300915'

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%