QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#245275#7678. The GameLilyWhite#WA 0ms5636kbC++203.4kb2023-11-09 20:17:532023-11-09 20:17:54

Judging History

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

  • [2023-11-09 20:17:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5636kb
  • [2023-11-09 20:17:53]
  • 提交

answer

// Problem: B. The Game
// Contest: undefined - The 2nd Universal Cup. Stage 8: Guilin
// URL: https://qoj.ac/contest/1404/problem/7678
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
#define repn(i, n) for (int i = 1; i <= (int)n; i++)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repr(i, m, n) for (int i = (int)m; i <= (int)n; i++)
#define repd(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#ifdef LILYWHITE
#define eprintf(...)                  \
    {                                 \
        fprintf(stderr, __VA_ARGS__); \
        fflush(stderr);               \
    }
#else
#define eprintf(...) ;
#endif
const int __attribute__((unused)) INF = 0x3f3f3f3f;
template <typename T>
inline T rd(T &x) {
    x = 0;
    T neg = 1;
    char c = 0;
    while (c < '0' || c > '9') {
        if (c == '-') neg = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - 48;
        c = getchar();
    }
    x *= neg;
    return x;
}
template <typename T, typename... Args>
inline void rd(T &x, Args &...args) {
    rd(x);
    rd(args...);
}
#define MULTI
const int N = 300050;
int a[N], b[N], ans[N];
int n, m;
void Main() {
    rd(n, m);
    repn(i, n) rd(a[i]);
    sort(a + 1, a + n + 1);
    repn(i, m) rd(b[i]);
    sort(b + 1, b + m + 1);
    int u, sum = 0, Max;
    for (int i = n; i > n - m; i--) {
        u = i - n + m;
        if (a[i] > b[u]) {
            printf("-1\n");
            return;
        }
        sum += b[u] - a[i];
    }
    Max = n - m;
    int cnt = Max - sum, v, cntans = 0, first;
    for (int i = 1; i <= n; i++) {
        if (a[i] == 1)
            v = i;
        else
            break;
    }
    first = 1;
    while (cnt) {
        ans[++cntans] = a[v];
        //        printf("%d %d\n", v, a[v]);
        a[v]++;
        if (a[v] > b[v - n + m] && v > n - m) {
            printf("-1\n");
            return;
        }
        first++;
        if (v > n - m) {
            Max--;
            sum--;
            if (sum < 0) {
                printf("-1\n");
                return;
            }
        } else
            cnt--;
        v--;
        if (v < first) {
            for (int i = first; i <= n; i++) {
                if (a[i] == a[first])
                    v = i;
                else
                    break;
            }
        }
    }
    for (int i = n; i > n - m; i--) {
        for (int j = a[i]; j < b[i - n + m]; j++) ans[++cntans] = j;
    }
    printf("%d\n", cntans);
    for (int i = 1; i <= cntans; i++) printf("%d ", ans[i]);
    cout << endl;
}
int main() {
#ifdef MULTI
    int T;
    rd(T);
    while (T--)
#endif
        Main();
    return 0;
}

详细

Test #1:

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

input:

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

output:

2
1 3 
-1
3
0 4 4 
5
1 1 1 2 3 
2
1 1 
-1

result:

wrong answer Wrong answer, erase a number that does not exist (test case 3)