QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#353599 | #7943. LIS on Grid | ucup-team1004# | WA | 0ms | 3908kb | C++14 | 1.6kb | 2024-03-14 11:55:54 | 2024-03-14 11:55:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(a) (a).begin(),(a).end()
#ifdef DEBUG
template<class T>
ostream& operator << (ostream &out,vector<T> a){
out<<'[';
for(T x:a)out<<x<<',';
return out<<']';
}
template<class T>
vector<T> ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<class T>
void debug(T x){
cerr<<x<<endl;
}
template<class T,class...S>
void debug(T x,S...y){
cerr<<x<<' ',debug(y...);
}
#else
#define debug(...) void()
#endif
const int N=2e5+10;
int T,n,m,a[N];
#define id(x,y) (((x)-1)*m+(y))
int ans[N],f[N];
bool chk(int mid){
fill(ans,ans+1+n*m,0);
fill(f+1,f+1+n,0);
int cur=0;
for(int i=1;i<=m;i++){
int ret=a[i];
for(int j=1;j<=n&&ret;j++){
if(f[j])ans[id(j,i)]=1,ret--;
}
if(!ret)continue;
if(!f[n]&&cur<mid){
ret--,cur++,f[n]=ans[id(n,i)]=1;
}
int k=n-1;
for(;k&&!f[k];k--);
for(int j=k,las=0;j>=1&&ret;j--){
if(f[j])las=j;
else{
f[j]=1,f[las]=0,ans[id(j,i)]=1;
ret--,las=j;
}
}
if(ret){
for(int j=n,las=0;j>k&&ret;j--){
if(f[j])las=j;
else{
if(!las)return 0;
f[j]=1,f[las]=0,ans[id(j,i)]=1;
ret--,las=j;
}
}
if(ret)return 0;
}
}
return 1;
}
void get(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)scanf("%d",&a[i]);
int l=0,r=min(n,m),mid;
for(;l+1<r;){
mid=(l+r)>>1;
if(chk(mid))r=mid;
else l=mid;
}
chk(r);
printf("%d\n",r);
// for(int i=1;i<=n;i++){
// for(int j=1;j<=m;j++)putchar(".#"[ans[id(i,j)]]);
// puts("");
// }
}
int main(){
for(scanf("%d",&T);T--;)get();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3908kb
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:
wrong answer Token parameter [name=s] equals to "3", doesn't correspond to pattern "[.#]{4,4}" (test case 1)