Problem:
いちご 2 (Strawberry 2)
問題文
果物好きのビ太郎は，いちごのつかみ取りに挑戦することにした．ビ太郎の目の前には
1
脚の机がある．机は長方形の形をしており，縦
H
行，横
W
列のマス目状に区切られている．机には
N
個のいちごが置かれており，
i
番目 (
1 ≦ i ≦ N
) のいちごは上から
A
i
行目，左から
B
i
列目のマスにある．複数のいちごが同じマスに置かれている可能性もある．
ビ太郎は机から，縦
3
行，横
3
列の正方形の領域をなす
9
個のマスを選び，それらのマスにあるいちごをすべて取る．この動作は
1
回だけ行う．
ビ太郎は，なるべく多くのいちごを取りたい．
机の大きさといちごの位置についての情報が与えられたとき，取れるいちごの個数の最大値を求めるプログラムを作成せよ．
制約
3 ≦ H ≦ 1 000 000 000
．
3 ≦ W ≦ 1 000 000 000
．
1 ≦ N ≦ 60 000
．
1 ≦ A
i
≦ H
(
1 ≦ i ≦ N
)．
1 ≦ B
i
≦ W
(
1 ≦ i ≦ N
)．
入力される値はすべて整数である．
入力
入力は以下の形式で標準入力から与えられる．
H
W
N
A
1
B
1
A
2
B
2
:
A
N
B
N
出力
標準出力に，取れるいちごの個数の最大値を
1
行で出力せよ．
入出力例
入力例 1
4 5
7
1 1
1 5
2 2
2 4
3 3
4 2
4 4
出力例 1
5
いちごの配置は図のようになっている (赤い丸がいちごを表す)．
太枠で囲った領域をなすマスを選ぶことで，
5
個のいちごが取れる．
5
個よりも多くのいちごを取ることはできないので，
5
を出力する．
入力例 2
3 5
6
1 1
1 2
2 1
2 4
2 4
3 4
出力例 2
4
複数のいちごが同じマスに置かれていることもある．
入力例 3
3 99999
9
1 77813
2 77813
3 77813
1 77814
2 77814
3 77814
1 77815
2 77815
3 77815
出力例 3
9
入力例 4
11 11
20
7 7
6 11
5 7
8 8
9 9
5 5
8 4
4 4
4 8
2 6
1 6
6 2
3 3
9 3
7 5
6 1
10 6
6 10
11 6
3 9
出力例 4
4
情報オリンピック日本委員会
作 『日本情報オリンピック第2回女性部門 本選 競技課題』

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

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

    vector<pair<int, int>> strawberries(N);
    for (int i = 0; i < N; ++i) {
        int r, c;
        cin >> r >> c;
        strawberries[i] = {r, c};
    }

    map<pair<int, int>, int> count;

    for (auto [r, c] : strawberries) {
        // 3×3 の範囲の中心座標を列挙（いちごを含む可能性のある範囲）
        for (int dr = -2; dr <= 0; ++dr) {
            for (int dc = -2; dc <= 0; ++dc) {
                int center_r = r + dr + 1;
                int center_c = c + dc + 1;

                // 範囲が盤面内かチェック
                if (center_r - 1 >= 1 && center_r + 1 <= H &&
                    center_c - 1 >= 1 && center_c + 1 <= W) {
                    count[{center_r, center_c}]++;
                }
            }
        }
    }

    int max_strawberries = 0;
    for (auto [_, cnt] : count) {
        max_strawberries = max(max_strawberries, cnt);
    }

    cout << max_strawberries << endl;
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 37276
final_rank: 6

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>

struct Point {
    int row;
    int col;
    int num;
};

bool comp(const Point& a, const Point& b) {
    if (a.row == b.row)
        return a.col < b.col;
    else
        return a.row < b.row;
}

int main()
{
    int H, W, N;
    std::cin >> H >> W >> N;
    std::vector<Point> point(N * 9);
    std::vector<Point> point2(N * 9);

    int A, B;
    int j = 0;
    for (int i = 0; i < N; i++) {
        std::cin >> A >> B;
        if (A + 2 <= H) {
            if (B + 2 <= W) {
                point[j].row = A;
                point[j].col = B;
                point[j].num = 1;
                j++;
            }
            if (2 <= B && B + 1 <= W) {
                point[j].row = A;
                point[j].col = B - 1;
                point[j].num = 1;
                j++;
            }
            if (3 <= B && B <= W) {
                point[j].row = A;
                point[j].col = B - 2;
                point[j].num = 1;
                j++;
            }
        }
        if (2 <= A && A + 1 <= H) {
            if (B + 2 <= W) {
                point[j].row = A - 1;
                point[j].col = B;
                point[j].num = 1;
                j++;
            }
            if (2 <= B && B + 1 <= W) {
                point[j].row = A - 1;
                point[j].col = B - 1;
                point[j].num = 1;
                j++;
            }
            if (3 <= B && B <= W) {
                point[j].row = A - 1;
                point[j].col = B - 2;
                point[j].num = 1;
                j++;
            }
        }
        if (3 <= A && A <= H) {
            if (B + 2 <= W) {
                point[j].row = A - 2;
                point[j].col = B;
                point[j].num = 1;
                j++;
            }
            if (2 <= B && B + 1 <= W) {
                point[j].row = A - 2;
                point[j].col = B - 1;
                point[j].num = 1;
                j++;
            }
            if (3 <= B && B <= W) {
                point[j].row = A - 2;
                point[j].col = B - 2;
                point[j].num = 1;
                j++;
            }
        }
    }
    
    std::sort(point.begin(), point.end(), comp);

    j = 0;
    point2[0].row = point[0].row;
    point2[0].col = point[0].col;
    point2[0].num = point[0].num;
    for (int i = 1; i < point.size(); i++) {
        if (point[i].row == point[i - 1].row &&
            point[i].col == point[i - 1].col)
            point2[j].num += point[i].num;
        else {
            j++;
            point2[j].row = point[i].row;
            point2[j].col = point[i].col;
            point2[j].num = point[i].num;
        }
    }

    int max = -1000000000;
    for (int i = 0; i < point2.size(); i++)
        if (max < point2[i].num)
            max = point2[i].num;
        
    std::cout << max << std::endl;

    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 15776
final_rank: 3

code_snippet: #include <iostream>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <cstdlib>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

template <typename Map>
auto max_value_element(const Map& umap) {
    return std::max_element(
        umap.begin(), umap.end(),
        [](const auto& a, const auto& b) { return a.second < b.second; }
    );
}

struct pair_hash {
    template <typename T1, typename T2>
    size_t operator ()(const pair<T1, T2>& p) const {
        auto h1 = hash<T1>{}(p.first);
        auto h2 = hash<T2>{}(p.second);
        return h1 ^ (h2 << 1);
    }
};
const int dx[3]={-1,0,1};
const int dy[3]={-1,0,1};

int main(){
  int h,w,n;
  cin >> h >> w >> n;
  unordered_map<pair<int,int>,int,pair_hash> ami;
  rep(k,n){
    int a,b;
    cin >> a >> b;
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        ami[{a+dx[i],b+dy[j]}]++;
      }
    }
  }
  cout << max_value_element(ami)->second << endl;
  return 0;
}
accuracy: 1
time_ms: 790
memory_kb: 35332
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	unsigned int H, W;
	unsigned short N, i, j, _i, _j, max = 0, temp;
	cin >> H >> W >> N;
	vector<pair<unsigned int, unsigned int>> berry(N);
	for (i = 0; i != N; ++i) cin >> berry[i].first >> berry[i].second;
	stable_sort(berry.begin(), berry.end());

	for (i = 0; i != N; ++i)
	{
		for (_i = 0; _i != 3 && berry[i].first >= _i; ++_i)
			for (_j = 0; _j != 3 && berry[i].second >= _j; ++_j)
			{
				temp = 0;
				for (j = 0; j != 3; ++j)
					temp += lower_bound(berry.begin(), berry.end(), make_pair(berry[i].first - _i + j, berry[i].second - _j + 3)) - lower_bound(berry.begin(), berry.end(), make_pair(berry[i].first - _i + j, berry[i].second - _j));
				if (temp > max) max = temp;
			}
	}

	cout << max << '\n';
	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 4156
final_rank: 1

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }
template<typename T=ll,size_t N>
array<T,N> arrin(){array<T,N> x;REP(i,N){ x[i]=in<T>(); }return x;}

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	auto H=in(),W=in(),N=in();
	vll S(N);
	REP(i,N){
		auto Y=in(),X=in();
		S[i]=X+Y*W;
	}
	sort(ALL(S));
	ll C=0;
	REP(i,N){
		ll offset[9]={-W-1ll,-W,-W+1ll,-1ll,0ll,1ll,W-1ll,W,W+1ll};
		REP(j,9){
			ll A=0;
			REP(k,9){
				auto res = equal_range(ALL(S),S[i]+offset[j]+offset[k]);
				A += distance(res.first,res.second);
			}
			chmax(C,A);
		}
	}
	out(C);
	return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 3612
final_rank: 2

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  if (x < 0) { cout << (i64)(x); }
  else { cout << (u64)(x); }
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll H, W, N, A, B;
  cin >> H >> W >> N;
  map<pi, ll> ichigo;
  rep(N) {
    cin >> A >> B;
    ichigo[mp(A, B)]++;
  }
  set<pi> centered;
  ll ans = 0;
  for (auto [p, c]: ichigo) {
    ll y = p.fi;
    ll x = p.se;
    static const vi dy{-1,-1,-1, 0, 0, 0, 1, 1, 1};
    static const vi dx{-1, 0, 1,-1, 0, 1,-1, 0, 1};
    auto calc_count = [&](ll y, ll x) {
      ll ret = 0;
      rep(i, len(dy)) {
        ll ny = y + dy[i];
        ll nx = x + dx[i];
        auto np = mp(ny, nx);
        if (ichigo.find(np) != ichigo.end()) {
          ret += ichigo[np];
        }
      }
      return ret;
    };
    rep(i, len(dy)) {
      ll ny = y + dy[i];
      ll nx = x + dx[i];
      auto np = mp(ny, nx);
      if (centered.find(np) == centered.end()) {
        chmax(ans, calc_count(ny, nx));
      }
    }
  }
  print(ans);
  return 0;
}
accuracy: 1
time_ms: 630
memory_kb: 7208
final_rank: 12

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }
template<typename T=ll,size_t N>
array<T,N> arrin(){array<T,N> x;REP(i,N){ x[i]=in<T>(); }return x;}

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto H=in(),W=in(),N=in();
	vll S(N);
	REP(i,N){
		auto X=in(),Y=in();
		S[i]=X+Y*W;
	}
	sort(ALL(S));
	ll C=0;
	REP(i,N){
		ll offset[9]={-W-1ll,-W,-W+1ll,-1ll,0ll,1ll,W-1ll,W,W+1ll};
		REP(j,9){
			ll A=0;
			REP(k,9){
				auto res = equal_range(ALL(S),S[i]+offset[j]+offset[k]);
				A += distance(res.first,res.second);
			}
			chmax(C,A);
		}
	}
	out(C);
	return 0;
}
accuracy: 0.32
time_ms: 130
memory_kb: 3608
final_rank: 18

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0732.cc: いちご 2 (Strawberry 2)
 */

#include<cstdio>
#include<map>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

/* typedef */

typedef pair<int,int> pii;
typedef map<pii,int> mpii;

/* global variables */

/* subroutines */

/* main */

int main() {
  int h, w, n;
  scanf("%d%d%d", &h, &w, &n);

  mpii pcs;

  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);

    for (int da = 0; da < 3; da++)
      for (int db = 0; db < 3; db++) {
	int a0 = a - da, a1 = a0 + 2;
	int b0 = b - db, b1 = b0 + 2;
	if (1 <= a0 && a1 <= h && 1 <= b0 && b1 <= w)
	  pcs[pii(a0, b0)]++;
      }
  }

  int maxc = 0;
  for (auto &pc: pcs)
    maxc = max(maxc, pc.second);

  printf("%d\n", maxc);

  return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 36760
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}


int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);
   
    ll H,W;
    cin>>H>>W;
    ll N;
    cin>>N;
    unordered_map<ll,ll> M;
    vll dy={-1,0,1};
    vll dx=dy;
    ll WW=2e9;
    rep(i,N){
        ll A,B;
        cin>>A>>B;
        rep(yy,3)rep(xx,3){
            M[(A+dy[yy])*WW+B+dx[xx]]++;
        }
    }
    ll an=0;
    for(auto p:M)chmax(an,p.second);
    cout<<an<<endl;
}
accuracy: 1
time_ms: 70
memory_kb: 27576
final_rank: 4

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int H,W; cin >> H >> W;
    int n; cin >> n;
    vector<int> a(n),b(n);
    int res = 0;
    map<pair<int,int>,int> mp;
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
        for(int j=-1;j<=1;j++){
            for(int k=-1;k<=1;k++){
                mp[{a[i]+j,b[i]+k}]++;
            }
        }
    }
    for(auto p:mp){
        res = max(res, p.second);
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 140
memory_kb: 37420
final_rank: 7

code_snippet: #include<iostream>
#include<vector>
#include<map>
using namespace std;

int main(){
    int h,w,n;
    cin >> h >> w >> n;
    //vector<vector<int>> straw(h+1,vector<int>(w+1,0));
    map<pair<int, int>, int> straw;
    vector<int> a(n),b(n);

    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i < n; i++){
        straw[pair(a[i]-1, b[i]-1)] += 1;
        //cout << a[i]-1 << b[i]-1 << endl;
    }
    int max = -1, t = 0;

    //存在と周囲8マスを中心として判定を行う
    for(int i = 0; i < n; i++){               //いちごのあるマスを参照する
        for(int j = -1; j <= 1; j++){               //いちごの縦+-1の範囲を中心に
            for(int k = -1; k <= 1; k++){           //いちごの横+-1の範囲を中心に

                for(int l = -1; l <= 1; l++){       //
                    for(int m = -1; m <= 1; m++){   //上と共に、中心と周囲8マスを探索
                        if(a[i]+j+l-1 < 0 or b[i]+k+m-1 < 0){break;}
                        else if(h < a[i]+j+l-1 or w < b[i]+k+m-1){break;}
                        else if(straw[pair(a[i]+j+l-1, b[i]+k+m-1)] > 0){
                        t += straw[pair(a[i]+j+l-1, b[i]+k+m-1)];
                        }
                    }
                }
                if(max < t){max = t;}
                t = 0;
            }
        }
    }
    cout << max << endl;
}
accuracy: 1
time_ms: 550
memory_kb: 97236
final_rank: 14

code_snippet: #include<iostream>
#include<vector>
using namespace std;

int main(){
    int h,w,n;
    cin >> h >> w >> n;
    vector<vector<int>> straw(h+1,vector<int>(w+1,0));
    vector<int> a(n),b(n);

    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i < n; i++){
        straw[a[i]-1][b[i]-1] += 1;
        //cout << a[i]-1 << b[i]-1 << endl;
    }
    int max = -1, t = 0;
    //存在の周囲8マスのみから判定を行う
    for(int i = 0; i < n; i++){                     //いちごのあるマスを参照する
        for(int j = -1; j <= 1; j++){               //いちごの縦+-1の範囲を中心に
            for(int k = -1; k <= 1; k++){           //いちごの横+-1の範囲を中心に

                for(int l = -1; l <= 1; l++){       //
                    for(int m = -1; m <= 1; m++){   //上と共に、中心の周囲8マスを探索
                        if(a[i]+j+l-1 < 0 or b[i]+k+m-1 < 0){break;}
                        else if(h < a[i]+j+l-1 or w < b[i]+k+m-1){break;}
                        else if(straw[a[i]+j+l-1][b[i]+k+m-1] > 0){
                        t += straw[a[i]+j+l-1][b[i]+k+m-1];
                        }
                    }
                }
                if(max < t){max = t;}
                t = 0;
            }
        }
    }
    cout << max << endl;
}
accuracy: 0.375
time_ms: 20
memory_kb: 7576
final_rank: 17

code_snippet: #include<iostream>
#include<vector>
using namespace std;

int main(){
    int h,w,n;
    cin >> h >> w >> n;
    vector<vector<int>> straw(h+1,vector<int>(w+1,0));
    vector<int> a(n),b(n);

    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i < n; i++){
        straw[a[i]-1][b[i]-1] += 1;
        //cout << a[i]-1 << b[i]-1 << endl;
    }
    int max = -1, t = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int k = 0; k < 3; k++){
                for(int l = 0; l < 3; l++){
                    if(h < i+k or w < j+l){break;}
                    else if(i+k < 0 or j+l < 0){break;}
                    else if(straw[i+k][j+l] > 0){t += straw[i+k][j+l];}
                    }
                }

                //for(int k = 0; k < 3; k++){
                  //  for(int l = 0; l < 3; l++){
                   //     if(h < a[i]+k-1 or w < b[i]+l-1){break;}
                     //   else if(a[i]+k-1 < 0 or b[i]+l-1 < 0){break;}
                       // else if(straw[a[i]+k-1][b[i]+l-1] > 0){t += straw[a[i]+k-1][b[i]+l-1];}
                 //   }
               // }
                if(max < t){max = t;}
                t = 0;
        }
    }
    cout << max << endl;
}
accuracy: 0.375
time_ms: 20
memory_kb: 7572
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001



#define SIZE 60005

int H,W;
map<pair<int,int>,int> MAP;
int R[SIZE],C[SIZE];

bool rangeCheck(int row,int col){

	return row >= 1 && row <= H && col >= 1 && col <= W;
}

int main(){

	scanf("%d %d",&H,&W);

	int N;
	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		scanf("%d %d",&R[i],&C[i]);
		MAP[make_pair(R[i],C[i])]++;
	}

	int maxi = 0;
	for(int i = 0; i < N; i++){
		for(int diff_row = -1; diff_row <= 1; diff_row++){
			for(int diff_col = -1; diff_col <= 1; diff_col++){

				int base_row = R[i]+diff_row,base_col = C[i]+diff_col;
				if(!rangeCheck(base_row,base_col)){

					continue;
				}

				int tmp = 0;
				for(int d_row = -1; d_row <= 1; d_row++){
					for(int d_col = -1; d_col <= 1; d_col++){
						int tmp_row = base_row+d_row;
						int tmp_col = base_col+d_col;

						if(!rangeCheck(tmp_row,tmp_col)){
							continue;
						}

						auto at = MAP.find(make_pair(tmp_row,tmp_col));
						if(at == MAP.end()){
							continue;
						}

						tmp += MAP[make_pair(tmp_row,tmp_col)];
					}
				}
				chmax(maxi,tmp);
			}
		}
	}

	printf("%d\n",maxi);

	return 0;
}
accuracy: 1
time_ms: 480
memory_kb: 7784
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = std::int64_t;
#define REP(i, m, n) for (int i = (m); i < int(n); ++i)
#define rep(i, n) REP(i, 0, n)
template <class T, class U>
bool chmax(T &a, const U b) {
    return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
bool chmin(T &a, const U b) {
    return (T)b < a ? a = (T)b, true : false;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &i : v) is >> i;
    return is;
}
constexpr std::int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr int MOD = 1000000007;

int main(void) {
    ll h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    map<pair<ll, ll>, int> mp;
    while (n--) {
        ll x, y;
        cin >> x >> y;
        rep (dx, 3) {
            rep (dy, 3) mp[{x + dx, y + dy}]++;
        }
    }

    int ans = 0;
    for (auto [p, s] : mp) {
        chmax(ans, s);
    }
    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 37188
final_rank: 8

code_snippet: #include <bits/extc++.h>

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)
#define all(x) begin(x),end(x)
#define Fixed fixed << setprecision(12)
#define updiv(a, b) (((a) + (b) - 1) / (b))
using pii = pair<int,int>;
constexpr int32_t INF  = 0x3f3f3f3f;
constexpr int_fast64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p){ is >> p.first >> p.second; return (is); }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p){ os << p.first << ' ' << p.second; return (os); }
template<class T> istream& operator>>(istream& is, vector<T>& v){ for (auto &&e : v) is >> e; return (is); }
template<class T> ostream& operator<<(ostream& os, vector<T>& v){ for (auto &&e : v) os << e << ' '; return (os); }

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
template <class A, class B> using umap = unordered_map<A, B>;
template <class T> using uset = unordered_set<T>;

template <class T> using Max_Heap = __gnu_pbds::priority_queue<T, less<T>, __gnu_pbds::rc_binomial_heap_tag>;
template <class T> using Min_Heap = __gnu_pbds::priority_queue<T, greater<T>, __gnu_pbds::rc_binomial_heap_tag>;
template <class T> using Set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class K, class V> using Umap = __gnu_pbds::gp_hash_table<K, V>;
template <class T> using Rope = __gnu_cxx::rope<T>;
using Trie = __gnu_pbds::trie<string, __gnu_pbds::null_type, __gnu_pbds::trie_string_access_traits<>, __gnu_pbds::pat_trie_tag, __gnu_pbds::trie_prefix_search_node_update>;

template <class T> void bye(T x){ cout << x << '\n'; exit(0); }
inline int square(int a){ return (a * a); }

constexpr int dx[] = {1,0,-1,0,1,1,-1,-1,0};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1,0};

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    int h, w, n;
    cin >> h >> w >> n;

    assert(3 <= h && h <= 1000000000);
    assert(3 <= w && w <= 1000000000);
    assert(1 <= n && n <= 60000);

    map<pair<int, int>, int> mp;

    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        assert(1 <= a && a <= h);
        assert(1 <= b && b <= w);
        mp[make_pair(a, b)]++;
    }

    int res = 0;

    for (auto [k, v] : mp) {
        auto [a, b] = k;
        for (int i = 0; i < 9; ++i) {
            int ca = a + dx[i];
            int cb = b + dy[i];
            int cnt = 0;
            for (int j = 0; j < 9; ++j) {
                int na = ca + dx[j];
                int nb = cb + dy[j];
                if (auto itr = mp.find(make_pair(na, nb)); itr != mp.end()) {
                    cnt += itr->second;
                }
            }
            chmax(res, cnt);
        }
    }

    cout << res << '\n';

    return (0);
}
accuracy: 1
time_ms: 420
memory_kb: 7144
final_rank: 10

code_snippet: #include <bits/extc++.h>

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)
#define all(x) begin(x),end(x)
#define Fixed fixed << setprecision(12)
#define updiv(a, b) (((a) + (b) - 1) / (b))
using pii = pair<int,int>;
constexpr int32_t INF  = 0x3f3f3f3f;
constexpr int_fast64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p){ is >> p.first >> p.second; return (is); }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p){ os << p.first << ' ' << p.second; return (os); }
template<class T> istream& operator>>(istream& is, vector<T>& v){ for (auto &&e : v) is >> e; return (is); }
template<class T> ostream& operator<<(ostream& os, vector<T>& v){ for (auto &&e : v) os << e << ' '; return (os); }

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
template <class A, class B> using umap = unordered_map<A, B>;
template <class T> using uset = unordered_set<T>;

template <class T> using Max_Heap = __gnu_pbds::priority_queue<T, less<T>, __gnu_pbds::rc_binomial_heap_tag>;
template <class T> using Min_Heap = __gnu_pbds::priority_queue<T, greater<T>, __gnu_pbds::rc_binomial_heap_tag>;
template <class T> using Set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class K, class V> using Umap = __gnu_pbds::gp_hash_table<K, V>;
template <class T> using Rope = __gnu_cxx::rope<T>;
using Trie = __gnu_pbds::trie<string, __gnu_pbds::null_type, __gnu_pbds::trie_string_access_traits<>, __gnu_pbds::pat_trie_tag, __gnu_pbds::trie_prefix_search_node_update>;

template <class T> void bye(T x){ cout << x << '\n'; exit(0); }
inline int square(int a){ return (a * a); }

constexpr int dx[] = {1,0,-1,0,1,1,-1,-1,0};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1,0};

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    int h, w, n;
    cin >> h >> w >> n;

    assert(3 <= h && h <= 1000000000);
    assert(3 <= w && w <= 1000000000);
    assert(1 <= n && n <= 60000);

    map<pair<int, int>, int> mp;

    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        mp[make_pair(a, b)]++;
    }

    int res = 0;

    for (auto [k, v] : mp) {
        auto [a, b] = k;
        for (int i = 0; i < 9; ++i) {
            int ca = a + dx[i];
            int cb = b + dy[i];
            int cnt = 0;
            for (int j = 0; j < 9; ++j) {
                int na = ca + dx[j];
                int nb = cb + dy[j];
                if (auto itr = mp.find(make_pair(na, nb)); itr != mp.end()) {
                    cnt += itr->second;
                }
            }
            chmax(res, cnt);
        }
    }

    cout << res << '\n';

    return (0);
}
accuracy: 1
time_ms: 410
memory_kb: 7252
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcountll(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define vector4d(type,name,h,w,d,...) vector<vector<vector<vector<type>>>>name(h,vector<vector<vector<type>>>(w,vector<vector<type>>(d,vector<type>(__VA_ARGS__))))
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
int msb(ll v){return 63-__builtin_clzll(v);}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(h,w);
    map<int,map<int,int>> mp;
    INT(n);
    vector<array<int,2>> a(n);
    rep(i,n){
        in(a[i][0],a[i][1]);
        mp[a[i][0]][a[i][1]]++;
    }
    auto f=[&](int x,int y){
        int res=0;
        for(int dx=-1;dx<=1;dx++){
            for(int dy=-1;dy<=1;dy++){
                res+=mp[x+dx][y+dy];
            }
        }
        return res;
    };
    int ans=0;
    rep(i,n){
        for(int dx=-1;dx<=1;dx++){
            for(int dy=-1;dy<=1;dy++){
                chmax(ans,f(a[i][0]+dx,a[i][1]+dy));
            }
        }
    }
    out(ans);
}
accuracy: 1
time_ms: 550
memory_kb: 101964
final_rank: 15