QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#371807#8057. Best Carry Player 4ucup-team3215#WA 45ms3580kbC++20859b2024-03-30 16:40:182024-03-30 16:40:18

Judging History

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

  • [2024-03-30 16:40:18]
  • 评测
  • 测评结果:WA
  • 用时:45ms
  • 内存:3580kb
  • [2024-03-30 16:40:18]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  for (int tc = (cin >> tc, tc); tc--; ) {
    int m; cin >> m;
    vector<int64_t> a(m), b(m);
    int maxa = -1, maxb = -1;
    for (int i = 0; i < m; ++i) cin >> a[i], maxa = a[i]? i: maxa;
    for (int i = 0; i < m; ++i) cin >> b[i], maxb = b[i]? i: maxb;
    a[0] = b[0] = 1e18;
    int64_t ans = 0;
    bool carry = 0;
    for (int i = m - 1, j = 0; j < m && i > -1; i -= !a[i], j += !b[j] || i + j < m - 1) {
      int64_t c = min(a[i], b[j]);
      carry |= c && i + j >= m;
      ans += c, a[i] -= c, b[j] -= c;
    }
    for (int i = m; i--; ) carry |= a[i] && i + maxb >= m;
    for (int i = m; i--; ) carry |= b[i] && i + maxa >= m;
    if (!carry) --ans, carry |= maxa + maxb >= m;
    cout << (carry? ans: 0) << '\n';
  }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3560kb

input:

5
2
1 2
3 4
3
1 0 1
0 1 0
4
1 0 0 1
1 1 1 1
5
123456 114514 1919810 233333 234567
20050815 998244353 0 0 0
10
5 3 5 3 2 4 2 4 1 5
9 9 8 2 4 4 3 5 3 0

output:

5
1
2
467900
29

result:

ok 5 number(s): "5 1 2 467900 29"

Test #2:

score: -100
Wrong Answer
time: 45ms
memory: 3580kb

input:

100000
5
0 1 1 1 1
0 0 1 0 0
5
0 0 0 0 0
1 1 1 0 0
5
0 0 2 1 1
0 2 1 0 1
5
0 0 0 0 0
1 2 1 0 0
5
0 1 0 1 1
0 0 1 1 1
5
2 0 0 0 1
1 0 0 0 3
5
2 0 0 1 1
0 2 1 1 1
5
0 0 0 0 2
0 0 0 0 1
5
0 0 0 0 0
0 1 1 0 0
5
4 0 0 0 0
0 0 0 1 0
5
0 0 0 0 1
2 1 1 0 0
5
0 2 3 0 0
0 0 0 1 0
5
1 1 1 0 1
1 0 1 0 1
5
0 0 0...

output:

2
0
4
0
4
3
3
2
0
0
1
1
3
0
3
0
0
0
0
0
0
0
4
0
4
1
0
2
4
3
1
5
0
0
2
0
0
1
1
0
0
3
5
3
2
2
2
0
1
2
2
2
0
4
0
2
1
1
0
1
0
4
0
0
2
2
0
3
3
0
2
0
1
0
0
1
1
2
0
3
4
0
2
5
0
2
1
0
0
0
3
2
3
0
2
0
4
3
3
0
2
2
0
1
3
1
1
0
0
0
1
0
3
2
2
0
2
1
1
0
1
0
0
2
4
1
3
3
2
2
2
0
2
0
0
2
3
1
3
1
0
2
2
3
0
1
2
0
1
1
...

result:

wrong answer 5th numbers differ - expected: '3', found: '4'