#include <bits/stdc++.h> int dx[]={-1, 1, 0, 0}; int dy[]={0, 0, 1, -1}; int map[2001][2001]; bool odwiedzone[2001][2001]; int main(){ int n, m, k; std::cin>>n>>m>>k; for (int i=0; i<n; i++){ for (int j=0; j<m; j++){ char ch; std::cin>>ch; if (ch=='X'){ map[i][j]=-1; } else{ map[i][j]=-2; } } } map[0][0]=0; std::queue <std::pair <int, int> > bfs; bfs.push(std::make_pair(0, 0)); bool isFound=false; while (!isFound){ std::pair<int, int> pointa = bfs.front(); bfs.pop(); for (int i=0; i<4; i++){ int y = pointa.first; int x = pointa.second; if (x+dx[i]>=m||x+dx[i]<0||y+dy[i]>=n||y+dy[i]<0){ continue; } else{ if(map[y+dy[i]][x+dx[i]]!=-1){ if (map[y+dy[i]][x+dx[i]]==-2){ map[y+dy[i]][x+dx[i]]=map[y][x]+1; if(y+dy[i]==n-1&&x+dx[i]==m-1){ isFound=true; break; } bfs.push(std::make_pair(y+dy[i], x+dx[i])); } } } } } //std::cout<<"cokoliwek"; //std::cout<<map[n-1][m-1]<<"\n"; long long int a=(map[n-1][m-1]-(n-1)-(m-1))/2; long long int b=a+m-1+n-1; //std::cout<<a<<" koniec a tera b "<<b; std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> > wyniki; for (int z=0; z<k; z++){ long long int ka, kb; std::cin>>ka>>kb; wyniki.push(ka*a+kb*b); } long long ilosc=0; long long int max=wyniki.top(); for (int i=0; i=i; i++){ if (wyniki.top()==max){ ilosc++; wyniki.pop(); } } std::cout<<m; }
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 | #include <bits/stdc++.h> int dx[]={-1, 1, 0, 0}; int dy[]={0, 0, 1, -1}; int map[2001][2001]; bool odwiedzone[2001][2001]; int main(){ int n, m, k; std::cin>>n>>m>>k; for (int i=0; i<n; i++){ for (int j=0; j<m; j++){ char ch; std::cin>>ch; if (ch=='X'){ map[i][j]=-1; } else{ map[i][j]=-2; } } } map[0][0]=0; std::queue <std::pair <int, int> > bfs; bfs.push(std::make_pair(0, 0)); bool isFound=false; while (!isFound){ std::pair<int, int> pointa = bfs.front(); bfs.pop(); for (int i=0; i<4; i++){ int y = pointa.first; int x = pointa.second; if (x+dx[i]>=m||x+dx[i]<0||y+dy[i]>=n||y+dy[i]<0){ continue; } else{ if(map[y+dy[i]][x+dx[i]]!=-1){ if (map[y+dy[i]][x+dx[i]]==-2){ map[y+dy[i]][x+dx[i]]=map[y][x]+1; if(y+dy[i]==n-1&&x+dx[i]==m-1){ isFound=true; break; } bfs.push(std::make_pair(y+dy[i], x+dx[i])); } } } } } //std::cout<<"cokoliwek"; //std::cout<<map[n-1][m-1]<<"\n"; long long int a=(map[n-1][m-1]-(n-1)-(m-1))/2; long long int b=a+m-1+n-1; //std::cout<<a<<" koniec a tera b "<<b; std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> > wyniki; for (int z=0; z<k; z++){ long long int ka, kb; std::cin>>ka>>kb; wyniki.push(ka*a+kb*b); } long long ilosc=0; long long int max=wyniki.top(); for (int i=0; i=i; i++){ if (wyniki.top()==max){ ilosc++; wyniki.pop(); } } std::cout<<m; } |