Problem p03282 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define gc getchar
#define t                                                                      \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--)
#define rep(i, j, k) for (i = j; i < k; i++)
#define rrep(i, j, k) for (i = j; i >= k; i--)
#define repm(i, j, n, m)                                                       \
  for (i = 0; i < n; i++)                                                      \
    for (j = 0; j < m; j++)
#define tr(c, it) for (auto it = (c).begin(); it != (c).end(); it++)
#define ZERO(a) memset(a, 0, sizeof(a))
#define lowbit(x) (x & (-x))
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define fin scan_int()
#define fout(x) fast_out(x)
#define pd(x) printf("%d ", x)
#define newl printf("\n")
#define xx first
#define yy second
#define INOUT take_input_and_output_from_file();
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define strtoint(s, n)                                                         \
  if (!(istringstream(s) >> n))                                                \
    n = 0;
#define mod 1000000007
typedef long long ll;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<string, ll> psi;
typedef pair<ll, ll> pii;

string inttostr(ll str) {
  stringstream stream;
  stream << str;
  return stream.str();
}
ll modexpo(ll a, ll b, ll n) {
  ll d = 1;
  while (b) {
    if (b & 1)
      d = (d * a) % n;
    b >>= 1;
    a = (a * a) % n;
  }
  return d;
}
ll expo(ll a, ll b) {
  ll d = 1;
  while (b) {
    if (b & 1)
      d = d * a;
    b >>= 1;
    a = a * a;
  }
  return d;
}
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll inv(ll a, ll m) { return modexpo(a, m - 2, m); }
void parr(ll a[], ll n) {
  ll i;
  rep(i, 0, n) cout << a[i] << " ";
  cout << endl;
}

void take_input_and_output_from_file() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

inline ll scan_int() {
  ll NR = 0, sign = 1;
  char c = gc();
  while (c < 48 || c > 57) {
    if (c == '-')
      sign = 0;
    c = gc();
  }
  while (c > 47 && c < 58) {
    NR = (NR << 3) + (NR << 1) + (c - 48);
    c = gc();
  }
  return (sign ? NR : (-NR));
}

////////////////////////////////////////////////////////////////////////////////////////////

int main() {
  INOUT;

  string s;
  cin >> s;
  ll i = 0;
  ll k = fin;
  if (s[0] != '1') {
    printf("%c\n", s[0]);
    return 0;
  }

  ll z = 0;
  while (s[z] == '1' && z < s.length())
    z++;
  if (k - 1 < z)
    cout << 1 << endl;
  else
    cout << s[z] << endl;

  return 0;
}


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

#define gc getchar
#define t                                                                      \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--)
#define rep(i, j, k) for (i = j; i < k; i++)
#define rrep(i, j, k) for (i = j; i >= k; i--)
#define repm(i, j, n, m)                                                       \
  for (i = 0; i < n; i++)                                                      \
    for (j = 0; j < m; j++)
#define tr(c, it) for (auto it = (c).begin(); it != (c).end(); it++)
#define ZERO(a) memset(a, 0, sizeof(a))
#define lowbit(x) (x & (-x))
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define fin scan_int()
#define fout(x) fast_out(x)
#define pd(x) printf("%d ", x)
#define newl printf("\n")
#define xx first
#define yy second
#define INOUT take_input_and_output_from_file();
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define strtoint(s, n)                                                         \
  if (!(istringstream(s) >> n))                                                \
    n = 0;
#define mod 1000000007
typedef long long ll;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<string, ll> psi;
typedef pair<ll, ll> pii;

string inttostr(ll str) {
  stringstream stream;
  stream << str;
  return stream.str();
}
ll modexpo(ll a, ll b, ll n) {
  ll d = 1;
  while (b) {
    if (b & 1)
      d = (d * a) % n;
    b >>= 1;
    a = (a * a) % n;
  }
  return d;
}
ll expo(ll a, ll b) {
  ll d = 1;
  while (b) {
    if (b & 1)
      d = d * a;
    b >>= 1;
    a = a * a;
  }
  return d;
}
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll inv(ll a, ll m) { return modexpo(a, m - 2, m); }
void parr(ll a[], ll n) {
  ll i;
  rep(i, 0, n) cout << a[i] << " ";
  cout << endl;
}

void take_input_and_output_from_file() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

inline ll scan_int() {
  ll NR = 0, sign = 1;
  char c = gc();
  while (c < 48 || c > 57) {
    if (c == '-')
      sign = 0;
    c = gc();
  }
  while (c > 47 && c < 58) {
    NR = (NR << 3) + (NR << 1) + (c - 48);
    c = gc();
  }
  return (sign ? NR : (-NR));
}

////////////////////////////////////////////////////////////////////////////////////////////

int main() {
  // INOUT;

  string s;
  cin >> s;
  ll i = 0;
  ll k = fin;
  if (s[0] != '1') {
    printf("%c\n", s[0]);
    return 0;
  }

  ll z = 0;
  while (s[z] == '1' && z < s.length())
    z++;
  if (k - 1 < z)
    cout << 1 << endl;
  else
    cout << s[z] << endl;

  return 0;
}