QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378164 | #7943. LIS on Grid | tylerm390 | WA | 1ms | 3844kb | C++17 | 1.9kb | 2024-04-06 08:44:49 | 2024-04-06 08:44:50 |
Judging History
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('.');
piles++;
}
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 = -1;
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
Wrong Answer
time: 1ms
memory: 3844kb
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 #### #... ###. ##.. 3 .#### ..### ####. ###..
result:
wrong answer Jury found better answer than participant (test case 4)