寝癖頭の解法

学習中の覚え書きを投稿、更新していきます。

AtCoder Problems in C++ #D - 散歩

第8回日本情報オリンピック 本選(過去問)から、その提出コードの解答例です。
AtCoderとは、コンテストを通じて、プログラミングやアルゴリズムを学習するサービスです。
atcoder.jp
プログラミングコンテストとは、「与えられた問題をいかに素早く、正確に」解くことができるかを競うものです。
競技プログラミング」を略して、「競プロ」などと呼ばれています。

#D - 散歩

https://www.ioi-jp.org/joi/2008/2009-ho-prob_and_sol/2009-ho.pdf#page=10

僕が作成、提出したコードは、以下のとおりです。

/*
AtCoder Problems in C++
#D - 散歩
https://www.ioi-jp.org/joi/2008/2009-ho-prob_and_sol/2009-ho.pdf#page=10
提出コードの解答例
https://neguse-atama.hatenablog.com
*/
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int h,w,n;
  cin>>h>>w>>n;
  vector<vector<int>> d(h,vector<int>(w)),t(h+1,vector<int>(w+1,0));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>d[i][j];
    }
  }
  t[0][0]+=(n-1);
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      t[i+1][j]+=(t[i][j]+1-d[i][j])/2;
      t[i][j+1]+=(t[i][j]+d[i][j])/2;
      d[i][j]=(t[i][j]+d[i][j])%2;
    }
  }
  int x=0,y=0;
  while(x<h && y<w){
    if(d[x][y]){
      y++;
    }else{
      x++;
    }
  }
  cout<<x+1<<" "<<y+1<<endl;
  return 0;
}