Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
140038 梁乃元 解药还是毒药 C++ 通过 100 0 MS 268 KB 855 2024-03-28 13:33:08

Tests(10/10):


# include <bits/stdc++.h> using namespace std; int n , m , x , a [101] , b [101] , visit [1024] , step [1024] ; queue <int> q ; int main ( ) { cin >> n >> m ; for ( int i=1; i<=m; ++i) { for (int j=1; j<=n; ++j) { cin >> x ; if ( x == 0 ) { a [i] += ( 1 << ( j - 1 ) ) ; } else if (x==-1) { b [i] += ( 1 << ( j - 1 ) ) ; } } } q.push ( ( 1 << n ) - 1 ) ; visit [ ( 1 << n ) - 1] = 1 ; while ( ! q . empty ( ) ) { int x = q . front ( ) ; q . pop ( ) ; if ( ! x ) { cout << step [x] << endl ; return 0 ; } for ( int i = 1 ; i <= m ; i ++ ) { int y = x & a [i] | b [i] ; if ( ! visit [y] ) { q . push ( y ) ; visit [y] = 1 ; step [y] = step [x] + 1 ; } } } cout << "The patient will be dead." << endl ; return 0 ; }


测评信息: