#include <iostream>
#include <queue>
using namespace std;
const int stala=2010;
bool o[stala][stala];
int tab[stala][stala];
queue<int>kolejka;
queue<int>kolejka2;
queue<int>kolejka3;
void bfs()
{
kolejka.push(1);
kolejka2.push(1);
kolejka3.push(0);
while(!kolejka.empty())
{
int x=kolejka.front();
int y=kolejka2.front();
int war=kolejka3.front();
kolejka.pop();
kolejka2.pop();
kolejka3.pop();
tab[x][y]=war;
if(o[x+1][y]==0)
{
o[x+1][y]=1;
kolejka.push(x+1);
kolejka2.push(y);
kolejka3.push(war+1);
}
if(o[x-1][y]==0)
{
o[x-1][y]=1;
kolejka.push(x-1);
kolejka2.push(y);
kolejka3.push(war+1);
}
if(o[x][y+1]==0)
{
o[x][y+1]=1;
kolejka.push(x);
kolejka2.push(y+1);
kolejka3.push(war+1);
}
if(o[x][y-1]==0)
{
o[x][y-1]=1;
kolejka.push(x);
kolejka2.push(y-1);
kolejka3.push(war+1);
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int x,y,k;
cin>>x>>y>>k;
for(int i=0;i<=x+1;i++)
{
for(int j=0;j<=y+1;j++)
{
if(i==0||i==x+1||j==0||j==y+1)
{
o[i][j]=1;
}
else
{
char a;
cin>>a;
if(a=='X')
{
o[i][j]=1;
}
}
}
}
bfs();
int pom=tab[x][y];
pom=pom-(x+y-2);
int w1=x+y-2;
int w2=0;
w1+=pom/2;
w2+=pom/2;
long long minimum=1e17;
int l=0;
for(int i=1;i<=k;i++)
{
long long t1,t2;
cin>>t1>>t2;
long long czas=(long long)w1*t1;
czas+=(long long)w2*t2;
if(minimum==czas)
{
l++;
}
else if(czas<minimum)
{
minimum=czas;
l=1;
}
}
cout<<minimum<<" "<<l;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | #include <iostream> #include <queue> using namespace std; const int stala=2010; bool o[stala][stala]; int tab[stala][stala]; queue<int>kolejka; queue<int>kolejka2; queue<int>kolejka3; void bfs() { kolejka.push(1); kolejka2.push(1); kolejka3.push(0); while(!kolejka.empty()) { int x=kolejka.front(); int y=kolejka2.front(); int war=kolejka3.front(); kolejka.pop(); kolejka2.pop(); kolejka3.pop(); tab[x][y]=war; if(o[x+1][y]==0) { o[x+1][y]=1; kolejka.push(x+1); kolejka2.push(y); kolejka3.push(war+1); } if(o[x-1][y]==0) { o[x-1][y]=1; kolejka.push(x-1); kolejka2.push(y); kolejka3.push(war+1); } if(o[x][y+1]==0) { o[x][y+1]=1; kolejka.push(x); kolejka2.push(y+1); kolejka3.push(war+1); } if(o[x][y-1]==0) { o[x][y-1]=1; kolejka.push(x); kolejka2.push(y-1); kolejka3.push(war+1); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int x,y,k; cin>>x>>y>>k; for(int i=0;i<=x+1;i++) { for(int j=0;j<=y+1;j++) { if(i==0||i==x+1||j==0||j==y+1) { o[i][j]=1; } else { char a; cin>>a; if(a=='X') { o[i][j]=1; } } } } bfs(); int pom=tab[x][y]; pom=pom-(x+y-2); int w1=x+y-2; int w2=0; w1+=pom/2; w2+=pom/2; long long minimum=1e17; int l=0; for(int i=1;i<=k;i++) { long long t1,t2; cin>>t1>>t2; long long czas=(long long)w1*t1; czas+=(long long)w2*t2; if(minimum==czas) { l++; } else if(czas<minimum) { minimum=czas; l=1; } } cout<<minimum<<" "<<l; return 0; } |
English