QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#731358#9574. Stripsucup-team008#WA 25ms3816kbC++174.5kb2024-11-10 02:26:512024-11-10 02:26:52

Judging History

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

  • [2024-11-10 02:26:52]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:3816kb
  • [2024-11-10 02:26:51]
  • 提交

answer

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include <omp.h>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
#define derr if(1) cerr

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << flush;
// END NO SAD

template<class Fun>
class y_combinator_result {
  Fun fun_;
public:
  template<class T>
  explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}

  template<class ...Args>
  decltype(auto) operator()(Args &&...args) {
    return fun_(std::ref(*this), std::forward<Args>(args)...);
  }
};

template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
  return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

template<class T>
bool updmin(T& a, T b) {
  if(b < a) {
    a = b;
    return true;
  }
  return false;
}
template<class T>
bool updmax(T& a, T b) {
  if(b > a) {
    a = b;
    return true;
  }
  return false;
}
typedef int64_t ll;

void rsolve() {
  int n, m, k, w;
  cin >> n >> m >> k >> w;
  vector<int> redv(n), blackv(m);
  for(auto& x: redv) cin >> x;
  for(auto& x: blackv) cin >> x;
  sort(all(redv));
  sort(all(blackv));
  assert(redv.back() <= w);
  blackv.pb(w+1); // no boundary cases here please
  vector<int> ret;
  // try the greediest left thing that makes sense, ignore overlaps
  for(int out: redv) {
    int lhs = out - k + 1;
    auto it = lb(all(ret), lhs);
    // is it already covered?
    if(it != ret.end() && (*it) <= out) continue;
    int endpoint = *lb(all(blackv), out);
    int cover = min(out, endpoint - k);
    if(cover == 0) {
      return void(cout << -1 << "\n");
    }
    ret.pb(cover);
  }
  // now shift things left
  for(int i = sz(ret)-2; i >= 0; i--) {
    if(ret[i+1] - ret[i] < k) {
      ret[i] = ret[i+1] - k;
      if(ret[i] < 1) {
        return void(cout << -1 << "\n");
      }
    }
  }
  // just check consistency
  for(int out: redv) {
    // each red must be covered
    int lhs = out - k + 1;
    auto it = lb(all(ret), lhs);
    if(it == ret.end() || (*it) > out) {
      return void(cout << -1 << "\n");
    }
  }
  for(int out: blackv) {
    // no black must be covered
    int lhs = out - k + 1;
    auto it = lb(all(ret), lhs);
    if(it != ret.end() && (*it) <= out) {
      return void(cout << -1 << "\n");
    }
  }
  cout << sz(ret) << "\n";
  for(int i = 0; i < sz(ret); i++) cout << ret[i] << " \n"[i == sz(ret)-1];
}
void solve() {
  int t;
  cin >> t;
  while(t--) rsolve();
}

// what would chika do
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases
// are you doing geometry in floating points
// are you not using modint when you should

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 25ms
memory: 3680kb

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 48 66
8
3 9 22 26 31 38 54 65
3
5 15 30
6
1 8 12 31 41 47
4
17 30 39 49
2
52 67
1
27
1
22
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
1 11 21 33
2
54 66
3
50 59 65
3
50 62 78
1
81
4
2 11 16 23
5
3 7 17 36 49
2
1 45
2
7 25
1
4
4
9 18 29 32...

result:

wrong answer Integer parameter [name=l_i] equals to -1, violates the range [1, 28] (test case 35)