QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#658868#6769. Monster HunterCangShuVWA 0ms3724kbC++232.4kb2024-10-19 17:49:082024-10-19 17:49:08

Judging History

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

  • [2024-10-19 17:49:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3724kb
  • [2024-10-19 17:49:08]
  • 提交

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] % 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3724kb

input:

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

output:

2
6

result:

wrong answer 1st lines differ - expected: '4', found: '2'