QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#856462#9574. StripsRafat_KabirWA 27ms3712kbC++205.3kb2025-01-14 01:21:502025-01-14 01:21:50

Judging History

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

  • [2025-01-14 01:21:50]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:3712kb
  • [2025-01-14 01:21:50]
  • 提交

answer


#include <bits/stdc++.h>
#include <time.h>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx2")
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>

using namespace __gnu_pbds;
using namespace std;
template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// to erase in multiset-> less_equal<T> and 
// s.erase(s.find_by_order(s.order_of_key(x)))
// lower_bound(x)=>(cannot use the stl lower_bound function)
// ll idx = s.order_of_key(x)
// if(idx == s.size()) -> no lower_bound
// else lb = *s.find_by_order(idx) // as 0-indexing
// idx-1 will give highest value which is strictly less than x
// for upper_bound->do the same with (x+1)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef tuple<ll, ll, ll> t64;
typedef vector<t64> vt64;
typedef vector<vt64> vvt64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef vector<vector<p32> > vvp32;
typedef vector<bool> vb;
ll mod =  1e9+7, MOD = 998244353;
double eps = 1e-12;
#define FOR(s, e, i) for(ll i = s; i <= e; i++)
#define ROF(s ,e, i) for(ll i = s; i >= e; i--)
#define F0R(i, e) for(ll i = 0; i < (e); i++)
#define trav(e, a) for(auto &e : a)
#define coutAll(A) for(auto asdafas : A) cout <<  asdafas << " "; cout << "\n";
#define foutAll(A) for(auto asdafas : A) fout <<  asdafas << " "; cout << "\n";
#define cinAll(A) for(auto &asdafas : A) cin >>  asdafas;
#define finAll(A) for(auto &asdafas : A) fin >>  asdafas;
#define minpq priority_queue<ll, v64, greater<ll>>
#define maxpq priority_queue<ll> 
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
ll inf = LLONG_MAX;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pii;
#define MAXN 100000000

void solve(int it)
{
    ll n, m, k, w;
    cin >> n >> m >> k >> w;
    vector<pair<ll, bool>>A;
    FOR(0, n - 1, i){
        ll x;
        cin >> x;
        A.emplace_back(x, true);
    }
    FOR(0, m - 1, i){
        ll x;
        cin >> x;
        A.emplace_back(x, false);
    }
    // setting left and right boundary with black
    A.emplace_back(0, false);
    A.emplace_back(w+1, false);
    sort(all(A));
    vp64 B;
    vv64 way;
    auto f = [&]()->ll{
        // trav(e, B){
        //     cout << e.fi << "(" << e.se << ") ";
        // }
        // cout << "\n";
        if(sz(B)<2) return 0;
        if(!(!B[0].se and !B.back().se)) return 0;
        if(sz(B) == 2) return 0;
        // trav(e, B){
        //     cout << e.fi << "(" << e.se << ") ";
        // }
        // cout << "\n";
        ll cnt = 0;
        ll last = -1;
        v64 temp;
        FOR(1, sz(B)-1, i){
            if(!B[i].se){
                break;
            }
            if(last == -1){
                last = B[i].fi;
                temp.pb(last);
                ++cnt;
                continue;
            }
            if(B[i].fi <= last+k-1){
                continue;
            }
            ++cnt;
            last = B[i].fi;            
            temp.pb(last);
        }
        // cout << cnt << "\n";
        if(k*cnt > B.back().fi-B[0].fi-1) return -1;
        ll pichao = B[sz(B)-2].fi+k - B.back().fi;
        // cout << pichao << "\n";
        // coutAll(temp);
        if(pichao > 0){
            temp.back() -= pichao;
            ROF(sz(temp)-3, 1, i){
                temp[i] = min(temp[i]-pichao, temp[i+1]-k);
            }
        }
        way.pb(temp);
        // trav(e, temp) way.pb(e);
        // way.insert(way.end(), all(temp));
        // coutAll(temp);
        // coutAll(way);
        // cout << cnt << " done\n";
        ll res = cnt;
        return res;
    };
    ll ans = 0;
    trav(e, A){
        // cout << e.fi << "=>\n";
        B.pb(e);
        if(e.se) continue;
        // cout << "start\n";
        ll res = f();
        // cout << "done\n";
        B.clear();
        B.pb(e);
        if(res == -1){
            cout << -1 << "\n";
            return;
        }
        // cout << "done\n";
        ans += res;
    }
    cout << ans << "\n";
    // coutAll(way);
    trav(v, way){
        trav(e, v) cout << e<< " ";
    }
    cout << '\n';

}


int main()
{
    fast_cin();    
    ll t = 1;
    cin >> t;
    for(int it=1; it<=t; it++)
    {
        //cout << "Case " << it << ": ";
        solve(it);
    }
    return 0;
}


详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3584kb

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
Wrong Answer
time: 27ms
memory: 3712kb

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:

2
3 32 
7
3 4 14 22 28 36 40 
3
32 43 66 
8
3 9 22 26 31 38 54 65 
3
4 15 27 
6
1 8 12 31 41 47 
4
14 30 39 49 
2
52 67 
1
22 
1
8 
1
62 
5
24 33 43 48 60 
2
4 31 
3
11 20 31 
3
3 16 33 
3
25 30 42 
3
3 17 60 
4
2 15 21 33 
2
54 66 
3
50 59 65 
3
50 60 70 
1
72 
4
2 11 16 23 
5
3 7 17 35 49 
2
1 42 ...

result:

wrong answer There are more than one stripe covering cell 43 (test case 3)