32tps玄关求条
查看原帖
32tps玄关求条
1264316
Re_End_of_dream楼主2025/7/27 15:49

WA32tps

#include<bits/stdc++.h>
using namespace std;
int e[300005],o[300005];
bool f[300005];
void solve(){
	int n,m,k;
	cin>>n>>m>>k;
	memset(f,0,sizeof f); 
	stack<int> stk; 
	for(int i=1,s=0;i<=m;i++){
		e[i]=-300005;
		o[i]=-300005;
		for(int j=1,x;j<=k;j++){
			cin>>x;
			if(x&1){
				e[i]=max(e[i],x);
				o[i]=max(o[i],-x);
			}
			else{
				o[i]=max(o[i],x);
				e[i]=max(e[i],-x);
			}
		}
		if(s+e[i]<n){
			s+=e[i];
			if(e[i]>o[i]) stk.push(i);
		}
		else if(s+o[i]<n){
			s+=o[i];
			f[i]=1; 
		}
		else{
			int p=i;
			if(e[i]<=o[i]){
				while(s+e[i]>=n){
					if(stk.empty()){
						cout<<"-1\n";
						return;
					}
					p=stk.top(); stk.pop();
					s+=o[p]-e[p];
					f[p]=1;
				}
				s+=e[i];
			}
			else{
				while(s+o[i]>=n){
					if(stk.empty()){
						cout<<"-1\n";
						return;
					}
					p=stk.top(); stk.pop();
					s+=o[p]-e[p];
					f[p]=1;
				}
				if(s+e[i]<=m) s+=e[i]-o[i],stk.push(i);
				else s+=o[i],f[i]=1;
			}
		}
	}
	for(int i=1;i<=m;i++){
		if(f[i]) cout<<"Odd ";
		else cout<<"Even ";
	}
	cout<<"\n";
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int T;
	cin>>T;
	while(T--){
		solve();
	}
}
2025/7/27 15:49
加载中...