QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#378165 | #7943. LIS on Grid | tylerm390 | WA | 79ms | 3760kb | C++17 | 2.0kb | 2024-04-06 08:47:12 | 2024-04-06 08:47:12 |
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), [&] (int u, int v) {
return make_tuple(-dp[u], -u) < make_tuple(-dp[v], -v);
});
sort(want.begin()+mid, want.end(), [&] (int u, int v) {
return make_tuple(dp[u], -u) < make_tuple(dp[v], -v);
});
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 << a << "\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: 100
Accepted
time: 1ms
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
Wrong Answer
time: 79ms
memory: 3508kb
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:
wrong answer Jury found better answer than participant (test case 21)