QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#72928 | #4376. Dragon slayer | poi | AC ✓ | 282ms | 3492kb | C++ | 2.0kb | 2023-01-20 13:54:14 | 2023-01-20 13:54:15 |
Judging History
answer
#include "iostream"
#include "cstring"
#include "cstdio"
#include "algorithm"
#include "queue"
#include "vector"
#include "queue"
#include "stack"
#include "ctime"
#include "set"
#include "map"
using namespace std;
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define mp make_pair
#define rep( i , a , b ) for( int i = (a) , i##end = b ; i <= i##end ; ++ i )
#define per( i , a , b ) for( int i = (a) , i##end = b ; i >= i##end ; -- i )
#define mem( a ) memset( a , 0 , sizeof (a) )
#define all( x ) x.begin() , x.end()
//#define int long long
typedef long long ll;
const int MAXN = 26 + 10;
const int P = 998244353;
int n , m , k;
const int dirx[] = { 1,0,-1,0 };
const int diry[] = { 0,1,0,-1 };
int xs , ys , xt , yt;
struct wall {
int x0 , y0 , x1 , y1;
void in( ) {
scanf("%d%d%d%d",&x0,&y0,&x1,&y1);
}
} A[MAXN] ;
int F[MAXN][MAXN][4];
int vis[MAXN][MAXN] , flg;
void dfs( int x , int y ) {
if( vis[x][y] ) return;
if( x == xt && y == yt ) {
flg = 1; return;
}
vis[x][y] = 1;
rep( d , 0 , 3 ) if( !F[x][y][d] ) {
int xx = x + dirx[d] , yy = y + diry[d];
if( xx < 0 || yy < 0 || xx >= n || yy >= m ) continue;
dfs( xx , yy );
}
}
void solve() {
cin >> n >> m >> k;
cin >> xs >> ys >> xt >> yt;
rep( i , 1 , k ) A[i].in( );
int res = k;
for( int s = 0 ; s < ( 1 << k ) ; ++ s ) {
rep( i , 1 , k ) if( ~s & ( 1 << i - 1 ) ) {
if( A[i].x0 != A[i].x1 ) {
rep( x , A[i].x0 , A[i].x1 - 1 )
F[x][A[i].y0 - 1][1] = 1 , F[x][A[i].y0][3] = 1;
} else {
rep( y , A[i].y0 , A[i].y1 - 1 )
F[A[i].x0][y][2] = 1 , F[A[i].x0 - 1][y][0] = 1;
}
}
flg = 0;
mem( vis );
dfs( xs , ys );
if( flg ) res = min( res , __builtin_popcount( s ) );
mem( F );
}
cout << res << endl;
}
signed main() {
// freopen("in","r",stdin);
// freopen("out","w",stdout);
int T;cin >> T;while( T-- ) solve();
// solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 282ms
memory: 3492kb
input:
10 4 4 4 0 2 3 3 0 2 4 2 1 3 1 0 2 4 2 1 3 1 3 4 3 2 2 0 0 2 1 0 1 3 1 1 0 1 2 3 2 2 0 0 2 1 2 1 2 2 1 0 1 1 15 15 15 3 12 4 1 8 0 8 15 1 11 15 11 1 1 1 15 3 1 3 15 0 10 14 10 14 1 14 14 8 1 8 15 1 5 14 5 0 15 14 15 0 4 14 4 0 2 15 2 11 0 11 15 4 1 4 15 1 11 15 11 1 12 14 12 15 15 15 8 5 14 0 0 12 1...
output:
1 2 0 5 3 5 1 4 1 0
result:
ok 10 lines