QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#378161#7939. High Towerstylerm390#RE 0ms0kbC++201.8kb2024-04-06 08:39:202024-04-06 08:39:20

Judging History

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

  • [2024-04-06 08:39:20]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-04-06 08:39:20]
  • 提交

answer

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

using vi = vector<int>;
using ll = long long;
using pii = pair<int, int>;
using vvi = vector<vi>;

#define rep(i, a, b) for(int i = a; i < (b); i++)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

void solve() {
    int n, m;
    cin >> n >> m;

    vi inp(m);
    for (int i = 0; i < m; i++) cin >> inp[i];


    auto calc = [&] (int piles_want) -> pair<int, vector<string>> {
        vi dp(n+1);
        vector<string> res(n);
        int piles = 0;
        for (int i = 0; i < m; i++) {
            int x = inp[i];

            vi moves, want;
            for (int i = 0; i < n; i++) {
                if (dp[i] != dp[i+1]) moves.push_back(i);
                else want.push_back(i);
            }
            int mid = max(0, min(sz(want), piles_want-piles));
            sort(all(want));
            reverse(all(want));
            reverse(want.begin()+mid, want.end());

            moves.insert(moves.end(), all(want));

            for (int j = 0; j < x; j++) res[moves[j]].push_back('#');
            for (int j = x; j < n; j++) res[moves[j]].push_back('.');
            for (int i = n; i > 0; i--) {
                dp[i] = max(dp[i], dp[i-1]+(res[i-1].back() == '#'));
            }
            for (int i = 0; i < n; i++) {
                dp[i+1] = max(dp[i+1], dp[i]);
            }
        }
        return {dp[n], res};
    };

    int res = 0;

    for (int pw = 1<<18; pw > 0; pw /= 2) {
        if (calc(res+pw).first > res+pw) res += pw;
    }
    res++;
    auto [a, b] = calc(res);
    cout << res << "\n";
    for (string s : b) cout << s << "\n";
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    int t;
    cin >> t;
    while (t--) solve();

    return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

6
3 3 4 2 5 1

output:


result: