QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378161 | #7939. High Towers | tylerm390# | RE | 0ms | 0kb | C++20 | 1.8kb | 2024-04-06 08:39:20 | 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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
6 3 3 4 2 5 1