Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace spike
- {
- class MainClass
- {
- public static void Main (string[] args)
- {
- StreamReader inf = new StreamReader ("spike.in");
- StreamWriter ouf = new StreamWriter ("spike.out");
- ///////////////////////////////////////////////
- String[] nmk = inf.ReadLine ().Split (' ');
- int n = Convert.ToInt32(nmk[0]);
- int m = Convert.ToInt32(nmk[1]);
- int k = Convert.ToInt32(nmk[2]);
- ///////////////////////////////////////////////
- int[,] city = new int[n,m];
- bool[,] pegas = new bool[n, m];
- int[,] weight = new int[n,m];
- for(int i = 0;i<n;i++)
- for(int j = 0;j<m;j++)
- weight[i,j] = 10000000;
- for (int i = 0; i < n; i++) {
- string[] city_str = inf.ReadLine().Split (' ');
- for (int j = 0; j < m; j++)
- city [i, j] = Convert.ToInt32(city_str [j]);
- }
- for (int i = 0; i < k; i++) {
- string[] pegas_xy = inf.ReadLine().Split (' ');
- pegas [Convert.ToInt32(pegas_xy [0]) - 1, Convert.ToInt32(pegas_xy [1])-1] = true;
- }
- ////////////////////////////////////////////////
- weight[0,0] = 0;
- for (int y = 0; y < n; y++) {
- for (int x = 0; x < m; x++) {
- if (0 <= x + 1 && x + 1 < m && weight [y, x + 1] > weight [y, x] + city [y, x])
- weight [y, x + 1] = weight [y, x] + city [y, x];
- if (0 <= y + 1 && y + 1 < n && weight [y + 1, x] > weight [y, x] + city [y, x])
- weight [y + 1, x] = weight [y, x] + city [y, x];
- if (pegas [y, x]) {
- if (0 <= x + 1 && x + 1 < m && 0 <= y + 2 && y + 2 < n && weight [y + 2, x + 1] > weight [y, x] + city [y, x])
- weight [y + 2, x + 1] = weight [y, x] + city [y, x];
- if (0 <= x + 2 && x + 2 < m && 0 <= y + 1 && y + 1 < n && weight [y + 1, x + 2] > weight [y, x] + city [y, x])
- weight [y + 1, x + 2] = weight [y, x] + city [y, x];
- }
- }
- }
- ouf.WriteLine(weight[n - 1,m - 1]+city[n - 1,m - 1]);
- ouf.Close ();
- inf.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement