QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#133657#4931. Comic Binge4k2kok#TL 16ms161444kbC++201.9kb2023-08-02 12:30:042023-08-02 12:30:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 12:30:05]
  • 评测
  • 测评结果:TL
  • 用时:16ms
  • 内存:161444kb
  • [2023-08-02 12:30:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(a,b) memset((a),(b),sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
#define int long long

const int maxn = 1e5 + 10;

int n, dp[1010][2][10010], a[1010], b[1010], pre[1010];

bool dfs(int pos, bool read, int gap, int used) {
    if (pos == n && read == 0) return 0;
    if (pos == n + 1) return 1;
    // if (~dp[pos][read][gap]) return dp[pos][read][gap];
    bool ans = 0;
    if (read) {
        bool nowans = dfs(pos + 1, 0, max(gap, used + b[pos] - pre[pos - 1]), used + b[pos]);
        ans = ans || nowans;
        if (nowans) {
            dp[pos][read][max(gap, used + b[pos] - pre[pos - 1])] = 1;
        }
        
        nowans = dfs(pos + 1, 1, max(gap, used + b[pos] - pre[pos - 1]), used + b[pos]);
        ans = ans || nowans;
        if (nowans) {
            dp[pos][read][max(gap, used + b[pos] - pre[pos - 1])] = 1;
        }
    } else {
        bool nowans = dfs(pos + 1, 1, gap, used);
        ans = ans || nowans;
        if (nowans) {
            dp[pos][read][gap] = 1;
        }
    }
    return ans;
}

void solve() {
    memset(dp, -1, sizeof dp);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        pre[i] = pre[i - 1] + a[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    dfs(1, 1, 0, 0);
    int ans = 0;
    // for (int i = 0; i <= 100; i++) {
    //     cerr << dp[n][1][i] << ' ';
    // }
    // cerr << '\n';
    for (int i = 0; i <= 10000; i++) {
        if (dp[n][1][i] == 1) {
            ans = i;
            break;
        }
    }
    cout << pre[n] + ans << '\n';
}

signed main(){
    // io;
    int T = 1;
    //cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 161444kb

input:

6
3 1 1 1 1 2
1 5 3 3 7 4

output:

13

result:

ok single line: '13'

Test #2:

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

input:

2
2 1
1 1

output:

4

result:

ok single line: '4'

Test #3:

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

input:

1
1
1

output:

2

result:

ok single line: '2'

Test #4:

score: -100
Time Limit Exceeded

input:

161
146 662 336 441 626 77 362 697 911 248 879 40 435 60 518 62 475 908 185 740 435 899 188 673 716 529 524 305 321 998 4 363 598 471 650 379 6 980 971 175 664 328 294 681 201 64 926 608 310 478 404 284 634 239 891 515 433 368 929 457 593 338 432 971 593 134 355 97 658 344 653 592 822 660 403 398 38...

output:


result: