QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#178330#2726. Fun Palacelgswdn25 ✓19ms82272kbC++141.9kb2023-09-13 21:14:252023-09-13 21:14:26

Judging History

This is the latest submission verdict.

  • [2023-09-13 21:14:26]
  • Judged
  • Verdict: 25
  • Time: 19ms
  • Memory: 82272kb
  • [2023-09-13 21:14:25]
  • Submitted

answer

#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128; 
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii; 
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=1005,M=20005,inf=0x3f3f3f3f;
int n,f[N][M],a[N],b[N],m;

signed main() {
  n=read()-1, b[0]=read(), m=b[0];
  rep(i,1,n) a[i]=read(), b[i]=read();
  rep(i,1,n) chmax(m,a[i]+b[i]);
  rep(i,0,b[0]-1) f[0][i]=i;
  rep(i,b[0],m) f[0][i]=-inf;
  rep(i,1,n) {
    int w=0;
    rep(j,0,a[i]-1) chmax(w,f[i-1][j]);
    rep(j,0,b[i]-1) chmax(f[i][j],w+j);
    rep(j,0,m) {
      if(a[i]+b[i]<=j) chmax(f[i][j],f[i-1][j]);
      else {
        if(j>=a[i]) chmax(f[i][j-a[i]],f[i-1][j]);
        else chmax(f[i][j+b[i]],f[i-1][j]+b[i]);
      }
    }
  }
  int ans=0;
  rep(j,0,m) chmax(ans,f[n][j]);
  printf("%d\n",ans);
  return 0;
}

詳細信息

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 0ms
memory: 3784kb

input:

2
1
1 1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

3
1
1 1
1 1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

4
2
1 1
1 1
1 1

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

5
2
1 1
1 1
1 1
1 1

output:

3

result:

ok single line: '3'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3728kb

input:

3
4
1 1
1 1

output:

3

result:

ok single line: '3'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

4
9
1 1
1 1
1 1

output:

8

result:

ok single line: '8'

Subtask #2:

score: 5
Accepted

Test #7:

score: 5
Accepted
time: 0ms
memory: 3828kb

input:

1
1

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 0ms
memory: 4064kb

input:

1
2

output:

1

result:

ok single line: '1'

Test #9:

score: 0
Accepted
time: 3ms
memory: 7776kb

input:

1000
1
2 1
2 1
1 1
2 2
2 1
1 1
1 1
1 2
1 2
2 1
2 2
2 2
2 2
2 1
2 2
1 2
2 2
2 1
1 2
2 1
2 2
1 2
1 2
2 1
1 1
2 2
2 1
1 2
1 1
1 2
2 2
1 1
1 2
1 1
2 1
1 1
2 2
1 1
2 1
2 2
2 2
1 2
2 2
1 2
2 1
2 1
1 1
1 2
2 1
1 1
1 2
1 1
2 1
2 1
2 2
2 1
2 2
2 1
2 1
1 2
2 2
2 1
1 1
1 1
1 1
1 1
1 1
2 2
1 1
2 2
1 1
1 1
1 2
1...

output:

717

result:

ok single line: '717'

Test #10:

score: 0
Accepted
time: 3ms
memory: 7752kb

input:

981
2
1 2
2 2
1 2
2 2
2 1
1 2
2 2
1 1
1 1
1 2
2 1
2 2
2 2
2 1
1 1
2 1
2 1
2 1
2 2
1 1
1 1
2 2
2 2
2 1
1 1
1 2
1 2
2 2
2 1
1 2
2 2
2 1
2 1
1 1
2 1
2 1
2 2
2 1
2 1
1 2
2 1
1 1
1 1
2 1
2 1
1 1
2 1
1 1
2 2
1 1
1 1
1 2
1 1
1 2
1 1
1 2
1 2
1 1
1 2
2 2
2 2
2 2
2 2
1 1
2 1
2 1
1 2
2 1
1 2
2 1
2 2
1 2
2 1
2 ...

output:

707

result:

ok single line: '707'

Subtask #3:

score: 12
Accepted

Test #11:

score: 12
Accepted
time: 0ms
memory: 3872kb

input:

2
20
5 5

output:

19

result:

ok single line: '19'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

2
20
5 20

output:

24

result:

ok single line: '24'

Test #13:

score: 0
Accepted
time: 0ms
memory: 4084kb

input:

7
7
2 8
6 6
1 1
2 4
2 8
7 8

output:

23

result:

ok single line: '23'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

1
122

output:

121

result:

ok single line: '121'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

1
11

output:

10

result:

ok single line: '10'

Test #16:

score: 0
Accepted
time: 1ms
memory: 5100kb

input:

200
150
132 123
186 124
156 123
166 60
71 79
55 159
40 194
35 18
197 13
130 176
25 106
193 6
19 65
128 190
5 86
4 100
173 185
30 124
103 100
1 114
113 105
120 72
125 178
94 196
74 175
68 95
180 171
70 135
96 175
142 21
177 78
120 48
134 191
156 41
121 119
32 149
57 60
19 78
129 115
123 122
15 34
128...

output:

14013

result:

ok single line: '14013'

Test #17:

score: 0
Accepted
time: 1ms
memory: 4884kb

input:

194
162
191 24
178 21
173 97
57 172
130 163
156 175
23 162
89 3
140 173
16 180
27 104
95 133
155 98
52 193
190 192
198 78
91 184
181 117
180 175
117 124
177 172
160 83
44 58
73 178
115 162
153 50
130 31
157 79
118 48
86 173
106 153
152 64
6 82
3 26
155 199
189 57
112 126
111 22
144 172
123 103
34 80...

output:

14097

result:

ok single line: '14097'

Subtask #4:

score: 5
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #18:

score: 5
Accepted
time: 0ms
memory: 8436kb

input:

1000
165
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1...

output:

500

result:

ok single line: '500'

Test #19:

score: 0
Accepted
time: 3ms
memory: 8300kb

input:

981
158
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
...

output:

491

result:

ok single line: '491'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3752kb

input:

1
8655

output:

8654

result:

ok single line: '8654'

Test #21:

score: 0
Accepted
time: 19ms
memory: 82272kb

input:

1000
3898
285 1505
4440 5701
3635 4207
825 1338
7519 7719
346 2400
7763 8911
9454 9169
119 357
8479 5754
6743 4185
9850 1214
4336 526
8144 2660
5223 3452
2999 8133
6978 1185
1255 1695
8940 2107
4094 2628
7797 959
7212 2059
9136 9014
2312 4958
2692 6923
6057 11
9372 110
4061 660
1047 8084
1445 4526
3...

output:

3503312

result:

ok single line: '3503312'

Test #22:

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

input:

1000
4618
1834 6250
6621 4954
2412 8894
2109 8198
4405 862
7385 9786
1492 1938
7371 9595
1870 1079
5424 9503
4520 8990
4233 7775
9952 4747
301 4268
8197 5382
3270 424
3114 3294
8559 3320
6311 9345
13 2921
5912 9444
1667 6056
220 8529
3852 168
8455 2740
5109 10000
896 302
1295 9547
7668 8131
9250 674...

output:

3505300

result:

ok single line: '3505300'

Test #23:

score: 0
Accepted
time: 16ms
memory: 80148kb

input:

974
160
6918 8267
8409 6670
4136 345
3898 1898
8113 2797
6384 1731
255 6498
3762 6476
8903 9362
8943 267
7919 7936
1560 2474
4437 3072
35 2090
6886 362
2122 1723
7800 5514
4090 1525
7937 4979
2933 1427
9421 5319
4032 5379
2796 5616
8453 5959
7873 299
1058 3766
1860 9656
8857 347
4177 4363
9902 3525
...

output:

3413376

result:

ok single line: '3413376'

Test #24:

score: 0
Accepted
time: 8ms
memory: 57764kb

input:

691
9004
7472 1937
7662 8150
8824 1629
8054 3376
8552 9837
9178 3972
578 4415
4188 4034
6921 6307
5395 3852
8533 5023
5417 2683
8658 637
155 1960
6112 6440
1709 5156
9908 3218
6116 5792
5174 8193
1737 9542
7906 9774
4925 6462
2311 7156
9071 1721
9498 9351
4152 1099
4756 6890
448 6968
6928 4872
6309 ...

output:

2426822

result:

ok single line: '2426822'

Extra Test:

score: 0
Extra Test Passed