Why D WA。。。

#include<bits/stdc++.h>
#define endl '\n'


using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

void solve(){
	ll n,m,q;cin>>n>>m>>q;
	string s="";
	for(int i=0;i<n;i++){
		string line; cin>>line;
		s += line;
	}
	vector<ll> a(q+1);
	a[0] = bitset<63>(s).to_ullong();
	for(int i=1;i<=q;i++){
		s = "";
		for(int j=0;j<n;j++){
			string line; cin>>line; s+=line;
		}
		a[i] = bitset<63>(s).to_ullong();
	}
	map<ll,ll> mp[2];
	mp[0][a[0]] = 0;
	map<ll,ll> path,idx;
    //path记录转移前的状态,x通过a[i]转移到x|a[i] path[x|a[i]] = x;
    //idx 记录用哪个计划转移  idx[x|a[i]] = i;
	path[a[0]] = 0;
	idx[a[0]] = 0;
	for(ll i=1;i<=q;i++){
		mp[i&1] = mp[(i-1)&1];
		for(auto &[x,y]:mp[(i-1)&1]){
			if(mp[i&1].find(x|a[i])==mp[i&1].end()){//之前的计划不能组合出x|a[i]状态
				mp[i&1][x|a[i]] = y+1;
				path[x|a[i]] = x;
				idx[x|a[i]] = i;
			}else if(mp[i&1][x|a[i]]> y + 1){
				mp[i&1][x|a[i]] = y+1;
				path[x|a[i]] = x;
				idx[x|a[i]] = i;
			}
		}
	}
	if(mp[q&1].find((1ll<<(n*m))-1)==mp[q&1].end()){
		return cout<<"-1",void();
	}
	cout<<mp[q&1][(1ll<<(n*m))-1]<<endl;
	ll res = idx[(1ll<<(n*m))-1];
	ll state = path[(1ll<<(n*m))-1];
	while(res!=0){
		cout<<res<<endl;
		res = idx[state];state = path[state];
		//if(res==0) break;
	}
}

int main(){		
    ifstream test_file("in.txt");
    if (test_file) {
        freopen("in.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
	std::ios::sync_with_stdio(0);std::cout.tie(0);std::cin.tie(0);
	int T = 1;
#ifdef MULTI_TEST
	cin>>T;
#endif
	while(T--){
		solve();
	}
	return 0;
}

WA 第4、5个点

全部评论
4 5到底是什么神秘数据,写了个dfs也wa在这了
点赞 回复 分享
发布于 2024-11-24 21:56 陕西

相关推荐

Gaynes:查看图片
点赞 评论 收藏
分享
07-14 12:29
门头沟学院 Java
后端岗,实习三周感觉有点想跑路了,担心秋招被拉黑,有没有佬是字节HR知道情况的
从零开始的转码生活:你实习三周都想跑路,将来拿到offer真的愿意在这干十几二十年吗
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务