alexjercan/bugnet huggingface dataset:
Problem p00464 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define pb push_back
#define int ll
#define INF 999999999
// #define INF (1LL<<59)

int data[1010][1010];
int dp[1010][1010];

int h, w, n;

void move(int y, int x) {
  if (y == h || x == w)
    cout << y + 1 << " " << x + 1 << endl;

  if (data[y][x] == 0)
    move(y + 1, x);
  if (data[y][x] == 1)
    move(y, x + 1);
}

signed main() {
  while (cin >> h >> w >> n && (h || w || n)) {

    rep(i, 1010) rep(j, 1010) data[i][j] = -1;
    rep(i, h) {
      rep(j, w) { cin >> data[i][j]; }
    }

    rep(i, 1010) rep(j, 1010) dp[i][j] = 0;
    dp[0][0] = n - 1;

    rep(i, h) {
      rep(j, w) {
        int d = dp[i][j] / 2, r = dp[i][j] / 2;
        if (data[i][j] == 0)
          d += dp[i][j] % 2;
        if (data[i][j] == 1)
          r += dp[i][j] % 2;

        dp[i + 1][j] += d;
        dp[i][j + 1] += r;
      }
    }

    rep(i, h) {
      rep(j, w) {
        if (dp[i][j] % 2 == 1)
          data[i][j] = !data[i][j];
      }
    }

    move(0, 0);
  }
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define pb push_back
#define int ll
#define INF 999999999
// #define INF (1LL<<59)

int data[1010][1010];
int dp[1010][1010];

int h, w, n;

void dfs(int y, int x, int num) {
  if (num == 0)
    return;
  if (y == h || x == w)
    return;
  dp[y][x] += num % 2;

  int d = num / 2, r = num / 2;
  if (data[y][x] == 0)
    d += num % 2;
  if (data[y][x] == 1)
    r += num % 2;

  dfs(y + 1, x, d);
  dfs(y, x + 1, r);
}

void move(int y, int x) {
  if (y == h || x == w)
    cout << y + 1 << " " << x + 1 << endl;

  if (data[y][x] == 0)
    move(y + 1, x);
  if (data[y][x] == 1)
    move(y, x + 1);
}

signed main() {
  while (cin >> h >> w >> n && (h || w || n)) {

    rep(i, 1010) rep(j, 1010) data[i][j] = -1;
    rep(i, h) {
      rep(j, w) { cin >> data[i][j]; }
    }

    rep(i, 1010) rep(j, 1010) dp[i][j] = 0;

    dfs(0, 0, n - 1);

    rep(i, h) {
      rep(j, w) {
        if (dp[i][j] % 2 == 1)
          data[i][j] = !data[i][j];
      }
    }

    move(0, 0);
  }
}
Problem p00464 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)

int dp[1003][1003];
int masu[1003][1003];
int main() {
  while (1) {
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    if (n == 0)
      break;
    rep(i, 1003) rep(j, 1003) masu[i][j] = dp[i][j] = 0;
    rep(i, n) {
      rep(j, m) { scanf("%d", &masu[j][i]); }
    }

    dp[0][0] = k - 1;

    rep(i, m) {
      rep(j, n) {
        dp[i + 1][j] += dp[i][j] / 2;
        dp[i][j + 1] += dp[i][j] / 2;

        if (dp[i][j] % 2 == 1) {
          if (masu[i][j] == 0) {
            dp[i][j + 1]++;
          } else {
            dp[i + 1][j]++;
          }
        }
        masu[i][j] += dp[i][j];
        masu[i][j] %= 2;
      }
    }

    int x = 0, y = 0;
    while (1) {
      if (masu[x][y] == 0) {
        y++;
      } else {
        x++;
      }
      if (y >= n || x >= m) {
        break;
      }
    }
    printf("%d %d\\n", y + 1, x + 1);
  }
}

/*
3 4 3
1 0 1 1
0 1 0 0
1 0 1 0

*/

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)

int main() {
  while (1) {
    int dp[203][203];
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    if (n == 0)
      break;
    int masu[203][203];
    rep(i, 103) rep(j, 103) masu[i][j] = dp[i][j] = 0;
    rep(i, n) {
      rep(j, m) { scanf("%d", &masu[j][i]); }
    }

    dp[0][0] = k - 1;

    rep(i, m) {
      rep(j, n) {
        dp[i + 1][j] += dp[i][j] / 2;
        dp[i][j + 1] += dp[i][j] / 2;

        if (dp[i][j] % 2 == 1) {
          if (masu[i][j] == 0) {
            dp[i][j + 1]++;
          } else {
            dp[i + 1][j]++;
          }
        }
        masu[i][j] += dp[i][j];
        masu[i][j] %= 2;
      }
    }

    int x = 0, y = 0;
    while (1) {
      if (masu[x][y] == 0) {
        y++;
      } else {
        x++;
      }
      if (y >= n || x >= m) {
        break;
      }
    }
    printf("%d %d\\n", y + 1, x + 1);
  }
}

/*
3 4 3
1 0 1 1
0 1 0 0
1 0 1 0

*/
Problem p00464 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <string.h>

int t[1002][1002];
int dp[1002][1002];

int main(void) {
  int i, j, ti, tj;
  int w, h, n;
  int d, gx, gy;

  while (scanf("%d%d%d", &h, &w, &n) && (h || w || n)) {
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
        scanf("%d", &t[i][j]);
      }
    }

    memset(dp, 0, sizeof(dp));
    dp[0][0] = n;
    gx = 0, gy = 0;

    for (tj = 0; tj < w && gx < w && gy < h; tj++) {
      for (i = 0; i < h && 0 <= tj - i && gx < w && gy < h; i++) {
        d = 0;
        j = tj - i;

        if (dp[i][j] % 2 == 0) {
          d = !t[i][j];
          dp[i][j + 1] += dp[i][j] / 2;
          dp[i + 1][j] += dp[i][j] / 2;
        } else {
          d = t[i][j];
          dp[i][j + 1] += dp[i][j] / 2 + d;
          dp[i + 1][j] += dp[i][j] / 2 + !d;
        }
        if (gx == j && gy == i) {
          gx += d;
          gy += !d;
        }
      }
    }

    for (ti = 1; ti < h && gx < w && gy < h; ti++) {
      for (tj = 0; tj < w && ti + tj < h && gx < w && gy < h; tj++) {
        d = 0;
        i = ti + tj;
        j = w - tj - 1;

        if (dp[i][j] % 2 == 0) {
          d = !t[i][j];
          dp[i][j + 1] += dp[i][j] / 2;
          dp[i + 1][j] += dp[i][j] / 2;
        } else {
          d = t[i][j];
          dp[i][j + 1] += dp[i][j] / 2 + d;
          dp[i + 1][j] += dp[i][j] / 2 + !d;
        }
        if (gx == j && gy == i) {
          gx += d;
          gy += !d;
        }
      }
    }

    printf("%d %d\\n", gy + 1, gx + 1);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;
typedef pair<int, int> P;

void solve() {
  int H, W, N;
  while (cin >> H >> W >> N, H || W || N) {
    vector<vector<int>> Field(H, vector<int>(W));
    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
        cin >> Field[i][j];
      }
    }
    P pos;
    for (int i = 0; i < N; ++i) {
      pos.first = 0;
      pos.second = 0;
      while (true) {
        if (pos.first == W || pos.second == H) {
          break;
        }
        if (Field[pos.second][pos.first] == 1) {
          Field[pos.second][pos.first] = 0;
          pos.first++;
        } else {
          Field[pos.second][pos.first] = 1;
          pos.second++;
        }
      }
    }
    cout << pos.second + 1 << " " << pos.first + 1 << endl;
  }
}

int main() {
  solve();
  return (0);
}
Problem p00464 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define FOR(i, b, n) for (int i = b; i < n; i++)
#define RFOR(i, b, n) for (int i = n - 1; i >= b; i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))

using namespace std;

static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> paii;

int h, w, n;
int ma[2000][2000];
int dp[2000][2000];

paii solve() {
  paii res = paii(0, 0);
  CLR(dp);

  dp[0][0] = n - 1;

  FOR(j, 0, h)
  FOR(i, 0, w) {
    if (dp[j][i] % 2 == 0) {
      dp[j + 1][i] += dp[j][i] / 2;
      dp[j][i + 1] += dp[j][i] / 2;
    } else {
      if (ma[j][i] == 0) {
        dp[j + 1][i] += (dp[j][i] + 1) / 2;
        dp[j][i + 1] += (dp[j][i] - 1) / 2;
      } else {
        dp[j + 1][i] += (dp[j][i] - 1) / 2;
        dp[j][i + 1] += (dp[j][i] + 1) / 2;
      }
    }
  }

  FOR(j, 0, h)
  FOR(i, 0, w) {
    if (dp[j][i] % 2 != 0)
      ma[j][i] = !ma[j][i];
  }

  while (res.first >= 0 && res.first < w && res.second >= 0 && res.second < h) {
    if (ma[res.second][res.first] == 1) // east
    {
      res.first++;
    } else // south
    {
      res.second++;
    }
  }

  res.first++;
  res.second++;

  return res;
}

int main() {
  while (cin >> h >> w >> n, (h || w || n)) {
    FOR(j, 0, h)
    FOR(i, 0, w) { cin >> ma[j][i]; }

    paii p = solve();

    cout << p.second << " " << p.first << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define FOR(i, b, n) for (int i = b; i < n; i++)
#define RFOR(i, b, n) for (int i = n - 1; i >= b; i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))

using namespace std;

static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> paii;

int h, w, n;
int ma[2000][2000];

paii solve() {
  paii res;

  FOR(k, 0, n) {
    int i = 0, j = 0;

    while (i >= 0 && i < w && j >= 0 && j < h) {
      if (ma[j][i] == 1) // east
      {
        ma[j][i] = 0;
        i++;
      } else {
        ma[j][i] = 1;
        j++;
      }
    }

    res.first = i + 1;
    res.second = j + 1;
  }

  return res;
}

int main() {
  while (cin >> h >> w >> n, (h || w || n)) {
    FOR(j, 0, h)
    FOR(i, 0, w) { cin >> ma[j][i]; }

    paii p = solve();

    cout << p.second << " " << p.first << endl;
  }

  return 0;
}
Problem p00464 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int grid[1000][1000];
int dp[1001][1001];
int dx[] = {1, 0};
int dy[] = {0, 1};

int main() {
  int h, w, n;
  while (scanf("%d %d %d", &h, &w, &n), h) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        scanf("%d", &grid[i][j]);
      }
    }

    memset(dp, 0, sizeof(dp));
    dp[0][0] = n - 1;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        dp[i][j + 1] += dp[i][j] / 2;
        dp[i + 1][j] += dp[i][j] / 2;
        if (dp[i][j] & 1) {
          if (grid[i][j] == 0)
            dp[i + 1][j]++;
          else
            dp[i][j + 1]++;
        }
      }
    }

    int nx = 0;
    int ny = 0;
    while (nx < h && ny < w) {
      int dir = (grid[nx][ny] + dp[nx][ny]) & 1;
      nx += dx[dir];
      ny += dy[dir];
    }

    printf("%d %d\\n", nx + 1, ny + 1);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;

const int dx[] = {0, 1};
const int dy[] = {1, 0};
int map[2000][2000];

int main() {
  int H, W, N;

  while (scanf("%d %d %d", &H, &W, &N), H + W + N) {

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        scanf("%d", &map[i][j]);
      }
    }

    int y, x;
    for (int i = 0; i < N; i++) {
      y = 0;
      x = 0;
      while (y < H && x < W) {
        int c = map[y][x];
        map[y][x] = !map[y][x];
        y += dy[c];
        x += dx[c];
      }
    }

    printf("%d %d\\n", y + 1, x + 1);
  }

  return 0;
}
Problem p00464 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int map[1001][1001];
int dp[1001][1001];
int main(void) {
  int h, w, n;
  int i, j;
  int x, y;

  scanf("%d %d %d", &h, &w, &n);
  while (h != 0 && w != 0 && n != 0) {
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        scanf("%d", &map[i][j]);
        dp[i][j] = 0;
      }
    }
    dp[1][1] = n - 1;
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        if (dp[i][j] % 2 == 0) {
          dp[i + 1][j] += dp[i][j] / 2;
          dp[i][j + 1] += dp[i][j] / 2;
        } else if (dp[i][j] % 2 != 0) {
          if (map[i][j] == 1) {
            dp[i][j + 1] += dp[i][j] / 2 + 1;
            dp[i + 1][j] += dp[i][j] / 2;
          } else if (map[i][j] == 0) {
            dp[i + 1][j] += dp[i][j] / 2 + 1;
            dp[i][j + 1] += dp[i][j] / 2;
          }
        }
      }
    }
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        if (dp[i][j] % 2 != 0) {
          if (map[i][j] == 1) {
            map[i][j] = 0;
          } else {
            map[i][j] = 1;
          }
        }
      }
    }
    x = 1;
    y = 1;
    while (x <= h && y <= w) {
      if (map[x][y] == 1) {
        y++;
      } else if (map[x][y] == 0) {
        x++;
      }
    }
    printf("%d %d\\n", x, y);
    scanf("%d %d %d", &h, &w, &n);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
int dp[1001][1001];
int map[1001][1001];
int main(void) {
  int h, w, n;
  int a, b;
  int i, j;

  scanf("%d %d %d", &h, &w, &n);
  while (h != 0 && w != 0 && n != 0) {
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        scanf("%d", &map[i][j]);
        dp[i][j] = 0;
      }
    }
    dp[1][1] = n - 1;
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        if (dp[i][j] % 2 == 0) {
          dp[i + 1][j] += dp[i][j] / 2;
          dp[i][j + 1] += dp[i][j] / 2;
        } else if (dp[i][j] % 2 != 0) {
          if (map[i][j] == 1) {
            dp[i + 1][j] += dp[i][j] / 2;
            dp[i][j + 1] += dp[i][j] / 2 + 1;
          } else if (map[i][j] == 0) {
            dp[i + 1][j] += dp[i][j] / 2 + 1;
            dp[i][j + 1] += dp[i][j] / 2;
          }
        }
      }
    }
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        if (dp[i][j] % 2 == 1) {
          if (map[i][j] == 1) {
            map[i][j] = 0;
          } else {
            map[i][j] = 1;
          }
        }
      }
    }
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        printf("%d ", map[i][j]);
      }
      printf("\\n");
    }
    a = b = 1;
    while (a <= h && b <= w) {
      if (map[a][b] == 0) {
        a++;
      } else if (map[a][b] == 1) {
        b++;
      }
    }
    printf("%d %d\\n", a, b);
    scanf("%d %d %d", &h, &w, &n);
  }
  return 0;
}
Problem p00464 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int map[1001][1001];
int dp[1001][1001];
int main(void) {
  int h, w, n;
  int i, j;
  int x, y;

  scanf("%d %d %d", &h, &w, &n);
  while (h != 0 && w != 0 && n != 0) {
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        scanf("%d", &map[i][j]);
        dp[i][j] = 0;
      }
    }
    dp[1][1] = n - 1;
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        if (dp[i][j] % 2 == 0) {
          dp[i + 1][j] += dp[i][j] / 2;
          dp[i][j + 1] += dp[i][j] / 2;
        } else if (dp[i][j] % 2 != 0) {
          if (map[i][j] == 1) {
            dp[i][j + 1] += dp[i][j] / 2 + 1;
            dp[i + 1][j] += dp[i][j] / 2;
          } else if (map[i][j] == 0) {
            dp[i + 1][j] += dp[i][j] / 2 + 1;
            dp[i][j + 1] += dp[i][j] / 2;
          }
        }
      }
    }
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        if (dp[i][j] % 2 != 0) {
          if (map[i][j] == 1) {
            map[i][j] = 0;
          } else {
            map[i][j] = 1;
          }
        }
      }
    }
    x = 1;
    y = 1;
    while (x <= h && y <= w) {
      if (map[x][y] == 1) {
        y++;
      } else if (map[x][y] == 0) {
        x++;
      }
    }
    printf("%d %d\\n", x, y);
    scanf("%d %d %d", &h, &w, &n);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int map[1001][1001];
int dp[1001][1001];
int main(void) {
  int h, w, n;
  int i, j;
  int x, y;

  scanf("%d %d %d", &h, &w, &n);
  while (h != 0 && w != 0 && n != 0) {
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        scanf("%d", &map[i][j]);
      }
    }
    while (n > 0) {
      x = 1;
      y = 1;
      while (x <= h && y <= w) {
        if (map[x][y] == 1) {
          map[x][y] = 0;
          y++;
        } else if (map[x][y] == 0) {
          map[x][y] = 1;
          x++;
        }
      }
      n--;
    }
    printf("%d %d\\n", x, y);
    scanf("%d %d %d", &h, &w, &n);
  }
  return 0;
}
Problem p00464 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <queue>

#define MAX 1024
#define fr first
#define sc second
#define mp make_pair

using namespace std;

typedef pair<int, int> pi;

void MakeCountMap(int h, int w, int M[][MAX], int cnt[][MAX]) {
  queue<pi> qp;
  bool vis[MAX][MAX] = {
      {
          false,
      },
  };
  qp.push(mp(0, 0));
  while (!qp.empty()) {
    pi now = qp.front();
    qp.pop();
    if (now.fr == h || now.sc == w)
      continue;
    int flr = cnt[now.fr][now.sc] / 2;
    int cel = cnt[now.fr][now.sc] % 2 == 0 ? flr : flr + 1;
    cnt[now.fr + 1][now.sc] += M[now.fr][now.sc] == 1 ? flr : cel;
    cnt[now.fr][now.sc + 1] += M[now.fr][now.sc] == 1 ? cel : flr;
    if (!vis[now.fr + 1][now.sc]) {
      vis[now.fr + 1][now.sc] = true;
      qp.push(mp(now.fr + 1, now.sc));
    }
    if (!vis[now.fr][now.sc + 1]) {
      vis[now.fr][now.sc + 1] = true;
      qp.push(mp(now.fr, now.sc + 1));
    }
  }
}

int main() {
  while (true) {
    static int M[MAX][MAX];
    static int cnt[MAX][MAX];
    int h, w, n;
    cin >> h >> w >> n;

    if (h == 0 && w == 0 && n == 0)
      break;

    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> M[i][j];
        cnt[i][j] = 0;
      }
    }
    cnt[0][0] = n;

    MakeCountMap(h, w, M, cnt);

    /*
    for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
        cout << cnt[i][j] << ' ';
      }
      cout << endl;
    }
    cout << endl;
    */

    int nowi = 0;
    int nowj = 0;
    while (nowi < h && nowj < w) {
      if (cnt[nowi][nowj] % 2 == 0) {
        M[nowi][nowj] = M[nowi][nowj] == 1 ? 0 : 1;
      }
      if (M[nowi][nowj]) {
        nowj++;
      } else {
        nowi++;
      }
    }
    cout << 1 + nowi << ' ' << 1 + nowj << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <queue>

#define MAX 1024
#define fr first
#define sc second
#define mp make_pair

using namespace std;

typedef pair<int, int> pi;

void MakeCountMap(int h, int w, int M[][MAX], int cnt[][MAX]) {
  queue<pi> qp;
  qp.push(mp(0, 0));
  while (!qp.empty()) {
    pi now = qp.front();
    qp.pop();
    if (now.fr == h || now.sc == w)
      continue;
    int flr = cnt[now.fr][now.sc] / 2;
    int cel = cnt[now.fr][now.sc] % 2 == 0 ? flr : flr + 1;
    cnt[now.fr + 1][now.sc] += M[now.fr][now.sc] == 1 ? flr : cel;
    cnt[now.fr][now.sc + 1] += M[now.fr][now.sc] == 1 ? cel : flr;
    qp.push(mp(now.fr + 1, now.sc));
    qp.push(mp(now.fr, now.sc + 1));
  }
}

int main() {
  while (true) {
    static int M[MAX][MAX];
    static int cnt[MAX][MAX];
    int h, w, n;
    cin >> h >> w >> n;

    if (h == 0 && w == 0 && n == 0)
      break;

    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> M[i][j];
        cnt[i][j] = 0;
      }
    }
    cnt[0][0] = n - 1;

    MakeCountMap(h, w, M, cnt);

    int nowi = 0;
    int nowj = 0;
    while (nowi < h && nowj < w) {
      if (!(M[nowi][nowj] & (1 & cnt[nowi][nowj]))) {
        nowj++;
      } else {
        nowi++;
      }
    }
    cout << 1 + nowi << ' ' << 1 + nowj << endl;
  }
  return 0;
}
Problem p00464 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
#define ALL(x) (x).begin(), (x).end()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define mp make_pair
#define eb emplace_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define INIT                                                                   \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0);

int maze[1010][1010], dp[1010][1010], h, w, n;

int main() {
  while (cin >> h >> w >> n && (h || w || n)) {
    for (int i = 1; i <= h; i++)
      for (int j = 1; j <= w; j++) {
        cin >> maze[i][j];
      }
    for (int i = 0; i < 1010; i++)
      for (int j = 0; j < 1010; j++) {
        dp[i][j] = 0;
      }
    n--, dp[1][1] = n;

    for (int i = 1; i <= h; i++)
      for (int j = 1; j <= w; j++) {
        dp[i][j] += dp[i][j - 1] / 2;
        if (maze[i][j - 1] == 1)
          dp[i][j] += dp[i][j - 1] % 2;
        dp[i][j] += dp[i - 1][j] / 2;
        if (maze[i - 1][j] == 0)
          dp[i][j] += dp[i - 1][j] % 2;
      }

    int y = 1, x = 1, t, f;
    while (y <= h && x <= w) {
      f = maze[y][x];
      if (dp[y][x] % 2)
        f = !f;
      if (f == 0)
        y++;
      else
        x++;
    }

    cout << y << " " << x << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
  int h, w, n;
  while (cin >> h >> w >> n && h != 0 && w != 0 && n != 0) {
    int map[1000][1000];
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> map[j][i];
      }
    }
    int ansh = 0, answ = 0;
    for (int i = 0; i < n; i++) {
      int posh = 0, posw = 0;
      while (posh != h && posw != w) {
        if (map[posw][posh] == 0) {
          map[posw][posh] = 1;
          posh++;
        } else {
          map[posw][posh] = 0;
          posw++;
        }
      }
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          cout << map[j][i];
        }
        cout << endl;
      }
      ansh = posh + 1, answ = posw + 1;
    }
    cout << ansh << " " << answ << endl;
  }
}