Skip to main content
1 of 4
johnchen902
  • 1.2k
  • 6
  • 15

#C++ 212 bytes * 0.5 = 106

Here is my solution. It's similar to user2357112's solution, but there are several difference:

  • First, I dispatch visiting times to the right and bottom, instead of compute them from the top and left.
  • Second, I do everything (reading input, dispatching, tracking the man's location) simultaneously.
  • Third, I keep only one row of memory.
  • Most importantly, shorter!
#include <iostream>
int o[1001],h,w,r,c,i,j,t,u;int main(){std::cin>>h>>w>>*o;--*o;for(;i<h;i++)for(j=0;j<w;)std::cin>>t,u=o[j],o[j]/=2,u%2&&o[j+t]++,r-i|c-j||((u+t)%2?c:r)++,o[++j]+=u/2;std::cout<<r<<" "<<c<<"\n";}

Here is the ungolfed version:

#include <iostream>
using namespace std;
int o[1001];
int main(){
    int h, w, n;
    cin >> h >> w >> n;
    o[0] = n - 1;
    int r = 0, c = 0;
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++){
            bool t;
            cin >> t;
            int u = o[j];
            o[j + 1] += u / 2;
            o[j] = u / 2;
            if(u % 2)
                (t ? o[j + 1] : o[j])++;
            if(r == i && c == j)
                ((u + t) % 2 ? c : r)++;
        }
    cout << r << " " << c << endl;
}
johnchen902
  • 1.2k
  • 6
  • 15