Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<ll>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;
 
  graph(ll n){
    init(n);
  }
 
  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }
 
  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }
 
  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
class UnionFind
{
public:
  ll par[100005];
  ll depth[100005];
  ll nGroup[100005];
 
  UnionFind(ll n) {
    init(n);
  }
 
  void init(ll n) {
    for(ll i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
 
  ll root(ll x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
 
  bool same(ll x, ll y) {
    return root(x) == root(y);
  }
 
  void unite(ll x, ll y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
 
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
} 
 
vector<ll> depth;
vector<ll> subtree_size;
void dfs(const Graph &G, ll v, ll p, ll d) {
    depth[v] = d;
    for (auto nv : G[v]) {
        if (nv == p) continue; // nv が親 p だったらダメ
        dfs(G, nv, v, d+1);
    }
 
    // 帰りがけ時に、部分木サイズを求める
    subtree_size[v] = INF; // 自分自身
    vl q;
    for (auto c : G[v]) {
        if (c == p) continue;
        q.pb(subtree_size[c]);// 子のサイズを加える
    }
  ll qq = q.size();
  //cout << v << " " << qq << endl;
  if(qq==0) subtree_size[v]=0;
  else{
  sort(all(q));
    //rep(i,qq)cout << q[i];
    //cout << endl;
  ll caa = 0;
  rep(i,qq){
    caa = max(qq+q[i]-i,caa);}
    subtree_size[v]=caa;
  }
}
ll dp[100005][2];
int main() {
ll H, W,m;
    cin >> H >> W >> m;
    ll hs[H+10]={};
    ll ws[W+10]={};
  set<ll> a;
  rep(i,m){
    ll b,c,d; cin>>b>>c;
    d = b*300000 + c;
    a.insert(d);
    hs[b]++;
    ws[c]++;}
  map<greater<ll>,ll>a1;
  map<greater<ll>,ll>a2;
  rep(i,300005){
    a1[hs[i]]=i;
    a2[ws[i]]=i;}
  ll ca = 0;
  ll ans = 0;
  ll ca1 = 0;
  for(auto p : a1){
    ca1 = max(ca1,p.fi);}
  ll ca2=0;
  for(auto p : a2){
    ca2 = max(ca2,p.fi);}
  for(auto p : a1){
    ll k = p.fi;
    ll k1 = p.se;
    if(ca1>k)break;
    for(auto pp : a2){
      ll k2 = pp.fi;
      ll k3 = pp.se;
      if(ca>k2) break;
      if(!a.count(k1*300000+k3)){
        ans = max(k + k2,ans);
        goto f;}
      ans = max(k+k2-1,ans);
    }
  }
  f:
  cout << ans << endl;}
    
    

Compiler output:
a.cc: In function 'int main()':
a.cc:193:7: error: no match for 'operator[]' (operand types are 'std::map<std::greater<long long int>, long long int>' and 'll' {aka 'long long int'})
  193 |     a1[hs[i]]=i;
      |       ^
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::greater<long long int>; _Tp = long long int; _Compare = std::less<std::greater<long long int> >; _Alloc = std::allocator<std::pair<const std::greater<long long int>, long long int> >; mapped_type = long long int; key_type = std::greater<long long int>]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from 'll' {aka 'long long int'} to 'const std::map<std::greater<long long int>, long long int>::key_type&' {aka 'const std::greater<long long int>&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = std::greater<long long int>; _Tp = long long int; _Compare = std::less<std::greater<long long int> >; _Alloc = std::allocator<std::pair<const std::greater<long long int>, long long int> >; mapped_type = long long int; key_type = std::greater<long long int>]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from 'll' {aka 'long long int'} to 'std::map<std::greater<long long int>, long long int>::key_type&&' {aka 'std::greater<long long int>&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:194:7: error: no match for 'operator[]' (operand types are 'std::map<std::greater<long long int>, long long int>' and 'll' {aka 'long long int'})
  194 |     a2[ws[i]]=i;}
      |       ^
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::greater<long long int>; _Tp = long long int; _Compare = std::less<std::greater<long long int> >; _Alloc = std::allocator<std::pair<const std::greater<long long int>, long long int> >; mapped_type = long long int; key_type = std::greater<long long int>]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from 'll' {aka 'long long int'} to 'const std::map<std::greater<long long int>, long long int>::key_type&' {aka 'const std::greater<long long int>&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = std::greater<long long int>; _Tp = long long int; _Compare = std::less<std::greater<long long int> >; _Alloc = std::allocator<std::pair<const std::greater<long long int>, long long int> >; mapped_type = long long int; key_type = std::greater<long long int>]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from 'll' {aka 'long long int'} to 'std::map<std::greater<long long int>, long long int>::key_type&&' {aka 'std::greater<long long int>&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:199:14: error: no matching function for call to 'max(ll&, const std::greater<long long int>&)'
  199 |     ca1 = max(ca1,p.fi);}
      |           ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:199:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::greater<long long int>')
  199 |     ca1 = max(ca1,p.fi);}
      |           ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:199:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  199 |     ca1 = max(ca1,p.fi);}
      |           ~~~^~~~~~~~~~
a.cc:202:14: error: no matching function for call to 'max(ll&, const std::greater<long long int>&)'
  202 |     ca2 = max(ca2,p.fi);}
      |           ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:202:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::greater<long long int>')
  202 |     ca2 = max(ca2,p.fi);}
      |           ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:202:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  202 |     ca2 = max(ca2,p.fi);}
      |           ~~~^~~~~~~~~~
a.cc:7:12: error: cannot convert 'const std::greater<long long int>' to 'll' {aka 'long long int'} in initialization
    7 | #define fi first
      |            ^
      |            |
      |            const std::greater<long long int>
a.cc:204:14: note: in expansion of macro 'fi'
  204 |     ll k = p.fi;
      |              ^~
a.cc:7:12: error: cannot convert 'const std::greater<long long int>' to 'll' {aka 'long long int'} in initialization
    7 | #define fi first
      |            ^
      |            |
      |            const std::greater<long long int>
a.cc:208:18: note: in expansion of macro 'fi'
  208 |       ll k2 = pp.fi;
      |                  ^~