QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#277709 | #4376. Dragon slayer | chunzhifeng | WA | 1ms | 3656kb | C++14 | 1.6kb | 2023-12-06 21:43:49 | 2023-12-06 21:43:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define endl "\n"
#define PII pair<int,int>
const ll INF=0x3f3f3f3f;//3f3f3f3f;
const int mod=1e9+7;
const int N=2e6+5;
vector<int>g[420];
int d[420];
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
void solve(){
int n,m,k; cin>>n>>m>>k;
int tot=n*m-1;
for(int i=0;i<=tot;i++) g[i].clear(),d[i]=INF;
int sx,sy,ex,ey; cin>>sx>>sy>>ex>>ey;
sx=sx*m+sy; ex=ex*m+ey;
while(k--){
int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
if(x1==x2){
if(x1==0||x1==n) continue;
int l=min(y1,y2),r=max(y1,y2);
for(int j=l;j<r;j++){
int t1=(x1-1)*m+j,t2=x1*m+j;
if(t1>=0&&t1<=tot&&t2>=0&&t2<=tot){
g[t1].push_back(t2);
g[t2].push_back(t1);
//cout<<t1<<' '<<t2<<endl;
}
}
}else{
if(y1==0||y1==m) continue;
int l=min(x1,x2),r=max(x1,x2);
for(int j=l;j<r;j++){
int t1=j*m+y1-1,t2=j*m+y1;
if(t1>=0&&t1<=tot&&t2>=0&&t2<=tot){
g[t1].push_back(t2);
g[t2].push_back(t1);
//cout<<t1<<' '<<t2<<endl;
}
}
}
}
deque<int>Q;
Q.push_front(sx);
d[sx]=0;
while(Q.size()){
auto u=Q.front(); Q.pop_front();
int x=u/m,y=u%m;
map<int,int>mp;
for(int &it:g[u]) mp[it]=1;
for(int i=0;i<4;i++){
int tx=x+dx[i],ty=y+dy[i];
int v=tx*m+ty,flag=mp[v];
if(tx>=0&&tx<n&&ty>=0&&ty<m&&d[v]>d[u]+flag){
d[v]=d[u]+flag;
if(!flag) Q.push_front(v);
else Q.push_back(v);
}
}
} cout<<d[ex]<<endl;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T=1; cin>>T;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3656kb
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:
2 2 0 5 3 6 1 4 1 0
result:
wrong answer 1st lines differ - expected: '1', found: '2'