QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#295094#7943. LIS on Gridckiseki#RE 0ms3760kbC++202.2kb2023-12-30 18:46:332023-12-30 18:46:33

Judging History

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

  • [2023-12-30 18:46:33]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3760kb
  • [2023-12-30 18:46:33]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
  cerr << "\e[1;32m(" << s << ") = (";
  int f = 0;
  (..., (cerr << (f++ ? ", " : "") << a));
  cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
  cerr << "\e[1;33m[ " << s << " ] = [ ";
  using namespace experimental;
  copy(L, R, make_ostream_joiner(cerr, ", "));
  cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define orange(...) safe
#define debug(...) safe
#endif

using lld = int64_t;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }

  auto ans = vector(n, vector(m, 0));
  ans[0][0] = 1;

  const auto valid = [&](int value, bool construct = false) {
    vector<int> v(value, 1);


    for (int k = 0; k < m; k++) {

      int distinct = v.size();
      for (size_t i = 1; i < v.size(); i++)
        distinct -= v[i] == v[i - 1];

      int left = a[k] - distinct;

      vector<int> nv(value);
      for (int i = 0; i < value; i++) {
        int d = max(0, i ? v[i - 1] - v[i] - 1 : n + 1 - v[i] - 1);
        nv[i] = v[i] + min(left, d);
        left -= min(left, d);
      }
      if (left) {
        return false;
      }

      if (construct) {
        for (int i = 0; i < value; i++) {
          for (int j = v[i]; j <= nv[i]; j++) {
            ans[j - 1][k] = 1;
          }
        }
      }

      v = nv;
    }

    return true;
  };

  int l = 0, r = 1000;

  while (r - l > 1) {
    int m = (l + r) / 2;
    if (valid(m)) {
      r = m;
    } else {
      l = m;
    }
  }

  valid(r, true);

  cout << r << '\n';

  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      if (ans[i][j]) {
        a[j]--;
        if (a[j] < 0) ans[i][j] = 0;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << ".#"[ans[n - 1 - i][j]];
    }
    cout << '\n';
  }

}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--)
    solve();

  return 0;
}

詳細信息

Test #1:

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

input:

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

output:

1
....
####
3
###
###
###
2
###.
#...
####
##..
2
..###
.####
####.
###..

result:

ok Correct (4 test cases)

Test #2:

score: -100
Runtime Error

input:

5699
5 5
4 5 1 3 5
4 4
3 1 2 4
5 5
2 2 3 3 4
3 4
1 3 2 2
5 5
2 5 3 4 4
4 5
4 1 1 4 1
5 5
3 3 2 5 5
5 5
3 1 3 1 1
5 5
2 4 4 3 2
4 5
2 2 2 2 2
5 5
4 5 3 4 1
5 4
5 4 1 4
5 4
1 1 1 3
4 2
2 4
5 5
2 5 5 2 5
5 5
5 1 2 1 3
5 5
4 4 2 2 3
5 2
5 2
3 5
2 3 3 1 3
5 5
4 2 5 1 1
5 5
4 5 4 1 5
5 4
3 2 5 3
5 5
5 4 1...

output:

3
.#..#
##.##
##.##
##..#
#####
2
...#
#..#
#.##
####
2
....#
...##
..##.
###.#
#####
2
.###
.#..
####
3
.####
.#..#
.#.##
####.
#####
2
#..#.
#..#.
#..#.
#####
3
...##
.####
##.##
#..##
#####
1
..###
..#..
###..
#....
#....
2
..###
.##..
.#.##
####.
###..
2
.....
.....
#####
#####
3
.###.
##.#.
###...

result: