Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

// PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

ll power(ll x, ll y);
#define repp(I, A, B) for (int I = A; I <= B; I++)
#define rep(I, A, B) for (int I = A; I < B; I++)
#define rrep(I, B, A) for (int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define debug(this) cerr << "> " << #this << " : " << this << "\\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M)                                                            \\
  repp(I, 1, M) {                                                              \\
    int A, B;                                                                  \\
    cin >> A >> B;                                                             \\
    v[A].pb(B), v[B].pb(A);                                                    \\
  }
#define in_edges2(M)                                                           \\
  repp(I, 1, M) {                                                              \\
    int A, B;                                                                  \\
    cin >> A >> B;                                                             \\
    v[A].pb(B);                                                                \\
  }
#define in_edges3(M)                                                           \\
  repp(I, 1, M) {                                                              \\
    int A, B, C;                                                               \\
    cin >> A >> B >> C;                                                        \\
    v[A].pb(B, C), v[B].pb(A, C);                                              \\
  }
#define endl "\\n"

const ll MOD = 1000000007;
const ll INF = 1e18;
const int N = 3e5 + 4;

int r[N], c[N];

int main() // PointBlank's code ¯\\_(ツ)_/¯
{
  quickio int n, m, k;
  cin >> n >> m >> k;

  map<pair<int, int>, int> mp;
  int R[k], C[k];
  rep(i, 0, k) {
    cin >> R[i] >> C[i];
    r[R[i]]++, c[C[i]]++;
    mp[MP(R[i], C[i])]++;
  }

  int mr = 0, mc = 0;
  rep(i, 1, N) if (r[mr] < r[i]) mr = i;
  rep(i, 1, N) if (c[mc] < c[i]) mc = i;

  vector<int> row, col;
  rep(i, 1, N) if (r[i] == r[mr]) row.pb(i);
  rep(i, 1, N) if (c[i] == c[mc]) col.pb(i);

  int loop = 0;
  int mx = 0;
  for (auto i : row) {
    for (auto j : col) {
      loop++;
      if (loop > 2000000) {
        cout << mx;
        return 0;
      }
      int X = r[i] + c[j];
      X -= mp[MP(i, j)];
      mx = max(X, mx);
    }
  }

  cout << mx;
}

ll power(ll x, ll y) {
  ll res = 1;
  x %= MOD;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % MOD;
    y = y >> 1, x = (x * x) % MOD;
  }
  return res;
}

Error: TLE

Fixed submission:

// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

// PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

ll power(ll x, ll y);
#define repp(I, A, B) for (int I = A; I <= B; I++)
#define rep(I, A, B) for (int I = A; I < B; I++)
#define rrep(I, B, A) for (int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define debug(this) cerr << "> " << #this << " : " << this << "\\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M)                                                            \\
  repp(I, 1, M) {                                                              \\
    int A, B;                                                                  \\
    cin >> A >> B;                                                             \\
    v[A].pb(B), v[B].pb(A);                                                    \\
  }
#define in_edges2(M)                                                           \\
  repp(I, 1, M) {                                                              \\
    int A, B;                                                                  \\
    cin >> A >> B;                                                             \\
    v[A].pb(B);                                                                \\
  }
#define in_edges3(M)                                                           \\
  repp(I, 1, M) {                                                              \\
    int A, B, C;                                                               \\
    cin >> A >> B >> C;                                                        \\
    v[A].pb(B, C), v[B].pb(A, C);                                              \\
  }
#define endl "\\n"

const ll MOD = 1000000007;
const ll INF = 1e18;
const int N = 3e5 + 4;

int r[N], c[N];

int main() // PointBlank's code ¯\\_(ツ)_/¯
{
  quickio int n, m, k;
  cin >> n >> m >> k;

  map<pair<int, int>, int> mp;
  int R[k], C[k];
  rep(i, 0, k) {
    cin >> R[i] >> C[i];
    r[R[i]]++, c[C[i]]++;
    mp[MP(R[i], C[i])]++;
  }

  int mr = 0, mc = 0;
  rep(i, 1, N) if (r[mr] < r[i]) mr = i;
  rep(i, 1, N) if (c[mc] < c[i]) mc = i;

  vector<int> row, col;
  rep(i, 1, N) if (r[i] == r[mr]) row.pb(i);
  rep(i, 1, N) if (c[i] == c[mc]) col.pb(i);

  int mx = 0;
  for (auto i : row) {
    for (auto j : col) {
      int X = r[i] + c[j];
      X -= mp[MP(i, j)];
      mx = max(X, mx);
    }
  }

  cout << mx;
}

ll power(ll x, ll y) {
  ll res = 1;
  x %= MOD;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % MOD;
    y = y >> 1, x = (x * x) % MOD;
  }
  return res;
}