QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#346853 | #7943. LIS on Grid | Delay_for_five_minutes | WA | 9ms | 5780kb | C++20 | 2.4kb | 2024-03-09 03:13:06 | 2024-03-09 03:13:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n , m;
int a[200005];
vector<char> v[200005];
int f[200005];
bool check(int mx) {
for(int i = 1;i <= n;i++) f[i] = 0;
for(int i = 1;i <= m;i++) {
int cnt = a[i];
vector<int> dif;
for(int j = 1;j <= n;j++) v[j][i] = '.';
dif.push_back(-1) ;
for(int j = 1;j <= n && cnt;j++) {
if(f[j] == f[j - 1] + 1) {
cnt-- ; v[j][i] = '#' ;
dif.push_back(j - 1) ;
}
}
if(cnt == 0) continue ;
if(f[n] == mx) {
int lst = 1;
dif.push_back(n) ;
for(int k = 0;k < dif.size() && cnt > 0;k++) {
/// [lst , dif[i]]
for(int j = dif[k] ; j >= lst && cnt > 0;j--) {
v[j][i] = '#' ; cnt--;
f[j]++;
}
lst = dif[k] + 2;
}
}
else {
for(int j = n;j >= 1;j--){
if(f[j] == f[j - 1]) {
v[j][i] = '#' ; cnt--; f[j]++;
dif.push_back(j - 1) ;
break ;
}
}
sort(dif.begin() , dif.end()) ;
int lst = 1;
for(int k = 0;k < dif.size() && cnt > 0;k++) {
/// [lst , dif[i]]
for(int j = dif[k] ; j >= lst && cnt > 0;j--) {
v[j][i] = '#' ; cnt--;
f[j]++;
}
lst = dif[k] + 2;
}
}
// for(int j = 1;j <= n;j++) printf("%d ",f[j]) ; printf("\n") ;
}
return (f[n] <= mx) ;
}
void solv() {
cin >> n >> m;
for(int i = 1;i <= n;i++) f[i] = 0;
for(int i = 1;i <= m;i++) {
cin >> a[i] ; v[i].resize(n + 1) ;
}
int l = 1 , r = n;
// check(3) ;
// for(int i = 1;i <= n;i++ , cout << '\n') for(int j = 1;j <= m;j++) cout << v[i][j];
// return ;
while(l < r) {
int md = (l + r >> 1);
if(check(md)) r = md;
else l = md + 1;
}
check(l) ;
cout << l << '\n' ;
for(int i = 1;i <= n;i++ , cout << '\n') for(int j = 1;j <= m;j++) cout << v[i][j];
return ;
}
int main() {
ios::sync_with_stdio(false) ;
cin.tie(0) ;
int t;cin >> t;
while(t--) solv() ;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3472kb
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: 9ms
memory: 5780kb
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 196)