QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#295666#7943. LIS on GridSolitaryDream#RE 0ms3584kbC++172.0kb2023-12-31 18:27:222023-12-31 18:27:22

Judging History

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

  • [2023-12-31 18:27:22]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3584kb
  • [2023-12-31 18:27:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
vector<string> gans;
inline bool Check(int n, int m, vector<int> num, int lim) {
    vector<int> sp;
    vector<string> ans(n, string(m, '.'));
    for (int i = 0; i < m; ++i) {
        if (num[i] <= sp.size()) {
            for (int j = 0; j < num[i]; ++j) ans[sp[j]][i] = '#';
        } else {
            for (auto x : sp) ans[x][i] = '#';
            int rm = num[i] - sp.size();
            for (int j = 0; j < sp.size(); ++j) {
                int &x = sp[j];
                while (rm && x > n - lim + j) {
                    if (x == 0 || ans[x - 1][i] == '#') break;
                    --x; --rm;
                    ans[x][i] = '#';
                }
            }
            if (rm && sp.size() < lim) {
                sp.push_back(n);
                int j = sp.size() - 1;
                int &x = sp[j];
                while (rm && x > n - lim + j) {
                    if (x == 0 || ans[x - 1][i] == '#') break;
                    --x; --rm;
                    ans[x][i] = '#';
                }
            }
            for (int j = 0; j < sp.size(); ++j) {
                int &x = sp[j];
                while (rm) {
                    if (x == 0 || ans[x - 1][i] == '#') break;
                    --x; --rm;
                    ans[x][i] = '#';
                }
            }
            if (rm) return 0;
        }
    }
    gans = ans;
    return 1;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int Case;
    cin >> Case;
    while (Case--) {
        int n, m;
        cin >> n >> m;
        vector<int> num(m);
        for (int i = 0; i < m; ++i) cin >> num[i];
        int ans = -1;
        gans.clear();
        for (int l = 0, r = n; l <= r; ) {
            int mid = (l + r) >> 1;
            if (Check(n, m, num, mid)) ans = mid, r = mid - 1; else l = mid + 1;
        }
        cout << ans << '\n';
        for (const auto &s : gans) cout << s << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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:


result: