QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764010#8981. Kangaroo PuzzlezxcdxwWA 1ms3848kbC++141.9kb2024-11-19 23:19:502024-11-19 23:19:51

Judging History

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

  • [2024-11-19 23:19:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3848kb
  • [2024-11-19 23:19:50]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define ull unsigned long long
#define ll long long
#define lowbit(x) (x)&(-x)
//#define int long long
//#define double long double 
const int N = 2e5 + 5;
const ll base = 131;
const ll mod = 998244353;
void solve() {
    int n, m, k, w;
    cin >> n >> m >> k >> w;
    vector<int>a(n + 1), b(m + 1);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= m; ++i) cin >> b[i];
    vector<pair<int, int>>x(n + m + 1);
    vector<int>as;
    for (int i = 1; i <= n; ++i) x[i] = { a[i],1 };
    for (int i = n+1; i <=n+m; ++i) x[i] = { b[i-n],0 };
    sort(x.begin() + 1, x.end());
    x[0] = { 0,0 };
    x.push_back({ w + 1,0 });
    int l = 0, r = 1, ans = 0, now = -1;
    while ( r <= n +m+ 1) {
        while (r <= n + 1+m && x[r].second != 0) {
            if (x[r].first > now) now = x[r].first + k - 1, ans++, as.push_back(x[r].first);
            r++;
        }
        if (now >= x[r].first) {
            int rr = r - 1, noww = x[r].first - k, xx = ans-1;
            as[xx] = noww;
            xx--;
            bool ok = false;
            while (rr > l) {
                rr--;
                if (rr == l) break;
                if (noww <= x[rr].first) continue;
                if (noww > x[rr].first + k - 1) {
                    ok = true;
                    break;
                }
                else noww = noww - k, as[xx] = noww, xx--;
            }
            if (noww > x[l].first) ok = true;
            if (!ok) {
                cout << -1 << '\n';
                return;
            }
        }
        l = r;
        r++;
        now = -1;
    }
    cout << ans << '\n';
    if (!ans) return;
    for (auto& it : as) cout << it << " ";
    cout << '\n';
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3848kb

input:

4 4
1111
1001
1001
1110

output:

-1
1
0 
1
0 
1
0 

result:

wrong answer Line [name=ans] equals to "-1", doesn't correspond to pattern "[UDLR]{1,50000}"