QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#747867#9574. StripsbexiaoheRE 0ms3548kbC++142.9kb2024-11-14 18:31:412024-11-14 18:31:41

Judging History

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

  • [2024-11-14 18:31:41]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3548kb
  • [2024-11-14 18:31:41]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'
#define int long long

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


const int N = 2e5 + 5;
int n, m, k, w, x;

void solve()
{
    int cnt = 0;
    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];
    }
    sort(a.begin() + 1, a.end());
    sort(b.begin() + 1, b.end());
    b.push_back(w + 1);
    
    //3
    //wrwwbwrwrwrwbrww
    vector<int> aa;
    for(int i = 1; i <= n; i ++)
    {
        int l = a[i];
        if(!aa.empty()){
            int lst = aa.back();
            if(l <= lst + k - 1) continue;
        }
//        if(lower_bound(b.begin(), b.end(), l) == b.end()){
//            cnt ++;
//            aa.push_back(l);
//            continue;
//        }
        int lctb = b[lower_bound(b.begin(), b.end(), l) - b.begin()];
        if(lctb > l + k - 1){
            cnt ++;
            aa.push_back(l);
            continue;
        }
        int nl = l - (k - (lctb - l));
        int yd = k - (lctb - l);
        if(nl < 0){
            cout << -1 << endl;
            return;
        }
        //if(i == 3) cout << "nl:" << nl << endl;
        int idx = aa.size() - 1;
        while(1)
        {
            //4
            //brwwwrwwwrb
//            auto it = lower_bound(b.begin(), b.end(), nl);
//            if(it != b.end())
//            {
//                lctb = b[lower_bound(b.begin(), b.end(), nl) - b.begin()];
//                if(lctb <= nl + k - 1){
//                    cout << -1 << endl;
//                    return;
//                }
//            }    
//            auto it = lower_bound(b.begin(), b.end(), nl);
//            if(it != b.end())
//            {
            lctb = b[lower_bound(b.begin(), b.end(), nl) - b.begin()];
            if(lctb <= nl + k - 1){
                cout << -1 << endl;
                return;
            }
//            }    
            else
            {
                int lst = aa[idx];
                if(nl <= lst + k - 1){
                    nl = a[idx] - yd;
                    idx --;
                    if(nl <= 0 || idx < 0){
                        cout << -1 << endl;
                        return;
                    } 
                }
                else{
                    cnt ++;
                    aa.push_back(nl);
                    break;
                }
            }
        }
    }
    if(aa.size() == 0){
        cout << -1 << endl;
        return;
    }
    cout << aa.size() << endl;
    for(auto i : aa){
        cout << i << ' ';
    }
    cout << endl;
}
//4
//brwwwrwwwrb
signed main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    int t = 1;
    cin>>t;
    while(t--)solve();
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
5 2 3 16
7 11 2 9 14
13 5
3 2 4 11
6 10 2
1 11
2 1 2 6
1 5
3
2 1 2 6
1 5
2

output:

4
2 7 10 14 
-1
2
1 5 
-1

result:

ok ok 4 cases (4 test cases)

Test #2:

score: -100
Runtime Error

input:

11000
3 8 2 53
32 3 33
35 19 38 20 1 30 10 6
7 10 1 42
3 14 4 36 28 40 22
17 20 12 41 27 7 1 19 13 9
6 6 13 78
55 76 53 32 54 58
62 45 21 4 7 61
8 7 3 68
9 26 54 31 22 3 38 65
34 16 58 47 52 29 53
5 8 4 33
33 5 30 6 15
27 12 9 28 19 2 13 10
6 1 2 48
8 12 48 1 41 31
40
7 6 7 61
20 19 30 52 49 17 40
3...

output:


result: