QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#658915#6769. Monster HunterCangShuVWA 1ms5644kbC++232.5kb2024-10-19 17:55:322024-10-19 17:55:33

Judging History

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

  • [2024-10-19 17:55:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5644kb
  • [2024-10-19 17:55:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int ar[N], br[N];
int pre[4][N];
int a, b, c;
void solve() {
    int n, m;
    cin >> n;
    a = c = b = 0;

    for (int i = 1; i <= n; ++i)
        cin >> ar[i];

    cin >> m;
    for (int i = 1; i <= m; ++i)
        cin >> br[i];

    for (int i = 1; i <= n; ++i) {
        pre[1][i] = pre[1][i - 1];
        pre[2][i] = pre[2][i - 1];
        pre[3][i] = pre[3][i - 1];
        pre[ar[i]][i] = pre[ar[i]][i - 1] + 1;
    }
    for (int i = 1; i <= m; ++i) {
        if (br[i] % 3 == 1) {
            c += 1;
        }
        if (br[i] % 3==2) {
            b += 1;
        }
        a += br[i] / 3;
    }
    auto check = [&](int mid) -> bool {
        int x, y, z;
        x = mid / n * pre[3][n] + pre[3][mid % n];
        y = mid / n * pre[2][n] + pre[2][mid % n];
        z = mid / n * pre[1][n] + pre[1][mid % n];
        x -= a;
        y -= b;
        z -= c;
        
        if (z < 0) {
            if (y > -z) {
                y += z;
                z = 0;
            } else if (y > 0) {
                z += y;
                y = 0;
            }
            if (x > -z) {
                x -= z;
                z = 0;
            } else if (x > 0) {
                z += x;
                x = 0;
            }
        }

        if (y < 0) {
            if (z / 2 > -y) {
                z += y * 2;
                y = 0;
            } else if (z / 2 > 0) {
                y += z / 2;
                z = z % 2;
            }
            if (x > -y) {
                x += y;
                y = 0;
            } else if (x > 0) {
                y += x;
                x = 0;
            }
        }
        if (x < 0) {
            int s = (-x) * 3;
            if (y > 0) {
                s -= y * 2;
            }
            if (z > 0) {
                s -= z;
            }
            if (s <= 0) {
                x = 0;
            }
        }

        if (x >= 0 and y >= 0 and z >= 0) {
            return true;
        } else {
            return false;
        }
    };
    int l = 1, r = 1e9;
    while (l < r) {
        int mid = l + r >> 1;
        if (check(mid))
            r = mid;
        else
            l = mid + 1;
    };
    cout << r << '\n';
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    while (n--)
        solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

input:

2
2
3 2
3
2 4 2
5
1 2 3 2 1
2
3 3

output:

4
3

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5644kb

input:

100
21
1 3 3 3 2 3 3 2 2 1 3 2 1 3 2 1 1 1 3 3 3
3
3 3 1
19
1 3 1 1 3 3 1 3 2 3 2 2 3 3 1 1 2 2 2
10
2 2 3 1 5 2 2 5 5 3
8
1 3 3 1 3 2 3 1
3
1 2 1
27
1 1 1 2 1 3 1 2 2 3 3 3 1 1 1 1 2 1 2 2 2 2 3 2 1 3 2
4
5 1 2 2
23
2 1 3 2 3 2 2 3 1 2 1 3 1 2 3 1 3 1 2 2 2 1 1
10
4 3 5 4 5 4 1 4 3 4
8
1 2 1 3 2 3 ...

output:

3
15
3
7
19
12
3
8
7
20
5
10
6
10
3
10
16
1
5
6
10
14
13
8
8
5
13
15
5
10
16
14
10
1
11
4
3
16
5
4
7
8
7
5
13
10
10
8
14
3
9
8
19
16
8
25
11
21
2
3
14
12
4
12
17
22
11
3
14
15
2
9
12
7
3
9
4
9
11
2
2
5
5
3
2
2
4
6
7
10
3
14
2
1
5
4
8
13
14
16

result:

wrong answer 35th lines differ - expected: '10', found: '11'