problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02579
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; int x[4] = {-1, 0, 1, 0}; int y[4] = {0, 1, 0, -1}; queue<P> q; char c[1100][1100]; int b[1100][1100]; int h, w, ch, dh, cw, dw; int main() { cin >> h >> w; cin >> ch >> cw >> dh >> dw; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> c[i][j]; } } // memset(b,-1,sizeof(b)); q.push(make_pair(ch, cw)); for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { b[i][j] = -1; } } b[ch][cw] = 0; vector<vector<P>> v(100000); v[0].push_back(make_pair(ch, cw)); int now; while (1) { int cnt = 0; while (!q.empty()) { P tmp = q.front(); q.pop(); int dx = tmp.first; int dy = tmp.second; now = b[dx][dy]; // if(dx == dh && dy == dw){ // cout << b[dh][dw] << endl; // return 0; // } for (int i = 0; i < 4; i++) { int xx = dx + x[i]; int yy = dy + y[i]; if (xx >= 1 && xx <= h && yy >= 1 && yy <= w && c[xx][yy] != '#' && b[xx][yy] == -1) { b[xx][yy] = b[dx][dy]; q.push(make_pair(xx, yy)); v[now].push_back(make_pair(xx, yy)); } } } for (int i = 0; i < v[now].size(); i++) { int dx = v[now][i].first; int dy = v[now][i].second; for (int j = -2; j <= 2; j++) { for (int k = -2; k <= 2; k++) { int xx = dx + j; int yy = dy + k; if (xx >= 1 && xx <= h && yy >= 1 && yy <= w && c[xx][yy] != '#' && b[xx][yy] == -1) { b[xx][yy] = b[dx][dy] + 1; q.push(make_pair(xx, yy)); int t = b[xx][yy]; v[t].push_back(make_pair(xx, yy)); cnt++; } } } } if (!cnt) break; } cout << b[dh][dw] << endl; // for(int i = 1;i<=h;i++){ // for(int j = 1;j<=w;j++){ // printf("%2d ",b[i][j]); // } // cout << endl; // } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; int x[4] = {-1, 0, 1, 0}; int y[4] = {0, 1, 0, -1}; queue<P> q; char c[1100][1100]; int b[1100][1100]; int h, w, ch, dh, cw, dw; int main() { cin >> h >> w; cin >> ch >> cw >> dh >> dw; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> c[i][j]; } } // memset(b,-1,sizeof(b)); q.push(make_pair(ch, cw)); for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { b[i][j] = -1; } } b[ch][cw] = 0; vector<vector<P>> v(1000010); v[0].push_back(make_pair(ch, cw)); int now; while (1) { int cnt = 0; while (!q.empty()) { P tmp = q.front(); q.pop(); int dx = tmp.first; int dy = tmp.second; now = b[dx][dy]; // if(dx == dh && dy == dw){ // cout << b[dh][dw] << endl; // return 0; // } for (int i = 0; i < 4; i++) { int xx = dx + x[i]; int yy = dy + y[i]; if (xx >= 1 && xx <= h && yy >= 1 && yy <= w && c[xx][yy] != '#' && b[xx][yy] == -1) { b[xx][yy] = b[dx][dy]; q.push(make_pair(xx, yy)); v[now].push_back(make_pair(xx, yy)); } } } for (int i = 0; i < v[now].size(); i++) { int dx = v[now][i].first; int dy = v[now][i].second; for (int j = -2; j <= 2; j++) { for (int k = -2; k <= 2; k++) { int xx = dx + j; int yy = dy + k; if (xx >= 1 && xx <= h && yy >= 1 && yy <= w && c[xx][yy] != '#' && b[xx][yy] == -1) { b[xx][yy] = b[dx][dy] + 1; q.push(make_pair(xx, yy)); int t = b[xx][yy]; v[t].push_back(make_pair(xx, yy)); cnt++; } } } } if (!cnt) break; } cout << b[dh][dw] << endl; // for(int i = 1;i<=h;i++){ // for(int j = 1;j<=w;j++){ // printf("%2d ",b[i][j]); // } // cout << endl; // } return 0; }
replace
26
27
26
27
0
p02579
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 7; int mat[N][N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int h, w, sI, sJ, eI, eJ; cin >> h >> w >> sI >> sJ >> eI >> eJ; sI--; sJ--; eI--; eJ--; for (int i = 0; i < h; i++) { string s; cin >> s; for (int j = 0; j < w; j++) { if (s[j] == '#') mat[i][j] = 1; else mat[i][j] = 0; } } deque<pair<int, int>> q; vector<vector<int>> d(h, vector<int>(w, 1e9 + 7)); q.push_front({sI, sJ}); d[sI][sJ] = 0; int dir[] = {1, 0, -1, 0, 1}; while (!q.empty()) { int cI, cJ; tie(cI, cJ) = q.front(); q.pop_front(); for (int i = 0; i < 4; i++) { int nI = cI + dir[i]; int nJ = cJ + dir[i + 1]; if (nI >= h || nI < 0 || nJ >= w || nJ < 0) continue; if (mat[nI][nJ]) continue; if (d[nI][nJ] > d[cI][cJ]) { d[nI][nJ] = d[cI][cJ]; q.push_front({nI, nJ}); } } for (int i = -2; i <= 2; i++) { for (int j = -2; j <= 2; j++) { int nI = cI + i; int nJ = cJ + j; if (nI >= h || nI < 0 || nJ >= w || nJ < 0) continue; if (mat[nI][nJ]) continue; if (d[nI][nJ] > d[cI][cJ] + 1) { d[nI][nJ] = d[cI][cJ] + 1; q.push_front({nI, nJ}); } } } } if (d[eI][eJ] == 1e9 + 7) cout << -1 << endl; else cout << d[eI][eJ] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 7; int mat[N][N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int h, w, sI, sJ, eI, eJ; cin >> h >> w >> sI >> sJ >> eI >> eJ; sI--; sJ--; eI--; eJ--; for (int i = 0; i < h; i++) { string s; cin >> s; for (int j = 0; j < w; j++) { if (s[j] == '#') mat[i][j] = 1; else mat[i][j] = 0; } } deque<pair<int, int>> q; vector<vector<int>> d(h, vector<int>(w, 1e9 + 7)); q.push_front({sI, sJ}); d[sI][sJ] = 0; int dir[] = {1, 0, -1, 0, 1}; while (!q.empty()) { int cI, cJ; tie(cI, cJ) = q.front(); q.pop_front(); for (int i = 0; i < 4; i++) { int nI = cI + dir[i]; int nJ = cJ + dir[i + 1]; if (nI >= h || nI < 0 || nJ >= w || nJ < 0) continue; if (mat[nI][nJ]) continue; if (d[nI][nJ] > d[cI][cJ]) { d[nI][nJ] = d[cI][cJ]; q.push_front({nI, nJ}); } } for (int i = -2; i <= 2; i++) { for (int j = -2; j <= 2; j++) { int nI = cI + i; int nJ = cJ + j; if (nI >= h || nI < 0 || nJ >= w || nJ < 0) continue; if (mat[nI][nJ]) continue; if (d[nI][nJ] > d[cI][cJ] + 1) { d[nI][nJ] = d[cI][cJ] + 1; q.push_back({nI, nJ}); } } } } if (d[eI][eJ] == 1e9 + 7) cout << -1 << endl; else cout << d[eI][eJ] << endl; return 0; }
replace
55
56
55
56
TLE
p02579
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> Pii; typedef pair<int, ll> Pil; typedef pair<ll, ll> Pll; typedef pair<int, ld> Pid; typedef pair<int, string> Pis; #define rep(i, n) for (int i = 0; i < n; i++) #define repm(i, s, n) for (int i = s; i < n; i++) #define all(a) (a).begin(), (a).end() const int INF = 1 << 30; const ll INF_L = 1LL << 60; const int MOD = 1e9 + 7; // 998244353; void coi(ll i) { cout << i << endl; } void cois(ll i) { cout << i << " "; } void cod(ld d) { cout << fixed << setprecision(16); cout << d << endl; } void cods(ld d) { cout << fixed << setprecision(16); cout << d << " "; } void coc(char c) { cout << c << endl; } void cocs(char c) { cout << c << " "; } void cos(string s) { cout << s << endl; } void coss(string s) { cout << s << " "; } void coynl(bool b) { cos(b ? "Yes" : "No"); } void coYNU(bool b) { cos(b ? "YES" : "NO"); } // ---------------------------------------------------------------- // String Functions // ---------------------------------------------------------------- int ctoi(char c) { if (isdigit(c)) return c - '0'; else if (islower(c)) return c - 'a'; else if (isupper(c)) return c - 'A'; else return -1; } char itocd(int i) { char c = i + '0'; if (isdigit(c)) return c; else return 0x00; } char itocl(int i) { char c = i + 'a'; if (islower(c)) return c; else return 0x00; } char itocu(int i) { char c = i + 'A'; if (isupper(c)) return c; else return 0x00; } // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Dynamical Programming // ---------------------------------------------------------------- template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Graph Theory // ---------------------------------------------------------------- struct edge { ll to, cost; }; struct graph_list { ll V; vector<vector<edge>> graph; vector<ll> dist; graph_list(ll n) { init(n); } void init(ll n) { V = n; graph.resize(V); dist.resize(V); for (int i = 0; i < V; i++) { dist[i] = INF_L; } } void add_edge(ll from, ll to, ll cost) { edge e; e.to = to; e.cost = cost; graph[from].push_back(e); } void dijkstra(ll s) { for (int i = 0; i < V; i++) { dist[i] = INF_L; } dist[s] = 0; priority_queue<Pll, vector<Pll>, greater<Pll>> que; que.push(Pll(0, s)); while (!que.empty()) { Pll p = que.top(); que.pop(); ll v = p.second; if (dist[v] < p.first) continue; for (auto e : graph[v]) { if (dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; que.push(Pll(dist[e.to], e.to)); } } } } void bellman_ford(ll s) { for (int i = 0; i < V; i++) { dist[i] = INF_L; } dist[s] = 0; } }; struct graph_matrix { ll vertex; vector<vector<edge>> graph; vector<ll> dist; graph_matrix(ll n) { init(n); } void init(ll n) { vertex = n; graph.resize(vertex); dist.resize(vertex); for (int i = 0; i < vertex; i++) { dist[i] = INF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t; e.cost = cost; graph[s].push_back(e); } void warshall_floyd(ll s) { for (int i = 0; i < vertex; i++) { dist[i] = INF; } dist[s] = 0; } }; // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Mathematical Functions // ---------------------------------------------------------------- ll gcd(ll A, ll B) { if (A % B == 0) { return (B); } else { return (gcd(B, A % B)); } } ll lcm(ll A, ll B) { return A * B / gcd(A, B); } ll getDigit(ll N) { return (ll)(to_string(N).length()); } ll getDigitForBase(ll N, ll B) { if (B < 2) { return -1; } else if (B == 10) { return getDigit(N); } else { ll r = 0; while (N != 0) { N /= B; r++; } return r; } } ll getDivTimes(ll N, ll D) { ll r = 0; while (N % D == 0) { N /= D; r++; } return r; } ll powMod(ll B, ll P) { if (P == 0) return 1; if (P % 2 == 0) { ll t = powMod(B, P / 2); return t * t % MOD; } return B * powMod(B, P - 1) % MOD; } /* ---------------------------------- Factorial, Permutation, Combination ---------------------------------- */ const int FAC_INIT_SIZE = 1e6 + 9; vector<ll> fac, finv, inv; void factModInit() { fac.resize(FAC_INIT_SIZE); finv.resize(FAC_INIT_SIZE); inv.resize(FAC_INIT_SIZE); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < FAC_INIT_SIZE; 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 factMod(ll N) { return fac[N] % MOD; } ll factInvMod(ll N) { return finv[N] % MOD; } ll permMod(ll N, ll K) { if (N < 0 || K < 0 || N < K) return 0; else return factMod(N) * factInvMod(N - K) % MOD; } ll combMod(ll N, ll K) { if (N < 0 || K < 0 || N < K) return 0; else if (N < FAC_INIT_SIZE) { return factMod(N) * (factInvMod(K) * factInvMod(N - K) % MOD) % MOD; } else { ll ans = 1; ll Ks = K < N - K ? K : N - K; for (ll i = N; i > N - Ks; i--) { ans *= i; ans %= MOD; } return ans * factInvMod(Ks) % MOD; } } /* ---------------------------------- Sieve of Atkin & Bernstein ---------------------------------- */ vector<bool> sieve; void sieveInit(ll size) { sieve.clear(); if (size < 0 || size > INF) return; int ss = (int)size + 9; int ssq = sqrt(ss + 0.1); sieve.resize(ss); sieve[2] = sieve[3] = true; int n = 0; for (int z = 1; z <= 5; z += 4) { for (int y = z; y <= ssq; y += 6) { for (int x = 1; x <= ssq && (n = 4 * x * x + y * y) < ss; x++) sieve[n] = !sieve[n]; for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2) sieve[n] = !sieve[n]; } } for (int z = 2; z <= 4; z += 2) { for (int y = z; y <= ssq; y += 6) { for (int x = 1; x <= ssq && (n = 3 * x * x + y * y) < ss; x += 2) sieve[n] = !sieve[n]; for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2) sieve[n] = !sieve[n]; } } for (int z = 1; z <= 2; z++) { for (int y = 3; y <= ssq; y += 6) { for (int x = z; x <= ssq && (n = 4 * x * x + y * y) < ss; x += 3) sieve[n] = !sieve[n]; } } for (int k = 5; k <= ssq; k++) if (sieve[k]) for (int n = k * k; n < ss; n += k * k) sieve[n] = false; } /* ---------------------------------- Prime Factorization ---------------------------------- */ map<ll, map<ll, ll>> primeFactorMap; map<ll, set<ll>> primeFactorSet; void primeFactorizeInit() { primeFactorMap.clear(); primeFactorSet.clear(); } void primeFactorize(ll N) { if (N < 0 || N > INF_L) return; ll Nc = N, Nsq = sqrt(N + 0.1); for (int k = 2; k <= Nsq; k++) { ll dt = 0; while (Nc % k == 0) { dt++; Nc /= k; } if (dt > 0) primeFactorMap[N][k] = dt; if (N % k == 0) { primeFactorSet[N].insert(k); primeFactorSet[N].insert(N / k); } } if (Nc != 1) primeFactorMap[N][Nc] = 1; primeFactorSet[N].insert(1); primeFactorSet[N].insert(N); } // ---------------------------------------------------------------- //* **************** GLOBAL VARIABLES **************** *// int H, W; int Ch, Cw; int Dh, Dw; vector<string> S; //* **************************************************** *// void input() { cin >> H >> W; cin >> Ch >> Cw; Ch--; Cw--; cin >> Dh >> Dw; Dh--; Dw--; S.resize(H); rep(i, H) cin >> S[i]; } void solve() { graph_list g(H * W); rep(h, H) { rep(w, W) { if (S[h][w] == '#') continue; int ghw = h * H + w; repm(dh, -2, 3) { repm(dw, -2, 3) { int nh = h + dh, nw = w + dw; int gdhw = nh * H + nw; if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (S[nh][nw] == '#') continue; if (abs(dh) + abs(dw) == 0) continue; if (abs(dh) + abs(dw) == 1) g.add_edge(ghw, gdhw, 0); if (abs(dh) + abs(dw) > 1) g.add_edge(ghw, gdhw, 1); } } } } // g.dijkstra(Ch * H + Cw); // coi(g.dist[Dh * H + Dw] == INF_L ? -1 : g.dist[Dh * H + Dw]); vector<vector<int>> SD(H, vector<int>(W, INF)); SD[Ch][Cw] = 0; int dh[4] = {1, 0, -1, 0}; int dw[4] = {0, 1, 0, -1}; deque<Pii> deq; deq.push_back(make_pair(Ch, Cw)); while (!deq.empty()) { int nh = deq.back().first; int nw = deq.back().second; int nd = SD[nh][nw]; deq.pop_back(); rep(i, 4) { int nnh = nh + dh[i]; int nnw = nw + dw[i]; if (nnh < 0 || nnh >= H || nnw < 0 || nnw >= W) continue; else if (S[nnh][nnw] == '#') continue; else if (SD[nnh][nnw] <= nd) continue; else { SD[nnh][nnw] = nd; deq.push_back(make_pair(nnh, nnw)); } } repm(i, -2, 3) { repm(j, -2, 3) { int nnh = nh + i; int nnw = nw + j; if (nnh < 0 || nnh >= H || nnw < 0 || nnw >= W) continue; else if (S[nnh][nnw] == '#') continue; else if (SD[nnh][nnw] <= nd + 1) continue; else { SD[nnh][nnw] = nd + 1; deq.push_front(make_pair(nnh, nnw)); } } } } cout << (SD[Dh][Dw] == INF ? -1 : SD[Dh][Dw]) << endl; } int main() { std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); input(); solve(); return 0; }
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> Pii; typedef pair<int, ll> Pil; typedef pair<ll, ll> Pll; typedef pair<int, ld> Pid; typedef pair<int, string> Pis; #define rep(i, n) for (int i = 0; i < n; i++) #define repm(i, s, n) for (int i = s; i < n; i++) #define all(a) (a).begin(), (a).end() const int INF = 1 << 30; const ll INF_L = 1LL << 60; const int MOD = 1e9 + 7; // 998244353; void coi(ll i) { cout << i << endl; } void cois(ll i) { cout << i << " "; } void cod(ld d) { cout << fixed << setprecision(16); cout << d << endl; } void cods(ld d) { cout << fixed << setprecision(16); cout << d << " "; } void coc(char c) { cout << c << endl; } void cocs(char c) { cout << c << " "; } void cos(string s) { cout << s << endl; } void coss(string s) { cout << s << " "; } void coynl(bool b) { cos(b ? "Yes" : "No"); } void coYNU(bool b) { cos(b ? "YES" : "NO"); } // ---------------------------------------------------------------- // String Functions // ---------------------------------------------------------------- int ctoi(char c) { if (isdigit(c)) return c - '0'; else if (islower(c)) return c - 'a'; else if (isupper(c)) return c - 'A'; else return -1; } char itocd(int i) { char c = i + '0'; if (isdigit(c)) return c; else return 0x00; } char itocl(int i) { char c = i + 'a'; if (islower(c)) return c; else return 0x00; } char itocu(int i) { char c = i + 'A'; if (isupper(c)) return c; else return 0x00; } // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Dynamical Programming // ---------------------------------------------------------------- template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Graph Theory // ---------------------------------------------------------------- struct edge { ll to, cost; }; struct graph_list { ll V; vector<vector<edge>> graph; vector<ll> dist; graph_list(ll n) { init(n); } void init(ll n) { V = n; graph.resize(V); dist.resize(V); for (int i = 0; i < V; i++) { dist[i] = INF_L; } } void add_edge(ll from, ll to, ll cost) { edge e; e.to = to; e.cost = cost; graph[from].push_back(e); } void dijkstra(ll s) { for (int i = 0; i < V; i++) { dist[i] = INF_L; } dist[s] = 0; priority_queue<Pll, vector<Pll>, greater<Pll>> que; que.push(Pll(0, s)); while (!que.empty()) { Pll p = que.top(); que.pop(); ll v = p.second; if (dist[v] < p.first) continue; for (auto e : graph[v]) { if (dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; que.push(Pll(dist[e.to], e.to)); } } } } void bellman_ford(ll s) { for (int i = 0; i < V; i++) { dist[i] = INF_L; } dist[s] = 0; } }; struct graph_matrix { ll vertex; vector<vector<edge>> graph; vector<ll> dist; graph_matrix(ll n) { init(n); } void init(ll n) { vertex = n; graph.resize(vertex); dist.resize(vertex); for (int i = 0; i < vertex; i++) { dist[i] = INF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t; e.cost = cost; graph[s].push_back(e); } void warshall_floyd(ll s) { for (int i = 0; i < vertex; i++) { dist[i] = INF; } dist[s] = 0; } }; // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Mathematical Functions // ---------------------------------------------------------------- ll gcd(ll A, ll B) { if (A % B == 0) { return (B); } else { return (gcd(B, A % B)); } } ll lcm(ll A, ll B) { return A * B / gcd(A, B); } ll getDigit(ll N) { return (ll)(to_string(N).length()); } ll getDigitForBase(ll N, ll B) { if (B < 2) { return -1; } else if (B == 10) { return getDigit(N); } else { ll r = 0; while (N != 0) { N /= B; r++; } return r; } } ll getDivTimes(ll N, ll D) { ll r = 0; while (N % D == 0) { N /= D; r++; } return r; } ll powMod(ll B, ll P) { if (P == 0) return 1; if (P % 2 == 0) { ll t = powMod(B, P / 2); return t * t % MOD; } return B * powMod(B, P - 1) % MOD; } /* ---------------------------------- Factorial, Permutation, Combination ---------------------------------- */ const int FAC_INIT_SIZE = 1e6 + 9; vector<ll> fac, finv, inv; void factModInit() { fac.resize(FAC_INIT_SIZE); finv.resize(FAC_INIT_SIZE); inv.resize(FAC_INIT_SIZE); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < FAC_INIT_SIZE; 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 factMod(ll N) { return fac[N] % MOD; } ll factInvMod(ll N) { return finv[N] % MOD; } ll permMod(ll N, ll K) { if (N < 0 || K < 0 || N < K) return 0; else return factMod(N) * factInvMod(N - K) % MOD; } ll combMod(ll N, ll K) { if (N < 0 || K < 0 || N < K) return 0; else if (N < FAC_INIT_SIZE) { return factMod(N) * (factInvMod(K) * factInvMod(N - K) % MOD) % MOD; } else { ll ans = 1; ll Ks = K < N - K ? K : N - K; for (ll i = N; i > N - Ks; i--) { ans *= i; ans %= MOD; } return ans * factInvMod(Ks) % MOD; } } /* ---------------------------------- Sieve of Atkin & Bernstein ---------------------------------- */ vector<bool> sieve; void sieveInit(ll size) { sieve.clear(); if (size < 0 || size > INF) return; int ss = (int)size + 9; int ssq = sqrt(ss + 0.1); sieve.resize(ss); sieve[2] = sieve[3] = true; int n = 0; for (int z = 1; z <= 5; z += 4) { for (int y = z; y <= ssq; y += 6) { for (int x = 1; x <= ssq && (n = 4 * x * x + y * y) < ss; x++) sieve[n] = !sieve[n]; for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2) sieve[n] = !sieve[n]; } } for (int z = 2; z <= 4; z += 2) { for (int y = z; y <= ssq; y += 6) { for (int x = 1; x <= ssq && (n = 3 * x * x + y * y) < ss; x += 2) sieve[n] = !sieve[n]; for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2) sieve[n] = !sieve[n]; } } for (int z = 1; z <= 2; z++) { for (int y = 3; y <= ssq; y += 6) { for (int x = z; x <= ssq && (n = 4 * x * x + y * y) < ss; x += 3) sieve[n] = !sieve[n]; } } for (int k = 5; k <= ssq; k++) if (sieve[k]) for (int n = k * k; n < ss; n += k * k) sieve[n] = false; } /* ---------------------------------- Prime Factorization ---------------------------------- */ map<ll, map<ll, ll>> primeFactorMap; map<ll, set<ll>> primeFactorSet; void primeFactorizeInit() { primeFactorMap.clear(); primeFactorSet.clear(); } void primeFactorize(ll N) { if (N < 0 || N > INF_L) return; ll Nc = N, Nsq = sqrt(N + 0.1); for (int k = 2; k <= Nsq; k++) { ll dt = 0; while (Nc % k == 0) { dt++; Nc /= k; } if (dt > 0) primeFactorMap[N][k] = dt; if (N % k == 0) { primeFactorSet[N].insert(k); primeFactorSet[N].insert(N / k); } } if (Nc != 1) primeFactorMap[N][Nc] = 1; primeFactorSet[N].insert(1); primeFactorSet[N].insert(N); } // ---------------------------------------------------------------- //* **************** GLOBAL VARIABLES **************** *// int H, W; int Ch, Cw; int Dh, Dw; vector<string> S; //* **************************************************** *// void input() { cin >> H >> W; cin >> Ch >> Cw; Ch--; Cw--; cin >> Dh >> Dw; Dh--; Dw--; S.resize(H); rep(i, H) cin >> S[i]; } void solve() { graph_list g(H * W); rep(h, H) { rep(w, W) { if (S[h][w] == '#') continue; int ghw = h * H + w; repm(dh, -2, 3) { repm(dw, -2, 3) { int nh = h + dh, nw = w + dw; int gdhw = nh * H + nw; if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (S[nh][nw] == '#') continue; if (abs(dh) + abs(dw) == 0) continue; // if(abs(dh) + abs(dw) == 1) g.add_edge(ghw, gdhw, 0); // if(abs(dh) + abs(dw) > 1) g.add_edge(ghw, gdhw, 1); } } } } // g.dijkstra(Ch * H + Cw); // coi(g.dist[Dh * H + Dw] == INF_L ? -1 : g.dist[Dh * H + Dw]); vector<vector<int>> SD(H, vector<int>(W, INF)); SD[Ch][Cw] = 0; int dh[4] = {1, 0, -1, 0}; int dw[4] = {0, 1, 0, -1}; deque<Pii> deq; deq.push_back(make_pair(Ch, Cw)); while (!deq.empty()) { int nh = deq.back().first; int nw = deq.back().second; int nd = SD[nh][nw]; deq.pop_back(); rep(i, 4) { int nnh = nh + dh[i]; int nnw = nw + dw[i]; if (nnh < 0 || nnh >= H || nnw < 0 || nnw >= W) continue; else if (S[nnh][nnw] == '#') continue; else if (SD[nnh][nnw] <= nd) continue; else { SD[nnh][nnw] = nd; deq.push_back(make_pair(nnh, nnw)); } } repm(i, -2, 3) { repm(j, -2, 3) { int nnh = nh + i; int nnw = nw + j; if (nnh < 0 || nnh >= H || nnw < 0 || nnw >= W) continue; else if (S[nnh][nnw] == '#') continue; else if (SD[nnh][nnw] <= nd + 1) continue; else { SD[nnh][nnw] = nd + 1; deq.push_front(make_pair(nnh, nnw)); } } } } cout << (SD[Dh][Dw] == INF ? -1 : SD[Dh][Dw]) << endl; } int main() { std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); input(); solve(); return 0; }
replace
405
409
405
407
0
p02579
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> Pii; typedef pair<int, ll> Pil; typedef pair<ll, ll> Pll; typedef pair<int, ld> Pid; typedef pair<int, string> Pis; #define rep(i, n) for (int i = 0; i < n; i++) #define repm(i, s, n) for (int i = s; i < n; i++) #define all(a) (a).begin(), (a).end() const int INF = 1 << 30; const ll INF_L = 1LL << 60; const int MOD = 1e9 + 7; // 998244353; void coi(ll i) { cout << i << endl; } void cois(ll i) { cout << i << " "; } void cod(ld d) { cout << fixed << setprecision(16); cout << d << endl; } void cods(ld d) { cout << fixed << setprecision(16); cout << d << " "; } void coc(char c) { cout << c << endl; } void cocs(char c) { cout << c << " "; } void cos(string s) { cout << s << endl; } void coss(string s) { cout << s << " "; } void coynl(bool b) { cos(b ? "Yes" : "No"); } void coYNU(bool b) { cos(b ? "YES" : "NO"); } // ---------------------------------------------------------------- // String Functions // ---------------------------------------------------------------- int ctoi(char c) { if (isdigit(c)) return c - '0'; else if (islower(c)) return c - 'a'; else if (isupper(c)) return c - 'A'; else return -1; } char itocd(int i) { char c = i + '0'; if (isdigit(c)) return c; else return 0x00; } char itocl(int i) { char c = i + 'a'; if (islower(c)) return c; else return 0x00; } char itocu(int i) { char c = i + 'A'; if (isupper(c)) return c; else return 0x00; } // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Dynamical Programming // ---------------------------------------------------------------- template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Graph Theory // ---------------------------------------------------------------- struct edge { ll to, cost; }; struct graph_list { ll V; vector<vector<edge>> graph; vector<ll> dist; graph_list(ll n) { init(n); } void init(ll n) { V = n; graph.resize(V); dist.resize(V); for (int i = 0; i < V; i++) { dist[i] = INF_L; } } void add_edge(ll from, ll to, ll cost) { edge e; e.to = to; e.cost = cost; graph[from].push_back(e); } void dijkstra(ll s) { for (int i = 0; i < V; i++) { dist[i] = INF_L; } dist[s] = 0; priority_queue<Pll, vector<Pll>, greater<Pll>> que; que.push(Pll(0, s)); while (!que.empty()) { Pll p = que.top(); que.pop(); ll v = p.second; if (dist[v] < p.first) continue; for (auto e : graph[v]) { if (dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; que.push(Pll(dist[e.to], e.to)); } } } } void bellman_ford(ll s) { for (int i = 0; i < V; i++) { dist[i] = INF_L; } dist[s] = 0; } }; struct graph_matrix { ll vertex; vector<vector<edge>> graph; vector<ll> dist; graph_matrix(ll n) { init(n); } void init(ll n) { vertex = n; graph.resize(vertex); dist.resize(vertex); for (int i = 0; i < vertex; i++) { dist[i] = INF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t; e.cost = cost; graph[s].push_back(e); } void warshall_floyd(ll s) { for (int i = 0; i < vertex; i++) { dist[i] = INF; } dist[s] = 0; } }; // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Mathematical Functions // ---------------------------------------------------------------- ll gcd(ll A, ll B) { if (A % B == 0) { return (B); } else { return (gcd(B, A % B)); } } ll lcm(ll A, ll B) { return A * B / gcd(A, B); } ll getDigit(ll N) { return (ll)(to_string(N).length()); } ll getDigitForBase(ll N, ll B) { if (B < 2) { return -1; } else if (B == 10) { return getDigit(N); } else { ll r = 0; while (N != 0) { N /= B; r++; } return r; } } ll getDivTimes(ll N, ll D) { ll r = 0; while (N % D == 0) { N /= D; r++; } return r; } ll powMod(ll B, ll P) { if (P == 0) return 1; if (P % 2 == 0) { ll t = powMod(B, P / 2); return t * t % MOD; } return B * powMod(B, P - 1) % MOD; } /* ---------------------------------- Factorial, Permutation, Combination ---------------------------------- */ const int FAC_INIT_SIZE = 1e6 + 9; vector<ll> fac, finv, inv; void factModInit() { fac.resize(FAC_INIT_SIZE); finv.resize(FAC_INIT_SIZE); inv.resize(FAC_INIT_SIZE); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < FAC_INIT_SIZE; 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 factMod(ll N) { return fac[N] % MOD; } ll factInvMod(ll N) { return finv[N] % MOD; } ll permMod(ll N, ll K) { if (N < 0 || K < 0 || N < K) return 0; else return factMod(N) * factInvMod(N - K) % MOD; } ll combMod(ll N, ll K) { if (N < 0 || K < 0 || N < K) return 0; else if (N < FAC_INIT_SIZE) { return factMod(N) * (factInvMod(K) * factInvMod(N - K) % MOD) % MOD; } else { ll ans = 1; ll Ks = K < N - K ? K : N - K; for (ll i = N; i > N - Ks; i--) { ans *= i; ans %= MOD; } return ans * factInvMod(Ks) % MOD; } } /* ---------------------------------- Sieve of Atkin & Bernstein ---------------------------------- */ vector<bool> sieve; void sieveInit(ll size) { sieve.clear(); if (size < 0 || size > INF) return; int ss = (int)size + 9; int ssq = sqrt(ss + 0.1); sieve.resize(ss); sieve[2] = sieve[3] = true; int n = 0; for (int z = 1; z <= 5; z += 4) { for (int y = z; y <= ssq; y += 6) { for (int x = 1; x <= ssq && (n = 4 * x * x + y * y) < ss; x++) sieve[n] = !sieve[n]; for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2) sieve[n] = !sieve[n]; } } for (int z = 2; z <= 4; z += 2) { for (int y = z; y <= ssq; y += 6) { for (int x = 1; x <= ssq && (n = 3 * x * x + y * y) < ss; x += 2) sieve[n] = !sieve[n]; for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2) sieve[n] = !sieve[n]; } } for (int z = 1; z <= 2; z++) { for (int y = 3; y <= ssq; y += 6) { for (int x = z; x <= ssq && (n = 4 * x * x + y * y) < ss; x += 3) sieve[n] = !sieve[n]; } } for (int k = 5; k <= ssq; k++) if (sieve[k]) for (int n = k * k; n < ss; n += k * k) sieve[n] = false; } /* ---------------------------------- Prime Factorization ---------------------------------- */ map<ll, map<ll, ll>> primeFactorMap; map<ll, set<ll>> primeFactorSet; void primeFactorizeInit() { primeFactorMap.clear(); primeFactorSet.clear(); } void primeFactorize(ll N) { if (N < 0 || N > INF_L) return; ll Nc = N, Nsq = sqrt(N + 0.1); for (int k = 2; k <= Nsq; k++) { ll dt = 0; while (Nc % k == 0) { dt++; Nc /= k; } if (dt > 0) primeFactorMap[N][k] = dt; if (N % k == 0) { primeFactorSet[N].insert(k); primeFactorSet[N].insert(N / k); } } if (Nc != 1) primeFactorMap[N][Nc] = 1; primeFactorSet[N].insert(1); primeFactorSet[N].insert(N); } // ---------------------------------------------------------------- //* **************** GLOBAL VARIABLES **************** *// int H, W; int Ch, Cw; int Dh, Dw; vector<string> S; //* **************************************************** *// void input() { cin >> H >> W; cin >> Ch >> Cw; Ch--; Cw--; cin >> Dh >> Dw; Dh--; Dw--; S.resize(H); rep(i, H) cin >> S[i]; } void solve() { graph_list g(H * W); rep(h, H) { rep(w, W) { if (S[h][w] == '#') continue; int ghw = h * H + w; if (h != 0) g.add_edge(ghw, ghw, 0); repm(dh, -2, 3) { repm(dw, -2, 3) { int nh = h + dh, nw = w + dw; int gdhw = nh * H + nw; if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (S[nh][nw] == '#') continue; if (abs(dh) + abs(dw) == 0) continue; // if(abs(dh) + abs(dw) == 1) g.add_edge(ghw, gdhw, // 0); if(abs(dh) + abs(dw) > 1) g.add_edge(ghw, // gdhw, 1); } } } } // g.dijkstra(Ch * H + Cw); // coi(g.dist[Dh * H + Dw] == INF_L ? -1 : g.dist[Dh * H + Dw]); vector<vector<int>> SD(H, vector<int>(W, INF)); SD[Ch][Cw] = 0; int dh[4] = {1, 0, -1, 0}; int dw[4] = {0, 1, 0, -1}; deque<Pii> deq; deq.push_back(make_pair(Ch, Cw)); while (!deq.empty()) { int nh = deq.back().first; int nw = deq.back().second; int nd = SD[nh][nw]; deq.pop_back(); rep(i, 4) { int nnh = nh + dh[i]; int nnw = nw + dw[i]; if (nnh < 0 || nnh >= H || nnw < 0 || nnw >= W) continue; else if (S[nnh][nnw] == '#') continue; else if (SD[nnh][nnw] <= nd) continue; else { SD[nnh][nnw] = nd; deq.push_back(make_pair(nnh, nnw)); } } repm(i, -2, 3) { repm(j, -2, 3) { int nnh = nh + i; int nnw = nw + j; if (nnh < 0 || nnh >= H || nnw < 0 || nnw >= W) continue; else if (S[nnh][nnw] == '#') continue; else if (SD[nnh][nnw] <= nd + 1) continue; else { SD[nnh][nnw] = nd + 1; deq.push_front(make_pair(nnh, nnw)); } } } } cout << (SD[Dh][Dw] == INF ? -1 : SD[Dh][Dw]) << endl; } int main() { std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); input(); solve(); return 0; }
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> Pii; typedef pair<int, ll> Pil; typedef pair<ll, ll> Pll; typedef pair<int, ld> Pid; typedef pair<int, string> Pis; #define rep(i, n) for (int i = 0; i < n; i++) #define repm(i, s, n) for (int i = s; i < n; i++) #define all(a) (a).begin(), (a).end() const int INF = 1 << 30; const ll INF_L = 1LL << 60; const int MOD = 1e9 + 7; // 998244353; void coi(ll i) { cout << i << endl; } void cois(ll i) { cout << i << " "; } void cod(ld d) { cout << fixed << setprecision(16); cout << d << endl; } void cods(ld d) { cout << fixed << setprecision(16); cout << d << " "; } void coc(char c) { cout << c << endl; } void cocs(char c) { cout << c << " "; } void cos(string s) { cout << s << endl; } void coss(string s) { cout << s << " "; } void coynl(bool b) { cos(b ? "Yes" : "No"); } void coYNU(bool b) { cos(b ? "YES" : "NO"); } // ---------------------------------------------------------------- // String Functions // ---------------------------------------------------------------- int ctoi(char c) { if (isdigit(c)) return c - '0'; else if (islower(c)) return c - 'a'; else if (isupper(c)) return c - 'A'; else return -1; } char itocd(int i) { char c = i + '0'; if (isdigit(c)) return c; else return 0x00; } char itocl(int i) { char c = i + 'a'; if (islower(c)) return c; else return 0x00; } char itocu(int i) { char c = i + 'A'; if (isupper(c)) return c; else return 0x00; } // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Dynamical Programming // ---------------------------------------------------------------- template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Graph Theory // ---------------------------------------------------------------- struct edge { ll to, cost; }; struct graph_list { ll V; vector<vector<edge>> graph; vector<ll> dist; graph_list(ll n) { init(n); } void init(ll n) { V = n; graph.resize(V); dist.resize(V); for (int i = 0; i < V; i++) { dist[i] = INF_L; } } void add_edge(ll from, ll to, ll cost) { edge e; e.to = to; e.cost = cost; graph[from].push_back(e); } void dijkstra(ll s) { for (int i = 0; i < V; i++) { dist[i] = INF_L; } dist[s] = 0; priority_queue<Pll, vector<Pll>, greater<Pll>> que; que.push(Pll(0, s)); while (!que.empty()) { Pll p = que.top(); que.pop(); ll v = p.second; if (dist[v] < p.first) continue; for (auto e : graph[v]) { if (dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; que.push(Pll(dist[e.to], e.to)); } } } } void bellman_ford(ll s) { for (int i = 0; i < V; i++) { dist[i] = INF_L; } dist[s] = 0; } }; struct graph_matrix { ll vertex; vector<vector<edge>> graph; vector<ll> dist; graph_matrix(ll n) { init(n); } void init(ll n) { vertex = n; graph.resize(vertex); dist.resize(vertex); for (int i = 0; i < vertex; i++) { dist[i] = INF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t; e.cost = cost; graph[s].push_back(e); } void warshall_floyd(ll s) { for (int i = 0; i < vertex; i++) { dist[i] = INF; } dist[s] = 0; } }; // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Mathematical Functions // ---------------------------------------------------------------- ll gcd(ll A, ll B) { if (A % B == 0) { return (B); } else { return (gcd(B, A % B)); } } ll lcm(ll A, ll B) { return A * B / gcd(A, B); } ll getDigit(ll N) { return (ll)(to_string(N).length()); } ll getDigitForBase(ll N, ll B) { if (B < 2) { return -1; } else if (B == 10) { return getDigit(N); } else { ll r = 0; while (N != 0) { N /= B; r++; } return r; } } ll getDivTimes(ll N, ll D) { ll r = 0; while (N % D == 0) { N /= D; r++; } return r; } ll powMod(ll B, ll P) { if (P == 0) return 1; if (P % 2 == 0) { ll t = powMod(B, P / 2); return t * t % MOD; } return B * powMod(B, P - 1) % MOD; } /* ---------------------------------- Factorial, Permutation, Combination ---------------------------------- */ const int FAC_INIT_SIZE = 1e6 + 9; vector<ll> fac, finv, inv; void factModInit() { fac.resize(FAC_INIT_SIZE); finv.resize(FAC_INIT_SIZE); inv.resize(FAC_INIT_SIZE); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < FAC_INIT_SIZE; 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 factMod(ll N) { return fac[N] % MOD; } ll factInvMod(ll N) { return finv[N] % MOD; } ll permMod(ll N, ll K) { if (N < 0 || K < 0 || N < K) return 0; else return factMod(N) * factInvMod(N - K) % MOD; } ll combMod(ll N, ll K) { if (N < 0 || K < 0 || N < K) return 0; else if (N < FAC_INIT_SIZE) { return factMod(N) * (factInvMod(K) * factInvMod(N - K) % MOD) % MOD; } else { ll ans = 1; ll Ks = K < N - K ? K : N - K; for (ll i = N; i > N - Ks; i--) { ans *= i; ans %= MOD; } return ans * factInvMod(Ks) % MOD; } } /* ---------------------------------- Sieve of Atkin & Bernstein ---------------------------------- */ vector<bool> sieve; void sieveInit(ll size) { sieve.clear(); if (size < 0 || size > INF) return; int ss = (int)size + 9; int ssq = sqrt(ss + 0.1); sieve.resize(ss); sieve[2] = sieve[3] = true; int n = 0; for (int z = 1; z <= 5; z += 4) { for (int y = z; y <= ssq; y += 6) { for (int x = 1; x <= ssq && (n = 4 * x * x + y * y) < ss; x++) sieve[n] = !sieve[n]; for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2) sieve[n] = !sieve[n]; } } for (int z = 2; z <= 4; z += 2) { for (int y = z; y <= ssq; y += 6) { for (int x = 1; x <= ssq && (n = 3 * x * x + y * y) < ss; x += 2) sieve[n] = !sieve[n]; for (int x = y + 1; x <= ssq && (n = 3 * x * x - y * y) < ss; x += 2) sieve[n] = !sieve[n]; } } for (int z = 1; z <= 2; z++) { for (int y = 3; y <= ssq; y += 6) { for (int x = z; x <= ssq && (n = 4 * x * x + y * y) < ss; x += 3) sieve[n] = !sieve[n]; } } for (int k = 5; k <= ssq; k++) if (sieve[k]) for (int n = k * k; n < ss; n += k * k) sieve[n] = false; } /* ---------------------------------- Prime Factorization ---------------------------------- */ map<ll, map<ll, ll>> primeFactorMap; map<ll, set<ll>> primeFactorSet; void primeFactorizeInit() { primeFactorMap.clear(); primeFactorSet.clear(); } void primeFactorize(ll N) { if (N < 0 || N > INF_L) return; ll Nc = N, Nsq = sqrt(N + 0.1); for (int k = 2; k <= Nsq; k++) { ll dt = 0; while (Nc % k == 0) { dt++; Nc /= k; } if (dt > 0) primeFactorMap[N][k] = dt; if (N % k == 0) { primeFactorSet[N].insert(k); primeFactorSet[N].insert(N / k); } } if (Nc != 1) primeFactorMap[N][Nc] = 1; primeFactorSet[N].insert(1); primeFactorSet[N].insert(N); } // ---------------------------------------------------------------- //* **************** GLOBAL VARIABLES **************** *// int H, W; int Ch, Cw; int Dh, Dw; vector<string> S; //* **************************************************** *// void input() { cin >> H >> W; cin >> Ch >> Cw; Ch--; Cw--; cin >> Dh >> Dw; Dh--; Dw--; S.resize(H); rep(i, H) cin >> S[i]; } void solve() { graph_list g(1000005); rep(h, H) { rep(w, W) { if (S[h][w] == '#') continue; int ghw = h * H + w; if (h != 0) g.add_edge(ghw, ghw, 0); repm(dh, -2, 3) { repm(dw, -2, 3) { int nh = h + dh, nw = w + dw; int gdhw = nh * H + nw; if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (S[nh][nw] == '#') continue; if (abs(dh) + abs(dw) == 0) continue; // if(abs(dh) + abs(dw) == 1) g.add_edge(ghw, gdhw, // 0); if(abs(dh) + abs(dw) > 1) g.add_edge(ghw, // gdhw, 1); } } } } // g.dijkstra(Ch * H + Cw); // coi(g.dist[Dh * H + Dw] == INF_L ? -1 : g.dist[Dh * H + Dw]); vector<vector<int>> SD(H, vector<int>(W, INF)); SD[Ch][Cw] = 0; int dh[4] = {1, 0, -1, 0}; int dw[4] = {0, 1, 0, -1}; deque<Pii> deq; deq.push_back(make_pair(Ch, Cw)); while (!deq.empty()) { int nh = deq.back().first; int nw = deq.back().second; int nd = SD[nh][nw]; deq.pop_back(); rep(i, 4) { int nnh = nh + dh[i]; int nnw = nw + dw[i]; if (nnh < 0 || nnh >= H || nnw < 0 || nnw >= W) continue; else if (S[nnh][nnw] == '#') continue; else if (SD[nnh][nnw] <= nd) continue; else { SD[nnh][nnw] = nd; deq.push_back(make_pair(nnh, nnw)); } } repm(i, -2, 3) { repm(j, -2, 3) { int nnh = nh + i; int nnw = nw + j; if (nnh < 0 || nnh >= H || nnw < 0 || nnw >= W) continue; else if (S[nnh][nnw] == '#') continue; else if (SD[nnh][nnw] <= nd + 1) continue; else { SD[nnh][nnw] = nd + 1; deq.push_front(make_pair(nnh, nnw)); } } } } cout << (SD[Dh][Dw] == INF ? -1 : SD[Dh][Dw]) << endl; } int main() { std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); input(); solve(); return 0; }
replace
389
390
389
390
0
p02580
C++
Runtime Error
#include "bits/stdc++.h" #define rep(i, j) for (int i = 0; i < j; i++) #define srep(i, j, k) for (int i = j; i < k; i++) using namespace std; using ll = long long; using P = pair<int, int>; using ull = unsigned long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } // エラトステネスの篩 vector<int> estora(vector<int> num) { int sel = 0; while (sel < num.size()) { int d = num[sel]; for (int i = 0; i < num.size(); i++) { if (num[i] % d == 0 && num[i] != d && d != 1) { num.erase(num.begin() + i); i--; } } sel++; } return num; } /*ライブラリ最大公約数*/ // ユーグリッドの互除法 int gcd(int x, int y) { int num[3]; num[0] = (x > y) ? x : y; num[1] = (x <= y) ? x : y; num[2] = num[0] % num[1]; while (num[2]) { num[0] = num[1]; num[1] = num[2]; num[2] = num[0] % num[1]; } return num[1]; } /*素因数分解*/ // 自作ライブラリ // iを常に素数にしておかないとうまくできない&&計算量ヤバイ // エストラネスの篩で素数を振るっておく必要性がありそう vector<ll> fac(ll n, vector<ll> num) { ll kazu = n; for (int i = 2; i <= n; i++) { while (1) { if (kazu % i != 0) break; kazu /= i; num[i]++; } } if (kazu == n && n != 1) num[n]++; return num; int ans = 0; if (kazu != 1) ans++; for (int i = 2; i <= sqrt(n); i++) { for (int j = 1; j <= num[i]; j++) { num[i] -= j; ans++; } } return num; } const int INF = 1001001001; // mint用の定数 (10の9乗 + 7) const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } int main() { int h, w, m; cin >> h >> w >> m; vector<int> dh(h), dw(w); set<P> abe; rep(i, m) { int n1, n2; cin >> n1 >> n2; n1--; n2--; dh[n1]++; dh[n2]++; abe.emplace(n1, n2); } int mh = 0, mw = 0; rep(i, h) mh = max(mh, dh[i]); rep(i, w) mw = max(mw, dw[i]); vector<int> is, js; rep(i, h) if (mh == dh[i]) is.emplace_back(i); rep(i, w) if (mw == dw[i]) js.emplace_back(i); int ans = mh + mw; for (int i : is) for (int j : js) { if (abe.count(P(i, j))) continue; cout << ans; return 0; } ans--; cout << ans << endl; ; return 0; }
#include "bits/stdc++.h" #define rep(i, j) for (int i = 0; i < j; i++) #define srep(i, j, k) for (int i = j; i < k; i++) using namespace std; using ll = long long; using P = pair<int, int>; using ull = unsigned long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } // エラトステネスの篩 vector<int> estora(vector<int> num) { int sel = 0; while (sel < num.size()) { int d = num[sel]; for (int i = 0; i < num.size(); i++) { if (num[i] % d == 0 && num[i] != d && d != 1) { num.erase(num.begin() + i); i--; } } sel++; } return num; } /*ライブラリ最大公約数*/ // ユーグリッドの互除法 int gcd(int x, int y) { int num[3]; num[0] = (x > y) ? x : y; num[1] = (x <= y) ? x : y; num[2] = num[0] % num[1]; while (num[2]) { num[0] = num[1]; num[1] = num[2]; num[2] = num[0] % num[1]; } return num[1]; } /*素因数分解*/ // 自作ライブラリ // iを常に素数にしておかないとうまくできない&&計算量ヤバイ // エストラネスの篩で素数を振るっておく必要性がありそう vector<ll> fac(ll n, vector<ll> num) { ll kazu = n; for (int i = 2; i <= n; i++) { while (1) { if (kazu % i != 0) break; kazu /= i; num[i]++; } } if (kazu == n && n != 1) num[n]++; return num; int ans = 0; if (kazu != 1) ans++; for (int i = 2; i <= sqrt(n); i++) { for (int j = 1; j <= num[i]; j++) { num[i] -= j; ans++; } } return num; } const int INF = 1001001001; // mint用の定数 (10の9乗 + 7) const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } int main() { int h, w, m; cin >> h >> w >> m; vector<int> dh(h), dw(w); set<P> abe; rep(i, m) { int n1, n2; cin >> n1 >> n2; n1--; n2--; dh[n1]++; dw[n2]++; abe.emplace(n1, n2); } int mh = 0, mw = 0; rep(i, h) mh = max(mh, dh[i]); rep(i, w) mw = max(mw, dw[i]); vector<int> is, js; rep(i, h) if (mh == dh[i]) is.emplace_back(i); rep(i, w) if (mw == dw[i]) js.emplace_back(i); int ans = mh + mw; for (int i : is) for (int j : js) { if (abe.count(P(i, j))) continue; cout << ans; return 0; } ans--; cout << ans << endl; ; return 0; }
replace
139
140
139
140
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define endl "\n" #define pb push_back #define mp make_pair #define F first #define S second #define int long long int #define pll pair<int, int> #define ALL(v) v.begin(), v.end() #define ALLR(v) v.rbegin(), v.rend() #define pii 3.14159265358979323 #define inf LLONG_MAX #define ones(x) __builtin_popcount(x) #define fill(a, b) memset(a, b, sizeof(a)) #define mod 1000000007 #define hell 998244353 ll mod_pow(ll a, ll b, ll m) { ll res = 1; while (b) { if (b & 1) { res = (res * a) % m; } a = (a * a) % m; b >>= 1; } return res; } ll mod_inverse(ll a) { return mod_pow(a, mod - 2, mod); } struct CustomCompare { bool operator()(const pair<int, int> &l, const pair<int, int> &r) { return l.S < r.S; } }; void solve() { int n, m, p; cin >> n >> m >> p; vector<pair<int, int>> a(p); for (int i = 0; i < p; ++i) { cin >> a[i].F >> a[i].S; } sort(ALL(a)); map<int, int> f; multiset<int> mt; for (int i = 0; i < p; ++i) { f[a[i].S]++; } for (auto u : f) { mt.insert(u.S); } int mx = 0; for (int i = 0; i < p; ++i) { int j = i; while (j < p && a[i].F == a[j].F) { mt.erase(mt.find(f[a[i].S])); mt.insert(f[a[i].S] - 1); j++; } auto tm = mt.end(); tm--; mx = max(mx, j - i + (*tm)); for (int z = i; z < j; ++z) { mt.erase(mt.find(f[a[z].S] - 1)); mt.insert(f[a[z].S]); } i = j - 1; } cout << mx; } signed main() { fast; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define endl "\n" #define pb push_back #define mp make_pair #define F first #define S second #define int long long int #define pll pair<int, int> #define ALL(v) v.begin(), v.end() #define ALLR(v) v.rbegin(), v.rend() #define pii 3.14159265358979323 #define inf LLONG_MAX #define ones(x) __builtin_popcount(x) #define fill(a, b) memset(a, b, sizeof(a)) #define mod 1000000007 #define hell 998244353 ll mod_pow(ll a, ll b, ll m) { ll res = 1; while (b) { if (b & 1) { res = (res * a) % m; } a = (a * a) % m; b >>= 1; } return res; } ll mod_inverse(ll a) { return mod_pow(a, mod - 2, mod); } struct CustomCompare { bool operator()(const pair<int, int> &l, const pair<int, int> &r) { return l.S < r.S; } }; void solve() { int n, m, p; cin >> n >> m >> p; vector<pair<int, int>> a(p); for (int i = 0; i < p; ++i) { cin >> a[i].F >> a[i].S; } sort(ALL(a)); map<int, int> f; multiset<int> mt; for (int i = 0; i < p; ++i) { f[a[i].S]++; } for (auto u : f) { mt.insert(u.S); } int mx = 0; for (int i = 0; i < p; ++i) { int j = i; while (j < p && a[i].F == a[j].F) { mt.erase(mt.find(f[a[j].S])); mt.insert(f[a[j].S] - 1); j++; } auto tm = mt.end(); tm--; mx = max(mx, j - i + (*tm)); for (int z = i; z < j; ++z) { mt.erase(mt.find(f[a[z].S] - 1)); mt.insert(f[a[z].S]); } i = j - 1; } cout << mx; } signed main() { fast; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
replace
78
80
78
80
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; using Pii = pair<int, int>; using Pll = pair<ll, ll>; #define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i) #define ALL(x) (x).begin(), (x).end() #define pb push_back ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int main() { ll h, w, m; cin >> h >> w >> m; vector<Pll> H(h, Pll(0, 0)), W(w, Pll(0, 0)); map<Pll, ll> mp; REP(i, 0, h) { H[i].second = i; } REP(i, 0, w) { W[i].second = i; } REP(i, 0, m) { ll x, y; cin >> x >> y; x--; y--; H[x].first++; W[y].first++; mp[Pii(x, y)]++; } sort(ALL(H), [](auto &x, auto &y) { return x.first > y.first; }); sort(ALL(W), [](auto &x, auto &y) { return x.first > y.first; }); ll Hmax = H[0].first, Wmax = W[0].first, i = 0; // cout << Hmax << Wmax << endl; ll ans = 0; while (i < h && Hmax - H[i].first < 1) { int l = 0; while (l < w && Wmax - W[l].first < 1) { if (mp[Pii(H[i].second, W[l].second)] == 1) { chmax(ans, H[i].first + W[l].first - 1); } else { chmax(ans, H[i].first + W[l].first); } l++; } i++; } cout << ans << endl; }
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; using Pii = pair<int, int>; using Pll = pair<ll, ll>; #define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i) #define ALL(x) (x).begin(), (x).end() #define pb push_back ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int main() { ll h, w, m; cin >> h >> w >> m; vector<Pll> H(h, Pll(0, 0)), W(w, Pll(0, 0)); map<Pll, ll> mp; REP(i, 0, h) { H[i].second = i; } REP(i, 0, w) { W[i].second = i; } REP(i, 0, m) { ll x, y; cin >> x >> y; x--; y--; H[x].first++; W[y].first++; mp[Pii(x, y)]++; } sort(ALL(H), [](auto &x, auto &y) { return x.first > y.first; }); sort(ALL(W), [](auto &x, auto &y) { return x.first > y.first; }); ll Hmax = H[0].first, Wmax = W[0].first, i = 0; // cout << Hmax << Wmax << endl; ll ans = 0; while (i < h && Hmax - H[i].first < 1) { int l = 0; while (l < w && Wmax - W[l].first < 1) { if (mp[Pii(H[i].second, W[l].second)] == 1) { chmax(ans, H[i].first + W[l].first - 1); } else { cout << H[i].first + W[l].first << endl; return 0; } l++; } i++; } cout << ans << endl; }
replace
65
66
65
67
TLE
p02580
C++
Time Limit Exceeded
/** * Dont raise your voice, improve your argument. * --Desmond Tutu */ #include <bits/stdc++.h> using namespace std; const bool ready = []() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); return true; }(); const double PI = acos(-1); using ll = long long; #define int ll #define all(v) (v).begin(), (v).end() #define fori(n) for (int i = 0; i < int(n); i++) #define cini(i) \ int i; \ cin >> i; #define cins(s) \ string s; \ cin >> s; #define cind(d) \ double d; \ cin >> d; #define cinai(a, n) \ vi a(n); \ fori(n) { cin >> a[i]; } #define cinas(s, n) \ vs s(n); \ fori(n) { cin >> s[i]; } #define cinad(a, n) \ vd a(n); \ fori(n) { cin >> a[i]; } using pii = pair<int, int>; using pdd = pair<double, double>; using vd = vector<double>; using vb = vector<bool>; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; #define endl "\n" /* we want to find the * row+col with most targets in it * Somehow we need to * recognize double count the crossing. */ void solve() { cini(h); cini(w); cini(m); vector<pii> hcnt(h); for (int i = 0; i < h; i++) hcnt[i].second = i; vector<pii> wcnt(w); for (int j = 0; j < w; j++) wcnt[j].second = j; map<pii, int> s; for (int i = 0; i < m; i++) { cini(th); cini(tw); th--; tw--; s[{th, tw}]++; hcnt[th].first++; wcnt[tw].first++; } sort(all(hcnt), greater<pii>()); sort(all(wcnt), greater<pii>()); int ans = 0; for (int i = 0; i < h; i++) { if (hcnt[i].first < hcnt[0].first) break; for (int j = 0; j < w; j++) { if (wcnt[j].first < wcnt[0].first) break; int lans = hcnt[i].first + wcnt[j].first; ans = max(ans, lans - s[{hcnt[i].second, wcnt[j].second}]); } } cout << ans << endl; } signed main() { solve(); } // FIRST THINK, THEN CODE // DO NOT JUMP BETWEEN PROBLEMS
/** * Dont raise your voice, improve your argument. * --Desmond Tutu */ #include <bits/stdc++.h> using namespace std; const bool ready = []() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); return true; }(); const double PI = acos(-1); using ll = long long; #define int ll #define all(v) (v).begin(), (v).end() #define fori(n) for (int i = 0; i < int(n); i++) #define cini(i) \ int i; \ cin >> i; #define cins(s) \ string s; \ cin >> s; #define cind(d) \ double d; \ cin >> d; #define cinai(a, n) \ vi a(n); \ fori(n) { cin >> a[i]; } #define cinas(s, n) \ vs s(n); \ fori(n) { cin >> s[i]; } #define cinad(a, n) \ vd a(n); \ fori(n) { cin >> a[i]; } using pii = pair<int, int>; using pdd = pair<double, double>; using vd = vector<double>; using vb = vector<bool>; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; #define endl "\n" /* we want to find the * row+col with most targets in it * Somehow we need to * recognize double count the crossing. */ void solve() { cini(h); cini(w); cini(m); vector<pii> hcnt(h); for (int i = 0; i < h; i++) hcnt[i].second = i; vector<pii> wcnt(w); for (int j = 0; j < w; j++) wcnt[j].second = j; map<pii, int> s; for (int i = 0; i < m; i++) { cini(th); cini(tw); th--; tw--; s[{th, tw}]++; hcnt[th].first++; wcnt[tw].first++; } sort(all(hcnt), greater<pii>()); sort(all(wcnt), greater<pii>()); int ans = 0; for (int i = 0; i < h; i++) { if (hcnt[i].first < hcnt[0].first) break; for (int j = 0; j < w; j++) { if (wcnt[j].first < wcnt[0].first) break; int lans = hcnt[i].first + wcnt[j].first; int dec = s[{hcnt[i].second, wcnt[j].second}]; ans = max(ans, lans - dec); if (dec == 0) break; } } cout << ans << endl; } signed main() { solve(); } // FIRST THINK, THEN CODE // DO NOT JUMP BETWEEN PROBLEMS
replace
91
92
91
95
TLE
p02580
C++
Runtime Error
/// mAAria... #include <bits/stdc++.h> using namespace std; #define int long long #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define all(v) v.begin(), v.end() #define allr(v) v.begin(), v.end() #define ld long double #define ff first #define ss second #define pb push_back #define pii pair<int, int> #define pi 3.1415926535897932384626433832 #define mod 1000000007 // #define mod 998244353 #define inf 1000000000 #define pr1(a) cout << a << endl #define pr2(a, b) cout << a << " " << b << endl #define pr3(a, b, c) cout << a << " " << b << " " << c << endl const long double PI = acos(-1); int powm(int a, int b) { int res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } bool power_of_two(int n) { return ((n & (n - 1)) == 0); } void solve() { int r, c, ans = 0; cin >> r >> c; int m; cin >> m; vector<int> adj[r + 1]; vector<int> row(r + 1, 0); vector<int> col(c + 1, 0); for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; adj[x].pb(y); row[x]++; col[y]++; } set<pii> col_cnt; for (int j = 1; j <= c; j++) { col_cnt.insert({col[j], j}); } for (int i = 1; i <= r; i++) { for (auto j : adj[i]) { if (col_cnt.find({col[j], j}) != col_cnt.end()) col_cnt.erase(col_cnt.find({col[j], j})); col[j]--; col_cnt.insert({col[j], j}); } auto it = col_cnt.end(); if (it != col_cnt.begin()) it--; ans = max(ans, row[i] + (*it).ff); for (auto j : adj[i]) { col_cnt.erase(col_cnt.find({col[j], j})); col[j]++; col_cnt.insert({col[j], j}); } } cout << ans << endl; } signed main() { IOS; int t = 1; cin >> t; for (int i = 1; i <= t; i++) { solve(); } return 0; }
/// mAAria... #include <bits/stdc++.h> using namespace std; #define int long long #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define all(v) v.begin(), v.end() #define allr(v) v.begin(), v.end() #define ld long double #define ff first #define ss second #define pb push_back #define pii pair<int, int> #define pi 3.1415926535897932384626433832 #define mod 1000000007 // #define mod 998244353 #define inf 1000000000 #define pr1(a) cout << a << endl #define pr2(a, b) cout << a << " " << b << endl #define pr3(a, b, c) cout << a << " " << b << " " << c << endl const long double PI = acos(-1); int powm(int a, int b) { int res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } bool power_of_two(int n) { return ((n & (n - 1)) == 0); } void solve() { int r, c, ans = 0; cin >> r >> c; int m; cin >> m; vector<int> adj[r + 1]; vector<int> row(r + 1, 0); vector<int> col(c + 1, 0); for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; adj[x].pb(y); row[x]++; col[y]++; } set<pii> col_cnt; for (int j = 1; j <= c; j++) { col_cnt.insert({col[j], j}); } for (int i = 1; i <= r; i++) { for (auto j : adj[i]) { if (col_cnt.find({col[j], j}) != col_cnt.end()) col_cnt.erase(col_cnt.find({col[j], j})); col[j]--; col_cnt.insert({col[j], j}); } auto it = col_cnt.end(); if (it != col_cnt.begin()) it--; ans = max(ans, row[i] + (*it).ff); for (auto j : adj[i]) { col_cnt.erase(col_cnt.find({col[j], j})); col[j]++; col_cnt.insert({col[j], j}); } } cout << ans << endl; } signed main() { IOS; int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { solve(); } return 0; }
replace
99
100
99
100
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for (int i = 0; i < (a); i++) typedef pair<int, int> P; typedef long long ll; const int INF = 1001001001; const int MOD = 1000000007; const double PI = acos(-1); int main() { int H, W, M; cin >> H >> W >> M; set<pair<int, int>> S; vector<vector<int>> Aw(W, vector<int>(2, 0)); vector<vector<int>> Ah(H, vector<int>(2, 0)); rep(i, W) { Aw[i][1] = i; } rep(i, H) { Ah[i][1] = i; } rep(i, M) { int h, w; cin >> h >> w; h--, w--; S.insert(make_pair(h, w)); Ah[h][0]++; Aw[w][0]++; } sort(Aw.begin(), Aw.end()); sort(Ah.begin(), Ah.end()); ll ans = 0; ll wnum = Aw.back()[0]; ll wint = Aw.back()[1]; vector<int> wmax; int idx = W - 1; while (Aw[idx][0] == wnum) { wmax.push_back(Aw[idx][1]); idx--; if (idx < 0) break; } ll hnum = Ah.back()[0]; ll hint = Ah.back()[1]; vector<int> hmax; idx = H - 1; while (Ah[idx][0] == hnum) { hmax.push_back(Ah[idx][1]); idx--; if (idx < 0) break; } int cnt = 0; rep(h, hmax.size()) { rep(w, wmax.size()) { ll tmp = hnum + wnum; // cout << hmax[h]+1 << " " << wmax[w]+1 << endl; if (S.count(make_pair(hmax[h], wmax[w]))) { tmp--; } ans = max(ans, tmp); } if (cnt > 1000000) break; if (cnt > 1000000) break; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for (int i = 0; i < (a); i++) typedef pair<int, int> P; typedef long long ll; const int INF = 1001001001; const int MOD = 1000000007; const double PI = acos(-1); int main() { int H, W, M; cin >> H >> W >> M; set<pair<int, int>> S; vector<vector<int>> Aw(W, vector<int>(2, 0)); vector<vector<int>> Ah(H, vector<int>(2, 0)); rep(i, W) { Aw[i][1] = i; } rep(i, H) { Ah[i][1] = i; } rep(i, M) { int h, w; cin >> h >> w; h--, w--; S.insert(make_pair(h, w)); Ah[h][0]++; Aw[w][0]++; } sort(Aw.begin(), Aw.end()); sort(Ah.begin(), Ah.end()); ll ans = 0; ll wnum = Aw.back()[0]; ll wint = Aw.back()[1]; vector<int> wmax; int idx = W - 1; while (Aw[idx][0] == wnum) { wmax.push_back(Aw[idx][1]); idx--; if (idx < 0) break; } ll hnum = Ah.back()[0]; ll hint = Ah.back()[1]; vector<int> hmax; idx = H - 1; while (Ah[idx][0] == hnum) { hmax.push_back(Ah[idx][1]); idx--; if (idx < 0) break; } int cnt = 0; rep(h, hmax.size()) { rep(w, wmax.size()) { ll tmp = hnum + wnum; // cout << hmax[h]+1 << " " << wmax[w]+1 << endl; if (S.count(make_pair(hmax[h], wmax[w]))) { tmp--; } ans = max(ans, tmp); cnt++; } if (cnt > 1000000) break; if (cnt > 1000000) break; } cout << ans << endl; }
insert
65
65
65
66
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll h, w, m; cin >> h >> w >> m; ll a[h][w]; for (ll i = 0; i < h; i++) for (ll j = 0; j < w; j++) { a[i][j] = 0; } set<pair<ll, ll>> s; vector<ll> mpr(300001, 0); vector<ll> mpc(300001, 0); while (m--) { ll x, y; cin >> x >> y; x--; y--; s.insert({x, y}); mpr[x]++; mpc[y]++; } ll mar = INT_MIN; ll r; for (ll i = 0; i < h; i++) { if (mpr[i] > mar) { mar = mpr[i]; r = i; } } ll mac = INT_MIN; ll c; for (ll i = 0; i < w; i++) { if (mpc[i] > mac) { mac = mpc[i]; c = i; } } ll cnt = INT_MIN; for (ll i = 0; i < h; i++) { if (s.find({i, c}) != s.end()) { cnt = max(cnt, mpr[i] + mac - 1); } else { cnt = max(cnt, mpr[i] + mac); } } for (ll i = 0; i < w; i++) { if (s.find({r, i}) != s.end()) { cnt = max(cnt, mpc[i] + mar - 1); } else { cnt = max(cnt, mpc[i] + mar); } } cout << cnt << endl; // cout<<ma<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll h, w, m; cin >> h >> w >> m; set<pair<ll, ll>> s; vector<ll> mpr(300001, 0); vector<ll> mpc(300001, 0); while (m--) { ll x, y; cin >> x >> y; x--; y--; s.insert({x, y}); mpr[x]++; mpc[y]++; } ll mar = INT_MIN; ll r; for (ll i = 0; i < h; i++) { if (mpr[i] > mar) { mar = mpr[i]; r = i; } } ll mac = INT_MIN; ll c; for (ll i = 0; i < w; i++) { if (mpc[i] > mac) { mac = mpc[i]; c = i; } } ll cnt = INT_MIN; for (ll i = 0; i < h; i++) { if (s.find({i, c}) != s.end()) { cnt = max(cnt, mpr[i] + mac - 1); } else { cnt = max(cnt, mpr[i] + mac); } } for (ll i = 0; i < w; i++) { if (s.find({r, i}) != s.end()) { cnt = max(cnt, mpc[i] + mar - 1); } else { cnt = max(cnt, mpc[i] + mar); } } cout << cnt << endl; // cout<<ma<<endl; }
replace
6
11
6
7
0
p02580
C++
Runtime Error
#include "bits/stdc++.h" #define rep(i, j) for (int i = 0; i < j; i++) #define srep(i, j, k) for (int i = j; i < k; i++) using namespace std; using ll = long long; using P = pair<int, int>; using ull = unsigned long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } // エラトステネスの篩 vector<int> estora(vector<int> num) { int sel = 0; while (sel < num.size()) { int d = num[sel]; for (int i = 0; i < num.size(); i++) { if (num[i] % d == 0 && num[i] != d && d != 1) { num.erase(num.begin() + i); i--; } } sel++; } return num; } /*ライブラリ最大公約数*/ // ユーグリッドの互除法 int gcd(int x, int y) { int num[3]; num[0] = (x > y) ? x : y; num[1] = (x <= y) ? x : y; num[2] = num[0] % num[1]; while (num[2]) { num[0] = num[1]; num[1] = num[2]; num[2] = num[0] % num[1]; } return num[1]; } /*素因数分解*/ // 自作ライブラリ // iを常に素数にしておかないとうまくできない&&計算量ヤバイ // エストラネスの篩で素数を振るっておく必要性がありそう vector<ll> fac(ll n, vector<ll> num) { ll kazu = n; for (int i = 2; i <= n; i++) { while (1) { if (kazu % i != 0) break; kazu /= i; num[i]++; } } if (kazu == n && n != 1) num[n]++; return num; int ans = 0; if (kazu != 1) ans++; for (int i = 2; i <= sqrt(n); i++) { for (int j = 1; j <= num[i]; j++) { num[i] -= j; ans++; } } return num; } const int INF = 1001001001; // mint用の定数 (10の9乗 + 7) const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } int main() { int h, w, m; cin >> h >> w >> m; vector<int> dh(h), dw(w); set<P> baku; rep(i, m) { int n1, n2; cin >> n1 >> n2; n1--; n2--; dh[n1]++; dh[n2]--; P kari = P(n1, n2); baku.insert(kari); } int mh = 0, mw = 0; rep(i, h) mh = max(mh, dh[i]); rep(i, w) mw = max(mw, dw[i]); vector<int> is, js; rep(i, h) if (mh == dh[i]) is.emplace_back(i); rep(j, w) if (mw == dw[j]) js.emplace_back(j); int ans = mh + mw; for (int i : is) for (int j : js) { if (!baku.count(P(i, j))) { cout << ans << endl; return 0; } } ans--; cout << ans << endl; return 0; }
#include "bits/stdc++.h" #define rep(i, j) for (int i = 0; i < j; i++) #define srep(i, j, k) for (int i = j; i < k; i++) using namespace std; using ll = long long; using P = pair<int, int>; using ull = unsigned long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } // エラトステネスの篩 vector<int> estora(vector<int> num) { int sel = 0; while (sel < num.size()) { int d = num[sel]; for (int i = 0; i < num.size(); i++) { if (num[i] % d == 0 && num[i] != d && d != 1) { num.erase(num.begin() + i); i--; } } sel++; } return num; } /*ライブラリ最大公約数*/ // ユーグリッドの互除法 int gcd(int x, int y) { int num[3]; num[0] = (x > y) ? x : y; num[1] = (x <= y) ? x : y; num[2] = num[0] % num[1]; while (num[2]) { num[0] = num[1]; num[1] = num[2]; num[2] = num[0] % num[1]; } return num[1]; } /*素因数分解*/ // 自作ライブラリ // iを常に素数にしておかないとうまくできない&&計算量ヤバイ // エストラネスの篩で素数を振るっておく必要性がありそう vector<ll> fac(ll n, vector<ll> num) { ll kazu = n; for (int i = 2; i <= n; i++) { while (1) { if (kazu % i != 0) break; kazu /= i; num[i]++; } } if (kazu == n && n != 1) num[n]++; return num; int ans = 0; if (kazu != 1) ans++; for (int i = 2; i <= sqrt(n); i++) { for (int j = 1; j <= num[i]; j++) { num[i] -= j; ans++; } } return num; } const int INF = 1001001001; // mint用の定数 (10の9乗 + 7) const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } int main() { int h, w, m; cin >> h >> w >> m; vector<int> dh(h), dw(w); set<P> baku; rep(i, m) { int n1, n2; cin >> n1 >> n2; n1--; n2--; dh[n1]++; dw[n2]++; P kari = P(n1, n2); baku.insert(kari); } int mh = 0, mw = 0; rep(i, h) mh = max(mh, dh[i]); rep(i, w) mw = max(mw, dw[i]); vector<int> is, js; rep(i, h) if (mh == dh[i]) is.emplace_back(i); rep(j, w) if (mw == dw[j]) js.emplace_back(j); int ans = mh + mw; for (int i : is) for (int j : js) { if (!baku.count(P(i, j))) { cout << ans << endl; return 0; } } ans--; cout << ans << endl; return 0; }
replace
139
140
139
140
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define forr(i, a, n) for (long long int i = a; i < n; i++) #define loop(i, a, n) for (long long int i = a; i >= n; i--) int main() { ios_base ::sync_with_stdio(false), cin.tie(NULL); int a, b, c, ans = -1; cin >> a >> b >> c; int x[c], y[c], m2x = -1, m1x = -1; map<int, int> m2, m1; map<pair<int, int>, int> m; forr(i, 0, c) { cin >> x[i] >> y[i]; m[{x[i], y[i]}]++; m1[x[i]]++; m2[y[i]]++; m2x = max(m2x, m2[y[i]]); m1x = max(m1x, m1[x[i]]); } vector<int> v, w; for (auto const x : m1) { if (x.second == m1x) v.push_back(x.first); } for (auto const x : m2) { if (x.second == m2x) w.push_back(x.first); } forr(i, 0, v.size()) { forr(j, 0, w.size()) { int xx = m1[v[i]] + m2[w[j]] - m[{v[i], w[j]}]; ans = max(ans, xx); } } cout << ans << '\n'; // cout<<m1[5]<<' '<<m2[3]<<' '<<m[{5, 3}]<<' '<<m[{3, 5}]; return 0; }
#include <bits/stdc++.h> using namespace std; #define forr(i, a, n) for (long long int i = a; i < n; i++) #define loop(i, a, n) for (long long int i = a; i >= n; i--) int main() { ios_base ::sync_with_stdio(false), cin.tie(NULL); int a, b, c, ans = -1; cin >> a >> b >> c; int x[c], y[c], m2x = -1, m1x = -1; map<int, int> m2, m1; map<pair<int, int>, int> m; forr(i, 0, c) { cin >> x[i] >> y[i]; m[{x[i], y[i]}]++; m1[x[i]]++; m2[y[i]]++; m2x = max(m2x, m2[y[i]]); m1x = max(m1x, m1[x[i]]); } vector<int> v, w; for (auto const x : m1) { if (x.second == m1x) v.push_back(x.first); } for (auto const x : m2) { if (x.second == m2x) w.push_back(x.first); } forr(i, 0, v.size()) { forr(j, 0, w.size()) { int xx = m1[v[i]] + m2[w[j]] - m[{v[i], w[j]}]; ans = max(ans, xx); if (m[{v[i], w[j]}] == 0) break; } } cout << ans << '\n'; // cout<<m1[5]<<' '<<m2[3]<<' '<<m[{5, 3}]<<' '<<m[{3, 5}]; return 0; }
insert
34
34
34
36
TLE
p02580
C++
Time Limit Exceeded
// Romene #include <bits/stdc++.h> #include <string> #include <sstream> using namespace std; #define ll long long #define ld long double #define pb push_back #define pf push_front #define f first #define s second #define all(c) c.begin(), c.end() #define ulli unsigned long long int #define lli long long int #define llv vector<ll> #define llc vector<char> #define lls vector<string> #define llb vector<bool> #define mp make_pair #define endl "\n" #define debg cout << "HI" << endl; #define ins insert #define foo(i, n) for (ll i = 0; i < n; i++) #define foa(i, a) for (ll i = 0; i < a.size(); i++) #define foe(i, a, b) for (ll i = a; i <= b; i++) #define max3(a, b, c) max(max(a, b), c) #define min3(a, b, c) min(min(a, b), c) #define INF 2147483647 #define len length #define sp setprecision(16) #define mod 1000000007 ll powr(ll b, ll m) { ll ans = 1; while (m > 0) { if (m % 2 == 1) { ans = (ans * b) % mod; } b = (b * b) % mod; m = m / 2; } return ans; } ll gcd1(ll a, ll b) { if (a == 0) return b; else { return gcd1(b % a, a); } } ll lcm(ll a, ll b) { return (a * b) / gcd1(a, b); } ll mod1(ll a) { if (a < 0) return -1 * a; else { return a; } } bool isPrime(int num) { if (num == 1) return 0; for (int i = 2; i * i <= (num); i++) { if (num % i == 0) { return false; break; } } return true; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int f1 = 1; for (int y3 = 0; y3 < f1; y3++) { int n, m, t; cin >> n >> m >> t; vector<ll> v, v1, a(n, 0), b(m, 0); map<pair<ll, ll>, ll> mp1; ll a1, b1, max1 = 0, max2 = 0; for (int i = 0; i < t; i++) { cin >> a1 >> b1; a[a1 - 1]++; b[b1 - 1]++; mp1[{a1 - 1, b1 - 1}] = 1ll; max1 = max(max1, a[a1 - 1]); max2 = max(max2, b[b1 - 1]); } for (int i = 0; i < n; i++) { if (max1 == a[i]) { v.pb(i); } } for (int i = 0; i < m; i++) { if (max2 == b[i]) { v1.pb(i); } } ll ans = 0, flag = 0; /// cout << v1[0]; if (t == m * n) ans = t; else { for (int i = 0; i < v.size(); i++) { ll count; for (int j = 0; j < v1.size(); j++) { count = a[v[i]] + b[v1[j]]; if (mp1[{v[i], v1[j]}]) { count--; } ans = max(ans, count); if (count == t) break; } } } cout << ans; } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
// Romene #include <bits/stdc++.h> #include <string> #include <sstream> using namespace std; #define ll long long #define ld long double #define pb push_back #define pf push_front #define f first #define s second #define all(c) c.begin(), c.end() #define ulli unsigned long long int #define lli long long int #define llv vector<ll> #define llc vector<char> #define lls vector<string> #define llb vector<bool> #define mp make_pair #define endl "\n" #define debg cout << "HI" << endl; #define ins insert #define foo(i, n) for (ll i = 0; i < n; i++) #define foa(i, a) for (ll i = 0; i < a.size(); i++) #define foe(i, a, b) for (ll i = a; i <= b; i++) #define max3(a, b, c) max(max(a, b), c) #define min3(a, b, c) min(min(a, b), c) #define INF 2147483647 #define len length #define sp setprecision(16) #define mod 1000000007 ll powr(ll b, ll m) { ll ans = 1; while (m > 0) { if (m % 2 == 1) { ans = (ans * b) % mod; } b = (b * b) % mod; m = m / 2; } return ans; } ll gcd1(ll a, ll b) { if (a == 0) return b; else { return gcd1(b % a, a); } } ll lcm(ll a, ll b) { return (a * b) / gcd1(a, b); } ll mod1(ll a) { if (a < 0) return -1 * a; else { return a; } } bool isPrime(int num) { if (num == 1) return 0; for (int i = 2; i * i <= (num); i++) { if (num % i == 0) { return false; break; } } return true; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int f1 = 1; for (int y3 = 0; y3 < f1; y3++) { int n, m, t; cin >> n >> m >> t; vector<ll> v, v1, a(n, 0), b(m, 0); map<pair<ll, ll>, ll> mp1; ll a1, b1, max1 = 0, max2 = 0; for (int i = 0; i < t; i++) { cin >> a1 >> b1; a[a1 - 1]++; b[b1 - 1]++; mp1[{a1 - 1, b1 - 1}] = 1ll; max1 = max(max1, a[a1 - 1]); max2 = max(max2, b[b1 - 1]); } for (int i = 0; i < n; i++) { if (max1 == a[i]) { v.pb(i); } } for (int i = 0; i < m; i++) { if (max2 == b[i]) { v1.pb(i); } } ll ans = 0, flag = 0; for (int i = 0; i < m; i++) { ans = max(ans, a[v[0]] + b[i] - mp1[{v[0], i}]); } for (int i = 0; i < n; i++) { ans = max(ans, b[v1[0]] + a[i] - mp1[{i, v1[0]}]); } cout << ans; } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
replace
114
132
114
119
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef int_fast32_t int32; typedef int_fast64_t int64; const int32 inf = 1e9 + 7; const int32 MOD = 1000000007; const int64 llinf = 1e18; #define YES(n) cout << ((n) ? "YES\n" : "NO\n") #define Yes(n) cout << ((n) ? "Yes\n" : "No\n") #define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n") #define ANS(n) cout << (n) << "\n" #define REP(i, n) for (int64 i = 0; i < (n); ++i) #define FOR(i, a, b) for (int64 i = (a); i < (b); i++) #define FORR(i, a, b) for (int64 i = (a); i >= (b); i--) #define all(obj) (obj).begin(), (obj).end() #define rall(obj) (obj).rbegin(), (obj).rend() #define fi first #define se second #define pb(a) push_back(a) typedef pair<int32, int32> pii; typedef pair<int64, int64> pll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline 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); int32 h, w, m; cin >> h >> w >> m; vector<int32> hcnt(h), wcnt(w); set<pii> obj; REP(i, m) { int32 hi, wi; cin >> hi >> wi; hi--; wi--; hcnt[hi]++; wcnt[wi]++; obj.insert(pii(hi, wi)); } int32 hmx = 0, wmx = 0; REP(i, h) { chmax(hmx, hcnt[i]); } REP(i, w) { chmax(wmx, wcnt[i]); } vector<int32> hmxi, wmxj; REP(i, h) { if (hcnt[i] == hmx) hmxi.pb(i); } REP(j, w) { if (wcnt[j] == wmx) wmxj.pb(j); } bool allobj = true; for (auto i : hmxi) for (auto j : wmxj) { if (obj.count(pii(i, j)) == 0) allobj = false; } if (allobj) { ANS(hmx + wmx - 1); } else { ANS(hmx + wmx); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef int_fast32_t int32; typedef int_fast64_t int64; const int32 inf = 1e9 + 7; const int32 MOD = 1000000007; const int64 llinf = 1e18; #define YES(n) cout << ((n) ? "YES\n" : "NO\n") #define Yes(n) cout << ((n) ? "Yes\n" : "No\n") #define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n") #define ANS(n) cout << (n) << "\n" #define REP(i, n) for (int64 i = 0; i < (n); ++i) #define FOR(i, a, b) for (int64 i = (a); i < (b); i++) #define FORR(i, a, b) for (int64 i = (a); i >= (b); i--) #define all(obj) (obj).begin(), (obj).end() #define rall(obj) (obj).rbegin(), (obj).rend() #define fi first #define se second #define pb(a) push_back(a) typedef pair<int32, int32> pii; typedef pair<int64, int64> pll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline 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); int32 h, w, m; cin >> h >> w >> m; vector<int32> hcnt(h), wcnt(w); set<pii> obj; REP(i, m) { int32 hi, wi; cin >> hi >> wi; hi--; wi--; hcnt[hi]++; wcnt[wi]++; obj.insert(pii(hi, wi)); } int32 hmx = 0, wmx = 0; REP(i, h) { chmax(hmx, hcnt[i]); } REP(i, w) { chmax(wmx, wcnt[i]); } vector<int32> hmxi, wmxj; REP(i, h) { if (hcnt[i] == hmx) hmxi.pb(i); } REP(j, w) { if (wcnt[j] == wmx) wmxj.pb(j); } bool allobj = true; if ((int64)hmxi.size() * (int64)wmxj.size() <= m) { for (auto i : hmxi) for (auto j : wmxj) { if (obj.count(pii(i, j)) == 0) allobj = false; } } else { allobj = false; } if (allobj) { ANS(hmx + wmx - 1); } else { ANS(hmx + wmx); } return 0; }
replace
69
74
69
78
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair ll bg = 100000000007; #define ff(i, n) for (i = 0; i < n; i++) ll row[300001]; int main() { ll kamal; kamal = 1; while (kamal--) { ll i, j, h, w, m; cin >> h >> w >> m; vector<set<ll>> adj(w); ff(i, m) { ll a, b; cin >> a >> b; row[a - 1]++; adj[b - 1].insert(a - 1); } vector<pair<ll, ll>> vec; ff(i, h) vec.pb(mp(row[i], i)); sort(vec.begin(), vec.end()); ll ans = 0; ff(i, m) { ll e = adj[i].size(), add = 0; for (j = vec.size() - 1; j >= 0; j--) { if (adj[i].find(vec[j].second) != adj[i].end()) { add = max(add, vec[j].first - 1); } else { add = max(add, vec[j].first); break; } } ans = max(ans, e + add); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair ll bg = 100000000007; #define ff(i, n) for (i = 0; i < n; i++) ll row[300001]; int main() { ll kamal; kamal = 1; while (kamal--) { ll i, j, h, w, m; cin >> h >> w >> m; vector<set<ll>> adj(w); ff(i, m) { ll a, b; cin >> a >> b; row[a - 1]++; adj[b - 1].insert(a - 1); } vector<pair<ll, ll>> vec; ff(i, h) vec.pb(mp(row[i], i)); sort(vec.begin(), vec.end()); ll ans = 0; ff(i, w) { ll e = adj[i].size(), add = 0; for (j = vec.size() - 1; j >= 0; j--) { if (adj[i].find(vec[j].second) != adj[i].end()) { add = max(add, vec[j].first - 1); } else { add = max(add, vec[j].first); break; } } ans = max(ans, e + add); } cout << ans << endl; } return 0; }
replace
25
26
25
26
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define deb(x) cerr << #x << ":" << x << "\n" #define all(x) x.begin(), x.end() #define sz(x) x.size() #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> void solve() { int h, w, m; cin >> h >> w >> m; unordered_map<int, unordered_set<int>> mpx; unordered_map<int, unordered_set<int>> mpy; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; mpx[x].insert(y); mpy[y].insert(x); } int mxx = -1, mxy = -1; for (auto P : mpx) { mxx = max(mxx, int(P.second.size())); } for (auto P : mpy) { mxy = max(mxy, int(P.second.size())); } // deb(mxx);deb(mxy); vector<int> a, b; for (auto P : mpx) { if (P.second.size() == mxx) { a.emplace_back(P.first); } } for (auto P : mpy) { if (P.second.size() == mxy) b.emplace_back(P.first); } int ans = 0; int cnt = 0; for (auto x : a) { for (auto y : b) { // cout<<x<<":"<<y<<"\n"; ++cnt; ans = max(ans, int(mpx[x].size() + mpy[y].size() - (mpx[x].count(y) || mpy[y].count(x)))); } if (cnt == 1000000) break; } cout << ans << "\n"; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define deb(x) cerr << #x << ":" << x << "\n" #define all(x) x.begin(), x.end() #define sz(x) x.size() #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> void solve() { int h, w, m; cin >> h >> w >> m; unordered_map<int, unordered_set<int>> mpx; unordered_map<int, unordered_set<int>> mpy; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; mpx[x].insert(y); mpy[y].insert(x); } int mxx = -1, mxy = -1; for (auto P : mpx) { mxx = max(mxx, int(P.second.size())); } for (auto P : mpy) { mxy = max(mxy, int(P.second.size())); } // deb(mxx);deb(mxy); vector<int> a, b; for (auto P : mpx) { if (P.second.size() == mxx) { a.emplace_back(P.first); } } for (auto P : mpy) { if (P.second.size() == mxy) b.emplace_back(P.first); } if (sz(a) * sz(b) > 300000) { int x = a[0], y = b[0]; cout << int(mpx[x].size() + mpy[y].size()) << "\n"; return; } int ans = 0; int cnt = 0; for (auto x : a) { for (auto y : b) { // cout<<x<<":"<<y<<"\n"; ++cnt; ans = max(ans, int(mpx[x].size() + mpy[y].size() - (mpx[x].count(y) || mpy[y].count(x)))); } if (cnt == 1000000) break; } cout << ans << "\n"; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
insert
44
44
44
49
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rng(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, b) rng(i, 0, b) #define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define per(i, b) gnr(i, 0, b) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int h, w, m; cin >> h >> w >> m; vector<P> hw(m); vector<int> hh(h, 0); vector<int> ww(w, 0); set<P> s; rep(i, m) { int hhh, www; cin >> hhh >> www; hhh--; www--; hh.at(hhh)++; ww.at(www)++; hw.at(i) = P(hhh, www); s.emplace(hhh, www); } int hMax = -1; vector<int> hi; int wMax = -1; vector<int> wi; rep(i, h) { if (hh.at(i) > hMax) { hMax = hh.at(i); hi.clear(); hi.push_back(i); } else if (hh.at(i) == hMax) { hi.push_back(i); } } rep(i, w) { if (ww.at(i) > wMax) { wMax = ww.at(i); wi.clear(); wi.push_back(i); } else if (ww.at(i) == wMax) { wi.push_back(i); } } int res = hMax + wMax; bool cross = true; // 交点に爆破対象 for (int i : hi) { for (int j : wi) { if (s.count(P(i, j)) > 0) { continue; } // 爆破対象がない交点があった cross = false; } } if (cross) { res--; } cout << res << endl; return 0; }
#include <bits/stdc++.h> #define rng(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, b) rng(i, 0, b) #define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define per(i, b) gnr(i, 0, b) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int h, w, m; cin >> h >> w >> m; vector<P> hw(m); vector<int> hh(h, 0); vector<int> ww(w, 0); set<P> s; rep(i, m) { int hhh, www; cin >> hhh >> www; hhh--; www--; hh.at(hhh)++; ww.at(www)++; hw.at(i) = P(hhh, www); s.emplace(hhh, www); } int hMax = -1; vector<int> hi; int wMax = -1; vector<int> wi; rep(i, h) { if (hh.at(i) > hMax) { hMax = hh.at(i); hi.clear(); hi.push_back(i); } else if (hh.at(i) == hMax) { hi.push_back(i); } } rep(i, w) { if (ww.at(i) > wMax) { wMax = ww.at(i); wi.clear(); wi.push_back(i); } else if (ww.at(i) == wMax) { wi.push_back(i); } } int res = hMax + wMax; bool cross = true; // 交点に爆破対象 for (int i : hi) { for (int j : wi) { if (s.count(P(i, j)) > 0) { continue; } // 爆破対象がない交点があった cross = false; break; } if (!cross) { break; } } if (cross) { res--; } cout << res << endl; return 0; }
insert
60
60
60
64
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define FOR(i, a, b) for (int i = a; i <= (b); i++) #define ROF(i, a, b) for (int i = a; i >= (b); i--) using pii = pair<int, int>; using vpii = vector<pii>; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using pll = pair<ll, ll>; using vpll = vector<pll>; using vll = vector<ll>; using vvll = vector<vll>; int main() { int h, w, m; cin >> h >> w >> m; vector<map<int, bool>> cy(h + 1); vi sx(h + 1), sy(w + 1); FOR(i, 1, m) { int x, y; cin >> x >> y; cy[x][y] = 1, sx[x]++, sy[y]++; } priority_queue<pii> pq; FOR(i, 1, w) pq.push({sy[i], i}); int ans = 0; FOR(i, 1, h) { if (sx[i]) { vpii rm; int tmx = 0; while (cy[i][pq.top().se]) { tmx = max(tmx, pq.top().fi - 1); rm.pb(pq.top()); pq.pop(); } if (!pq.empty()) tmx = max(tmx, pq.top().fi); ans = max(ans, sx[i] + tmx); for (pii j : rm) pq.push(j); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define FOR(i, a, b) for (int i = a; i <= (b); i++) #define ROF(i, a, b) for (int i = a; i >= (b); i--) using pii = pair<int, int>; using vpii = vector<pii>; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using pll = pair<ll, ll>; using vpll = vector<pll>; using vll = vector<ll>; using vvll = vector<vll>; int main() { int h, w, m; cin >> h >> w >> m; vector<map<int, bool>> cy(h + 1); vi sx(h + 1), sy(w + 1); FOR(i, 1, m) { int x, y; cin >> x >> y; cy[x][y] = 1, sx[x]++, sy[y]++; } priority_queue<pii> pq; FOR(i, 1, w) pq.push({sy[i], i}); int ans = 0; FOR(i, 1, h) { if (sx[i]) { vpii rm; int tmx = 0; while (!pq.empty() && cy[i][pq.top().se]) { tmx = max(tmx, pq.top().fi - 1); rm.pb(pq.top()); pq.pop(); } if (!pq.empty()) tmx = max(tmx, pq.top().fi); ans = max(ans, sx[i] + tmx); for (pii j : rm) pq.push(j); } } cout << ans << endl; }
replace
39
40
39
40
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, m, k, x, y; vector<pair<int, int>> p; vector<int> col, row; int main() { cin >> n >> m >> k; row.assign(n + 1, 0); col.assign(m + 1, 0); int mxr = 0, mxc = 0; for (int i = 0; i < k; i++) { cin >> x >> y; p.push_back({x, y}); row[x]++; col[y]++; mxr = max(row[x], mxr); mxc = max(col[x], mxc); } int qtd = 0, qtdr = 0, qtdc = 0; for (int i = 0; i <= n; i++) if (row[i] == mxr) qtdr++; for (int i = 0; i <= m; i++) if (col[i] == mxc) qtdc++; for (auto par : p) { if (row[par.first] == mxr && col[par.second] == mxc) { qtd++; } } if (qtd == qtdr * qtdc) cout << mxr + mxc - 1 << '\n'; else cout << mxr + mxc << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, k, x, y; vector<pair<int, int>> p; vector<int> col, row; int main() { cin >> n >> m >> k; row.assign(n + 1, 0); col.assign(m + 1, 0); int mxr = 0, mxc = 0; for (int i = 0; i < k; i++) { cin >> x >> y; p.push_back({x, y}); row[x]++; col[y]++; mxr = max(row[x], mxr); mxc = max(col[y], mxc); } int qtd = 0, qtdr = 0, qtdc = 0; for (int i = 0; i <= n; i++) if (row[i] == mxr) qtdr++; for (int i = 0; i <= m; i++) if (col[i] == mxc) qtdc++; for (auto par : p) { if (row[par.first] == mxr && col[par.second] == mxc) { qtd++; } } if (qtd == qtdr * qtdc) cout << mxr + mxc - 1 << '\n'; else cout << mxr + mxc << '\n'; return 0; }
replace
19
20
19
20
0
p02580
C++
Runtime Error
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i <= (int)(n); i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = long long; using pi = pair<int, int>; const ll INF = 1LL << 60; int main() { int h, w, m; cin >> h >> w >> m; vector<int> hp(h), wp(w); set<pi> s; rep(i, m) { int y, x; cin >> y >> x; y--, x--; hp[y]++; wp[x]++; s.insert(pi(y, x)); } int mh = 0, mw = 0; rep(i, h) mh = max(mh, hp[i]); rep(i, w) mw = max(mw, wp[i]); vector<int> hm, wm; rep(i, h) if (hp[i] == mh) hm.push_back(i); rep(i, w) if (wp[i] == mw) wm.push_back(i); ll ans = mh + mw; rep(i, h) rep(j, w) { if (s.count(pi(hm[i], wm[j]))) continue; cout << ans << endl; return 0; } cout << --ans << endl; return 0; }
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i <= (int)(n); i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = long long; using pi = pair<int, int>; const ll INF = 1LL << 60; int main() { int h, w, m; cin >> h >> w >> m; vector<int> hp(h), wp(w); set<pi> s; rep(i, m) { int y, x; cin >> y >> x; y--, x--; hp[y]++; wp[x]++; s.insert(pi(y, x)); } int mh = 0, mw = 0; rep(i, h) mh = max(mh, hp[i]); rep(i, w) mw = max(mw, wp[i]); vector<int> hm, wm; rep(i, h) if (hp[i] == mh) hm.push_back(i); rep(i, w) if (wp[i] == mw) wm.push_back(i); ll ans = mh + mw; for (int y : hm) for (int x : wm) { if (s.count(pi(y, x))) continue; cout << ans << endl; return 0; } cout << --ans << endl; return 0; }
replace
34
40
34
41
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> // #pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") using namespace std; typedef long long ll; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // typedef // tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds; #define IN freopen("in.txt", "r", stdin) #define OUT freopen("out.txt", "w", stdout) #define pi pair<int, int> #define F first #define S second #define pb push_back #define pp pop_back #define mod 1000000007 #define pai acos(-1) #define N 300005 int tree[3 * N]; vector<int> G[N]; void update(int node, int b, int e, int idx, int val) { if (idx < b || idx > e) return; if (b == e) { tree[node] += val; return; } int mid = (b + e) / 2; update(2 * node, b, mid, idx, val); update(2 * node + 1, mid + 1, e, idx, val); tree[node] = max(tree[2 * node], tree[2 * node + 1]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int h, w, m; cin >> h >> w >> m; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; G[x].pb(y); update(1, 1, w, y, 1); } int ans = 0; for (int i = 1; i <= h; i++) { if (G[i].size()) { int cnt = G[i].size(); for (int v : G[i]) update(1, 1, w, v, -1); cnt += tree[1]; ans = max(cnt, ans); for (int v : G[i]) update(1, 1, w, v, 1); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> // #pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") using namespace std; typedef long long ll; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // typedef // tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds; #define IN freopen("in.txt", "r", stdin) #define OUT freopen("out.txt", "w", stdout) #define pi pair<int, int> #define F first #define S second #define pb push_back #define pp pop_back #define mod 1000000007 #define pai acos(-1) #define N 300005 int tree[4 * N]; vector<int> G[N]; void update(int node, int b, int e, int idx, int val) { if (idx < b || idx > e) return; if (b == e) { tree[node] += val; return; } int mid = (b + e) / 2; update(2 * node, b, mid, idx, val); update(2 * node + 1, mid + 1, e, idx, val); tree[node] = max(tree[2 * node], tree[2 * node + 1]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int h, w, m; cin >> h >> w >> m; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; G[x].pb(y); update(1, 1, w, y, 1); } int ans = 0; for (int i = 1; i <= h; i++) { if (G[i].size()) { int cnt = G[i].size(); for (int v : G[i]) update(1, 1, w, v, -1); cnt += tree[1]; ans = max(cnt, ans); for (int v : G[i]) update(1, 1, w, v, 1); } } cout << ans << endl; return 0; }
replace
25
26
25
26
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define ALL(c) (c).begin(), (c).end() #define SUM(x) std::accumulate(ALL(x), 0LL) #define MIN(v) *std::min_element(v.begin(), v.end()) #define MAX(v) *std::max_element(v.begin(), v.end()) #define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) using namespace std; using ll = long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline void dump(vector<T> v) { for (auto &x : v) cerr << x << " "; cerr << endl; } template <class T> inline void dump(vector<pair<T, T>> v) { for (auto &p : v) cerr << p.first << " " << p.second << endl; } template <class T> inline void dump(vector<vector<T>> vv) { for (auto &v : vv) { for (auto &x : v) cerr << x << " "; cerr << endl; } } constexpr int INF = 1001001001; constexpr long long INFL = (1LL << 60); constexpr double eps = (1e-9); using P = pair<int, int>; int main() { cin.tie(0); ios::sync_with_stdio(false); int h, w, m; cin >> h >> w >> m; vector<ll> nh(h, 0); // i 行に置いてある対象物 vector<ll> nw(w, 0); // i 列に置いてある対象物 set<P> t; // 対象物が置いてある座標 rep(i, m) { int hh, ww; cin >> hh >> ww; hh--; ww--; nh[hh]++; nw[ww]++; t.insert({hh, ww}); } map<ll, vector<int>> mph, mpw; // x 個破壊できる 行番号, 列番号 rep(i, h) { int num = nh[i]; mph[num].push_back(i); } rep(i, w) { int num = nw[i]; mpw[num].push_back(i); } ll ans = 1; /* cerr << "hmax: " << hmax << " wmax: " << wmax << endl; dump(nh); dump(nw); dump(mph.rbegin()->second); dump(mpw.rbegin()->second); */ auto itrx = mph.rbegin(); for (auto &x : itrx->second) { // x: 爆弾を置く行番号 auto itry = mpw.rbegin(); for (auto &y : itry->second) { // y: 爆弾を置く列番号 if (t.count({x, y}) == 0) { cout << itrx->first + itry->first << endl; return 0; } else { chmax(ans, ll(itrx->first + itry->first - 1)); // 交点に対象物がある } } itry++; if (itry == mpw.rend()) continue; for (auto &y : itry->second) { // y: 爆弾を置く列番号 if (t.count({x, y}) == 0) { chmax(ans, ll(itrx->first + itry->first)); } else { chmax(ans, ll(itrx->first + itry->first - 1)); // 交点に対象物がある } } } auto itry = mpw.rbegin(); for (auto &y : itry->second) { // y: 爆弾を置く列番号 auto itrx = mph.rbegin(); for (auto &x : itrx->second) { // x: 爆弾を置く行番号 if (t.count({x, y}) == 0) { cout << itrx->first + itry->first << endl; return 0; } else { chmax(ans, ll(itrx->first + itry->first - 1)); // 交点に対象物がある } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define ALL(c) (c).begin(), (c).end() #define SUM(x) std::accumulate(ALL(x), 0LL) #define MIN(v) *std::min_element(v.begin(), v.end()) #define MAX(v) *std::max_element(v.begin(), v.end()) #define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) using namespace std; using ll = long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline void dump(vector<T> v) { for (auto &x : v) cerr << x << " "; cerr << endl; } template <class T> inline void dump(vector<pair<T, T>> v) { for (auto &p : v) cerr << p.first << " " << p.second << endl; } template <class T> inline void dump(vector<vector<T>> vv) { for (auto &v : vv) { for (auto &x : v) cerr << x << " "; cerr << endl; } } constexpr int INF = 1001001001; constexpr long long INFL = (1LL << 60); constexpr double eps = (1e-9); using P = pair<int, int>; int main() { cin.tie(0); ios::sync_with_stdio(false); int h, w, m; cin >> h >> w >> m; vector<ll> nh(h, 0); // i 行に置いてある対象物 vector<ll> nw(w, 0); // i 列に置いてある対象物 set<P> t; // 対象物が置いてある座標 rep(i, m) { int hh, ww; cin >> hh >> ww; hh--; ww--; nh[hh]++; nw[ww]++; t.insert({hh, ww}); } map<ll, vector<int>> mph, mpw; // x 個破壊できる 行番号, 列番号 rep(i, h) { int num = nh[i]; mph[num].push_back(i); } rep(i, w) { int num = nw[i]; mpw[num].push_back(i); } ll ans = 1; /* cerr << "hmax: " << hmax << " wmax: " << wmax << endl; dump(nh); dump(nw); dump(mph.rbegin()->second); dump(mpw.rbegin()->second); */ auto itrx = mph.rbegin(); for (auto &x : itrx->second) { // x: 爆弾を置く行番号 auto itry = mpw.rbegin(); for (auto &y : itry->second) { // y: 爆弾を置く列番号 if (t.count({x, y}) == 0) { cout << itrx->first + itry->first << endl; return 0; } else { chmax(ans, ll(itrx->first + itry->first - 1)); // 交点に対象物がある } } } auto itry = mpw.rbegin(); for (auto &y : itry->second) { // y: 爆弾を置く列番号 auto itrx = mph.rbegin(); for (auto &x : itrx->second) { // x: 爆弾を置く行番号 if (t.count({x, y}) == 0) { cout << itrx->first + itry->first << endl; return 0; } else { chmax(ans, ll(itrx->first + itry->first - 1)); // 交点に対象物がある } } } cout << ans << endl; return 0; }
delete
107
118
107
107
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define endl '\n' #define uset unordered_set #define umap unordered_map #define all(var) var.begin(), var.end() #define input freopen("input", "r", stdin) #define output freopen("output", "w", stdout) #define Fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL) typedef long long ll; using namespace std; struct HASH { size_t operator()(const pair<int, int> &x) const { return hash<long long>()(((long long)x.first) ^ (((long long)x.second) << 32)); } }; int dr[] = {0, 0, -1, +1, -1, -1, +1, +1}; int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1}; int main() { int h, w, n; scanf("%d%d%d", &h, &w, &n); umap<int, int> row, col; umap<pair<int, int>, int, HASH> grid; int mx_r = 0, mx_c = 0; for (int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); row[x]++; col[y]++; grid[{x, y}] = 1; mx_r = max(mx_r, row[x]); mx_c = max(mx_c, col[y]); } vector<int> a, b; for (auto i : row) { if (i.second == mx_r) a.push_back(i.first); } for (auto i : col) { if (i.second == mx_c) b.push_back(i.first); } int ans = 0; int highest = h + w - 1; for (int i : a) { for (int j : b) { ans = max(ans, mx_r + mx_c - grid[{i, j}]); if (ans == highest) goto end; } } end:; printf("%d", ans); }
#include <bits/stdc++.h> #define endl '\n' #define uset unordered_set #define umap unordered_map #define all(var) var.begin(), var.end() #define input freopen("input", "r", stdin) #define output freopen("output", "w", stdout) #define Fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL) typedef long long ll; using namespace std; struct HASH { size_t operator()(const pair<int, int> &x) const { return hash<long long>()(((long long)x.first) ^ (((long long)x.second) << 32)); } }; int dr[] = {0, 0, -1, +1, -1, -1, +1, +1}; int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1}; int main() { int h, w, n; scanf("%d%d%d", &h, &w, &n); umap<int, int> row, col; umap<pair<int, int>, int, HASH> grid; int mx_r = 0, mx_c = 0; for (int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); row[x]++; col[y]++; grid[{x, y}] = 1; mx_r = max(mx_r, row[x]); mx_c = max(mx_c, col[y]); } vector<int> a, b; for (auto i : row) { if (i.second == mx_r) a.push_back(i.first); } for (auto i : col) { if (i.second == mx_c) b.push_back(i.first); } int ans = 0; int highest = mx_r + mx_c; for (int i : a) { for (int j : b) { ans = max(ans, mx_r + mx_c - grid[{i, j}]); if (ans == highest) goto end; } } end:; printf("%d", ans); }
replace
46
47
46
47
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ar array #define endl '\n' #define ll long long #define in insert #define pb push_back #define vt vector #define P_Q(x) priority_queue<x> #define p_q(x) priority_queue<x, vector<x>, greater<x>> #define Rep(i, a, b) for (int i = a; i <= b; i++) #define Rev(i, a, b) for (ll i = a; i >= b; i--) #define FOR(m) Rep(i, 1, m) #define For(m) Rep(i, 0, m - 1) #define Rbl(x, a) for (auto &x : a) #define FIO \ ios::sync_with_stdio(0); \ cin.tie(0); #define F first #define S second #define pii pair<int, int> #define pll pair<ll, ll> #define mp make_pair #define vpii vector<pii> #define vpll vector<pll> #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() const ll INF = 0x3f3f3f3f3f3f3f3fll; #define mod 1000000007 const int mxN = 3e5 + 1; // ll a[mxN]; set<ll> row[mxN], col[mxN]; set<array<ll, 2>> R, C; ll n, m, q; int main() { FIO cin >> n >> m >> q; For(q) { ll u, v; cin >> u >> v; row[u].in(v); col[v].in(u); } FOR(n) if (sz(row[i])) R.in({sz(row[i]), i}); FOR(m) if (sz(col[i])) C.in({sz(col[i]), i}); auto z = *R.rbegin(); ll maxi1 = z[0]; z = *C.rbegin(); ll maxi2 = z[0]; ll ans = maxi1 + maxi2 - 1; for (auto i = R.rbegin(); i != R.rend() && (*i)[0] == maxi1; i++) { vt<array<ll, 2>> vec; for (ll x : row[(*i)[1]]) { array<ll, 2> temp = {sz(col[x]), x}; C.erase(temp); vec.pb(temp); } auto z = *C.rbegin(); if (z[0] == maxi2) { ans = maxi1 + maxi2; break; } for (auto x : vec) C.in(x); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ar array #define endl '\n' #define ll long long #define in insert #define pb push_back #define vt vector #define P_Q(x) priority_queue<x> #define p_q(x) priority_queue<x, vector<x>, greater<x>> #define Rep(i, a, b) for (int i = a; i <= b; i++) #define Rev(i, a, b) for (ll i = a; i >= b; i--) #define FOR(m) Rep(i, 1, m) #define For(m) Rep(i, 0, m - 1) #define Rbl(x, a) for (auto &x : a) #define FIO \ ios::sync_with_stdio(0); \ cin.tie(0); #define F first #define S second #define pii pair<int, int> #define pll pair<ll, ll> #define mp make_pair #define vpii vector<pii> #define vpll vector<pll> #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() const ll INF = 0x3f3f3f3f3f3f3f3fll; #define mod 1000000007 const int mxN = 3e5 + 1; // ll a[mxN]; set<ll> row[mxN], col[mxN]; set<array<ll, 2>> R, C; ll n, m, q; int main() { FIO cin >> n >> m >> q; For(q) { ll u, v; cin >> u >> v; row[u].in(v); col[v].in(u); } FOR(n) if (sz(row[i])) R.in({sz(row[i]), i}); FOR(m) if (sz(col[i])) C.in({sz(col[i]), i}); auto z = *R.rbegin(); ll maxi1 = z[0]; z = *C.rbegin(); ll maxi2 = z[0]; ll ans = maxi1 + maxi2 - 1; for (auto i = R.rbegin(); i != R.rend() && (*i)[0] == maxi1; i++) { vt<array<ll, 2>> vec; for (ll x : row[(*i)[1]]) { array<ll, 2> temp = {sz(col[x]), x}; C.erase(temp); vec.pb(temp); } if (!C.empty()) { auto z = *C.rbegin(); if (z[0] == maxi2) { ans = maxi1 + maxi2; break; } } for (auto x : vec) C.in(x); } cout << ans << endl; }
replace
62
67
62
68
0
p02580
C++
Runtime Error
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; //----------------------- Print Function ----------------------// inline void print() { cout << endl; } template <typename First, typename... Rest> void print(const First &first, const Rest &...rest) { cout << first << ' '; print(rest...); } template <typename T> void print(const vector<T> &v) { for (auto e : v) cout << e << ' '; cout << endl; } //------------------------- Libraries -------------------------// //--------------------------- Solve ---------------------------// void solve() { int H, W, M; cin >> H >> W >> M; set<pair<int, int>> items; vector<long long> sum_h(W), sum_w(H); for (int i = 0; i < M; i++) { int h, w; cin >> h >> w; h--; w--; sum_h[w]++; sum_w[h]++; items.insert(make_pair(h, w)); } set<int> ans_w, ans_h; long long max_w = 0, max_h = 0; for (int w = 0; w < W; w++) { if (max_h < sum_h[w]) { max_h = max(max_h, sum_h[w]); ans_w.clear(); ans_w.insert(w); } else if (max_h == sum_h[w]) { ans_w.insert(w); } } for (int h = 0; h < W; h++) { if (max_w < sum_w[h]) { max_w = max(max_w, sum_w[h]); ans_h.clear(); ans_h.insert(h); } else if (max_w == sum_w[h]) { ans_h.insert(h); } } long long siz = (long long)ans_w.size() * (long long)ans_h.size(); if (siz > M) { cout << max_w + max_h << '\n'; } else { for (int w : ans_w) { for (int h : ans_h) { if (items.find(make_pair(h, w)) == items.end()) { cout << max_w + max_h << '\n'; return; } } } cout << max_w + max_h - 1 << '\n'; } } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); solve(); return 0; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; //----------------------- Print Function ----------------------// inline void print() { cout << endl; } template <typename First, typename... Rest> void print(const First &first, const Rest &...rest) { cout << first << ' '; print(rest...); } template <typename T> void print(const vector<T> &v) { for (auto e : v) cout << e << ' '; cout << endl; } //------------------------- Libraries -------------------------// //--------------------------- Solve ---------------------------// void solve() { int H, W, M; cin >> H >> W >> M; set<pair<int, int>> items; vector<long long> sum_h(W), sum_w(H); for (int i = 0; i < M; i++) { int h, w; cin >> h >> w; h--; w--; sum_h[w]++; sum_w[h]++; items.insert(make_pair(h, w)); } set<int> ans_w, ans_h; long long max_w = 0, max_h = 0; for (int w = 0; w < W; w++) { if (max_h < sum_h[w]) { max_h = max(max_h, sum_h[w]); ans_w.clear(); ans_w.insert(w); } else if (max_h == sum_h[w]) { ans_w.insert(w); } } for (int h = 0; h < H; h++) { if (max_w < sum_w[h]) { max_w = max(max_w, sum_w[h]); ans_h.clear(); ans_h.insert(h); } else if (max_w == sum_w[h]) { ans_h.insert(h); } } long long siz = (long long)ans_w.size() * (long long)ans_h.size(); if (siz > M) { cout << max_w + max_h << '\n'; } else { for (int w : ans_w) { for (int h : ans_h) { if (items.find(make_pair(h, w)) == items.end()) { cout << max_w + max_h << '\n'; return; } } } cout << max_w + max_h - 1 << '\n'; } } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); solve(); return 0; }
replace
51
52
51
52
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define pb push_back #define pll pair<long long, long long> #define f first #define s second #define debug cout << "here\n" #define MOD 1000000009 const int MAXN = 2e5 + 15; using namespace std; int R[MAXN], C[MAXN]; void solve() { int n, m, q; cin >> n >> m >> q; int mrc = 0, mcc = 0, mr, mc; map<pair<int, int>, bool> mp; for (int i = 0; i < q; i++) { int a, b; cin >> a >> b; R[a]++; C[b]++; if (C[b] > mcc) { mcc = C[b]; mc = b; } if (R[a] > mrc) { mrc = R[a]; mr = a; } mp[{a, b}] = 1; } int ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, mcc + R[i + 1] - mp[{i + 1, mc}]); } for (int i = 0; i < m; i++) { ans = max(ans, mrc + C[i + 1] - mp[{mr, i + 1}]); } cout << ans; } int main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); cout << fixed << setprecision(12); int t = 1; // cin>>t; for (int i = 1; i <= t; i++) { solve(); cout << "\n"; } return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define pll pair<long long, long long> #define f first #define s second #define debug cout << "here\n" #define MOD 1000000009 const int MAXN = 3e5 + 15; using namespace std; int R[MAXN], C[MAXN]; void solve() { int n, m, q; cin >> n >> m >> q; int mrc = 0, mcc = 0, mr, mc; map<pair<int, int>, bool> mp; for (int i = 0; i < q; i++) { int a, b; cin >> a >> b; R[a]++; C[b]++; if (C[b] > mcc) { mcc = C[b]; mc = b; } if (R[a] > mrc) { mrc = R[a]; mr = a; } mp[{a, b}] = 1; } int ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, mcc + R[i + 1] - mp[{i + 1, mc}]); } for (int i = 0; i < m; i++) { ans = max(ans, mrc + C[i + 1] - mp[{mr, i + 1}]); } cout << ans; } int main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); cout << fixed << setprecision(12); int t = 1; // cin>>t; for (int i = 1; i <= t; i++) { solve(); cout << "\n"; } return 0; }
replace
9
10
9
10
0
p02580
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; #define N (1000000000 + 7) // #define N 998244353 #define INF 1e16 typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> Q; const int inf = (int)1e9; int main(void) { int h, w, m; cin >> h >> w >> m; map<int, int> mp1, mp2; map<P, bool> exist; for (int i = 0; i < m; i++) { int hi, wi; cin >> hi >> wi; hi--; wi--; mp1[hi]++; mp2[wi]++; exist[P(hi, wi)] = true; } int colmax = 0, rowmax = 0; for (auto [x, y] : mp1) { colmax = max(colmax, y); } for (auto [x, y] : mp2) { rowmax = max(rowmax, y); } set<P> p1, p2; for (auto [x, y] : mp1) { if (colmax == y) { p1.insert(P(x, y)); } } for (auto [x, y] : mp2) { if (rowmax == y) { p2.insert(P(x, y)); } } int ans = 0; for (auto itr1 = p1.begin(); itr1 != p1.end(); ++itr1) { for (auto itr2 = p2.begin(); itr2 != p2.end(); ++itr2) { int num = (itr1->second) + (itr2->second); int x = itr1->first; int y = itr2->first; if (exist[P(x, y)]) num--; ans = max(ans, num); } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; #define N (1000000000 + 7) // #define N 998244353 #define INF 1e16 typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> Q; const int inf = (int)1e9; int main(void) { int h, w, m; cin >> h >> w >> m; map<int, int> mp1, mp2; map<P, bool> exist; for (int i = 0; i < m; i++) { int hi, wi; cin >> hi >> wi; hi--; wi--; mp1[hi]++; mp2[wi]++; exist[P(hi, wi)] = true; } int colmax = 0, rowmax = 0; for (auto [x, y] : mp1) { colmax = max(colmax, y); } for (auto [x, y] : mp2) { rowmax = max(rowmax, y); } set<P> p1, p2; for (auto [x, y] : mp1) { if (colmax == y) { p1.insert(P(x, y)); } } for (auto [x, y] : mp2) { if (rowmax == y) { p2.insert(P(x, y)); } } int ans = 0; for (auto itr1 = p1.begin(); itr1 != p1.end(); ++itr1) { for (auto itr2 = p2.begin(); itr2 != p2.end(); ++itr2) { int num = (itr1->second) + (itr2->second); int x = itr1->first; int y = itr2->first; if (exist[P(x, y)]) num--; else { cout << num << endl; return 0; } ans = max(ans, num); } } cout << ans << endl; return 0; }
insert
64
64
64
68
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using Int = long long; const char newl = '\n'; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } template <typename T> void drop(const T &x) { cout << x << endl; exit(0); } template <typename T = int> vector<T> read(size_t n) { vector<T> ts(n); for (size_t i = 0; i < n; i++) cin >> ts[i]; return ts; } template <typename TV, const int N> void read_tuple_impl(TV &) {} template <typename TV, const int N, typename Head, typename... Tail> void read_tuple_impl(TV &ts) { get<N>(ts).emplace_back(*(istream_iterator<Head>(cin))); read_tuple_impl<TV, N + 1, Tail...>(ts); } template <typename... Ts> decltype(auto) read_tuple(size_t n) { tuple<vector<Ts>...> ts; for (size_t i = 0; i < n; i++) read_tuple_impl<decltype(ts), 0, Ts...>(ts); return ts; } // INSERT ABOVE HERE signed main() { cin.tie(0); ios::sync_with_stdio(0); int h, w, m; cin >> h >> w >> m; auto [ys, xs] = read_tuple<int, int>(m); using P = pair<int, int>; set<P> sp; for (int i = 0; i < m; i++) sp.emplace(ys[i], xs[i]); map<int, int> cy, cx; for (int y : ys) cy[y]++; for (int x : xs) cx[x]++; int my = 0, mx = 0; for (auto [y, c] : cy) chmax(my, c); for (auto [x, d] : cx) chmax(mx, d); for (auto [y, c] : cy) for (auto [x, d] : cx) if (c == my and d == mx and !sp.count(P(y, x))) drop(my + mx); cout << my + mx - 1 << newl; return 0; }
#include <bits/stdc++.h> using namespace std; using Int = long long; const char newl = '\n'; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } template <typename T> void drop(const T &x) { cout << x << endl; exit(0); } template <typename T = int> vector<T> read(size_t n) { vector<T> ts(n); for (size_t i = 0; i < n; i++) cin >> ts[i]; return ts; } template <typename TV, const int N> void read_tuple_impl(TV &) {} template <typename TV, const int N, typename Head, typename... Tail> void read_tuple_impl(TV &ts) { get<N>(ts).emplace_back(*(istream_iterator<Head>(cin))); read_tuple_impl<TV, N + 1, Tail...>(ts); } template <typename... Ts> decltype(auto) read_tuple(size_t n) { tuple<vector<Ts>...> ts; for (size_t i = 0; i < n; i++) read_tuple_impl<decltype(ts), 0, Ts...>(ts); return ts; } // INSERT ABOVE HERE signed main() { cin.tie(0); ios::sync_with_stdio(0); int h, w, m; cin >> h >> w >> m; auto [ys, xs] = read_tuple<int, int>(m); using P = pair<int, int>; set<P> sp; for (int i = 0; i < m; i++) sp.emplace(ys[i], xs[i]); map<int, int> cy, cx; for (int y : ys) cy[y]++; for (int x : xs) cx[x]++; int my = 0, mx = 0; for (auto [y, c] : cy) chmax(my, c); for (auto [x, d] : cx) chmax(mx, d); auto filter = [&](auto mp, int target) { vector<int> vs; for (auto [key, val] : mp) if (val == target) vs.emplace_back(key); return vs; }; auto yy = filter(cy, my); auto xx = filter(cx, mx); for (auto y : yy) for (auto x : xx) if (!sp.count(P(y, x))) drop(my + mx); cout << my + mx - 1 << newl; return 0; }
replace
64
67
64
77
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; /* typedef */ typedef long long ll; typedef pair<int, int> pii; /* constant */ const int INF = 1 << 30; const ll LINF = 1LL << 50; const int NIL = -1; // const int MAX = 300001; const int MAX = 10; const int mod = 1000000007; const double pi = 3.141592653589; /* global variables */ /* function */ /* main */ int main() { vector<int> cntx(MAX), cnty(MAX); map<pii, int> mp; int H, W, N; cin >> H >> W >> N; for (int i = 0; i < N; i++) { int x, y; cin >> x >> y; cntx[x]++; cnty[y]++; mp[pii(x, y)]++; } int mx = *max_element(cntx.begin(), cntx.end()); int my = *max_element(cnty.begin(), cnty.end()); vector<int> X, Y; for (int i = 1; i < MAX; i++) { if (cntx[i] == mx) X.push_back(i); if (cnty[i] == my) Y.push_back(i); } for (int x : X) { for (int y : Y) { if (mp.count(pii(x, y)) == 0) { cout << mx + my << '\n'; return 0; } } } cout << mx + my - 1 << '\n'; }
#include <bits/stdc++.h> using namespace std; /* typedef */ typedef long long ll; typedef pair<int, int> pii; /* constant */ const int INF = 1 << 30; const ll LINF = 1LL << 50; const int NIL = -1; const int MAX = 300001; const int mod = 1000000007; const double pi = 3.141592653589; /* global variables */ /* function */ /* main */ int main() { vector<int> cntx(MAX), cnty(MAX); map<pii, int> mp; int H, W, N; cin >> H >> W >> N; for (int i = 0; i < N; i++) { int x, y; cin >> x >> y; cntx[x]++; cnty[y]++; mp[pii(x, y)]++; } int mx = *max_element(cntx.begin(), cntx.end()); int my = *max_element(cnty.begin(), cnty.end()); vector<int> X, Y; for (int i = 1; i < MAX; i++) { if (cntx[i] == mx) X.push_back(i); if (cnty[i] == my) Y.push_back(i); } for (int x : X) { for (int y : Y) { if (mp.count(pii(x, y)) == 0) { cout << mx + my << '\n'; return 0; } } } cout << mx + my - 1 << '\n'; }
replace
9
11
9
10
0
p02580
C++
Time Limit Exceeded
// I'll always miss you like a darling. #include <bits/stdc++.h> using namespace std; #define LL long long #define LD long double #define ull unsigned long long #define x first #define y second #define pb push_back #define pf push_front #define mp make_pair #define Pair pair<int, int> #define pLL pair<LL, LL> #define pii pair<double, double> #define LOWBIT(x) x & (-x) #define rep(i, a, b) for (int i = a; i <= b; i++) #define REP(i, a, b) for (int i = a; i >= b; i--) const int INF = 2e9; const LL LINF = 2e16; const int magic = 348; const int MOD = 1e9 + 7; const double eps = 1e-10; const double pi = acos(-1); struct fastio { static const int S = 1e7; char rbuf[S + 48], wbuf[S + 48]; int rpos, wpos, len; fastio() { rpos = len = wpos = 0; } inline char Getchar() { if (rpos == len) rpos = 0, len = fread(rbuf, 1, S, stdin); if (!len) return EOF; return rbuf[rpos++]; } template <class T> inline void Get(T &x) { char ch; bool f; T res; while (!isdigit(ch = Getchar()) && ch != '-') { } if (ch == '-') f = false, res = 0; else f = true, res = ch - '0'; while (isdigit(ch = Getchar())) res = res * 10 + ch - '0'; x = (f ? res : -res); } inline void getstring(char *s) { char ch; while ((ch = Getchar()) <= 32) { } for (; ch > 32; ch = Getchar()) *s++ = ch; *s = '\0'; } inline void flush() { fwrite(wbuf, 1, wpos, stdout); fflush(stdout); wpos = 0; } inline void Writechar(char ch) { if (wpos == S) flush(); wbuf[wpos++] = ch; } template <class T> inline void Print(T x, char ch) { char s[20]; int pt = 0; if (x == 0) s[++pt] = '0'; else { if (x < 0) Writechar('-'), x = -x; while (x) s[++pt] = '0' + x % 10, x /= 10; } while (pt) Writechar(s[pt--]); Writechar(ch); } inline void printstring(char *s) { int pt = 1; while (s[pt] != '\0') Writechar(s[pt++]); } } io; template <typename T> inline void check_max(T &x, T cmp) { x = max(x, cmp); } template <typename T> inline void check_min(T &x, T cmp) { x = min(x, cmp); } template <typename T> inline T myabs(T x) { return x >= 0 ? x : -x; } template <typename T> inline T gcd(T x, T y) { return y == 0 ? x : gcd(y, x % y); } inline int add(int x) { if (x >= MOD) x -= MOD; return x; } inline int add(int x, int MO) { if (x >= MO) x -= MO; return x; } inline int sub(int x) { if (x < 0) x += MOD; return x; } inline int sub(int x, int MO) { if (x < 0) x += MO; return x; } inline void Add(int &x, int y) { x = add(x + y); } inline void Add(int &x, int y, int MO) { x = add(x + y, MO); } inline void Sub(int &x, int y) { x = sub(x - y); } inline void Sub(int &x, int y, int MO) { x = sub(x - y, MO); } template <typename T> inline int quick_pow(int x, T y) { int res = 1; while (y) { if (y & 1) res = 1ll * res * x % MOD; x = 1ll * x * x % MOD; y >>= 1; } return res; } template <typename T> inline int quick_pow(int x, T y, int MO) { int res = 1; while (y) { if (y & 1) res = 1ll * res * x % MO; x = 1ll * x * x % MO; y >>= 1; } return res; } const int MAXN = 3e5; int r, c, n; struct node { int x, y; } a[MAXN + 48]; inline bool cmp_x(node x, node y) { return x.x < y.x; } inline bool cmp_y(node x, node y) { return x.y < y.y; } set<int> candidate; int tot; int main() { #ifndef ONLINE_JUDGE double TIME = clock(); freopen("a.in", "r", stdin); freopen("a.out", "w", stdout); cerr << "Running..." << endl; #endif scanf("%d%d%d", &r, &c, &n); rep(i, 1, n) scanf("%d%d", &a[i].x, &a[i].y); int max1 = 0, max2 = 0; sort(a + 1, a + n + 1, cmp_y); rep(i, 1, n) { int j = i, cur = a[i].y; while (j <= n && a[j].y == cur) j++; j--; if (j - i + 1 > max2) { max2 = j - i + 1; candidate.clear(); candidate.insert(cur); } else if (j - i + 1 == max2) candidate.insert(cur); i = j; } tot = int(candidate.size()); sort(a + 1, a + n + 1, cmp_x); rep(i, 1, n) { int j = i, cur = a[i].x; while (j <= n && a[j].x == cur) j++; j--; check_max(max1, j - i + 1); i = j; } bool f = false; rep(i, 1, n) { int j = i, cur = a[i].x; while (j <= n && a[j].x == cur) j++; j--; if (j - i + 1 == max1) { int cnt = 0; rep(k, i, j) if (candidate.find(a[k].y) != candidate.end()) cnt++; if (cnt < tot) f = true; } } int ans = max1 + max2; if (!f) ans--; printf("%d\n", ans); #ifndef ONLINE_JUDGE cerr << "Exec Time: " << (clock() - TIME) / CLOCKS_PER_SEC << endl; #endif return 0; }
// I'll always miss you like a darling. #include <bits/stdc++.h> using namespace std; #define LL long long #define LD long double #define ull unsigned long long #define x first #define y second #define pb push_back #define pf push_front #define mp make_pair #define Pair pair<int, int> #define pLL pair<LL, LL> #define pii pair<double, double> #define LOWBIT(x) x & (-x) #define rep(i, a, b) for (int i = a; i <= b; i++) #define REP(i, a, b) for (int i = a; i >= b; i--) const int INF = 2e9; const LL LINF = 2e16; const int magic = 348; const int MOD = 1e9 + 7; const double eps = 1e-10; const double pi = acos(-1); struct fastio { static const int S = 1e7; char rbuf[S + 48], wbuf[S + 48]; int rpos, wpos, len; fastio() { rpos = len = wpos = 0; } inline char Getchar() { if (rpos == len) rpos = 0, len = fread(rbuf, 1, S, stdin); if (!len) return EOF; return rbuf[rpos++]; } template <class T> inline void Get(T &x) { char ch; bool f; T res; while (!isdigit(ch = Getchar()) && ch != '-') { } if (ch == '-') f = false, res = 0; else f = true, res = ch - '0'; while (isdigit(ch = Getchar())) res = res * 10 + ch - '0'; x = (f ? res : -res); } inline void getstring(char *s) { char ch; while ((ch = Getchar()) <= 32) { } for (; ch > 32; ch = Getchar()) *s++ = ch; *s = '\0'; } inline void flush() { fwrite(wbuf, 1, wpos, stdout); fflush(stdout); wpos = 0; } inline void Writechar(char ch) { if (wpos == S) flush(); wbuf[wpos++] = ch; } template <class T> inline void Print(T x, char ch) { char s[20]; int pt = 0; if (x == 0) s[++pt] = '0'; else { if (x < 0) Writechar('-'), x = -x; while (x) s[++pt] = '0' + x % 10, x /= 10; } while (pt) Writechar(s[pt--]); Writechar(ch); } inline void printstring(char *s) { int pt = 1; while (s[pt] != '\0') Writechar(s[pt++]); } } io; template <typename T> inline void check_max(T &x, T cmp) { x = max(x, cmp); } template <typename T> inline void check_min(T &x, T cmp) { x = min(x, cmp); } template <typename T> inline T myabs(T x) { return x >= 0 ? x : -x; } template <typename T> inline T gcd(T x, T y) { return y == 0 ? x : gcd(y, x % y); } inline int add(int x) { if (x >= MOD) x -= MOD; return x; } inline int add(int x, int MO) { if (x >= MO) x -= MO; return x; } inline int sub(int x) { if (x < 0) x += MOD; return x; } inline int sub(int x, int MO) { if (x < 0) x += MO; return x; } inline void Add(int &x, int y) { x = add(x + y); } inline void Add(int &x, int y, int MO) { x = add(x + y, MO); } inline void Sub(int &x, int y) { x = sub(x - y); } inline void Sub(int &x, int y, int MO) { x = sub(x - y, MO); } template <typename T> inline int quick_pow(int x, T y) { int res = 1; while (y) { if (y & 1) res = 1ll * res * x % MOD; x = 1ll * x * x % MOD; y >>= 1; } return res; } template <typename T> inline int quick_pow(int x, T y, int MO) { int res = 1; while (y) { if (y & 1) res = 1ll * res * x % MO; x = 1ll * x * x % MO; y >>= 1; } return res; } const int MAXN = 3e5; int r, c, n; struct node { int x, y; } a[MAXN + 48]; inline bool cmp_x(node x, node y) { return x.x < y.x; } inline bool cmp_y(node x, node y) { return x.y < y.y; } set<int> candidate; int tot; int main() { #ifndef ONLINE_JUDGE double TIME = clock(); freopen("a.in", "r", stdin); freopen("a.out", "w", stdout); cerr << "Running..." << endl; #endif scanf("%d%d%d", &r, &c, &n); rep(i, 1, n) scanf("%d%d", &a[i].x, &a[i].y); int max1 = 0, max2 = 0; sort(a + 1, a + n + 1, cmp_y); rep(i, 1, n) { int j = i, cur = a[i].y; while (j <= n && a[j].y == cur) j++; j--; if (j - i + 1 > max2) { max2 = j - i + 1; candidate.clear(); candidate.insert(cur); } else if (j - i + 1 == max2) candidate.insert(cur); i = j; } tot = int(candidate.size()); sort(a + 1, a + n + 1, cmp_x); rep(i, 1, n) { int j = i, cur = a[i].x; while (j <= n && a[j].x == cur) j++; j--; check_max(max1, j - i + 1); i = j; } bool f = false; rep(i, 1, n) { int j = i, cur = a[i].x; while (j <= n && a[j].x == cur) j++; j--; if (j - i + 1 == max1) { int cnt = 0; rep(k, i, j) if (candidate.find(a[k].y) != candidate.end()) cnt++; if (cnt < tot) f = true; } i = j; } int ans = max1 + max2; if (!f) ans--; printf("%d\n", ans); #ifndef ONLINE_JUDGE cerr << "Exec Time: " << (clock() - TIME) / CLOCKS_PER_SEC << endl; #endif return 0; }
insert
204
204
204
205
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> #define poi 201000 using namespace std; typedef long long ll; struct girl { int x, y; bool operator<(const girl &b) const { return (x ^ b.x) ? x < b.x : y < b.y; } } a[poi]; int b[poi], ans, h, w, n, tans; set<pair<int, int>> s; inline int re() { char x = getchar(); int k = 1, y = 0; while (x < '0' || x > '9') { if (x == '-') k = -1; x = getchar(); } while (x >= '0' && x <= '9') { y = (y << 3) + (y << 1) + x - '0'; x = getchar(); } return y * k; } void wr(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) wr(x / 10); putchar(x % 10 + '0'); } int lookfor(int st) { int x = a[st].x; for (int i = st;; i++) { if (a[i].x != x) break; s.erase(make_pair(b[a[i].y]--, a[i].y)); s.insert(make_pair(b[a[i].y], a[i].y)); } ans = (*--s.end()).first; for (int i = st;; i++) { if (a[i].x != x) return i; ans++; s.erase(make_pair(b[a[i].y]++, a[i].y)); s.insert(make_pair(b[a[i].y], a[i].y)); } } signed main() { // freopen("lca.in","r",stdin); // freopen("lca.out","w",stdout); h = re(), w = re(), n = re(); for (int i = 1; i <= n; i++) { a[i].x = re(), a[i].y = re(); b[a[i].y]++; } for (int i = 1; i <= w; i++) s.insert(make_pair(b[a[i].y], a[i].y)); sort(a + 1, a + n + 1); for (int i = 1; i <= n;) { i = lookfor(i); tans = max(ans, tans); } wr(tans); return 0; }
#include <bits/stdc++.h> #define poi 601000 using namespace std; typedef long long ll; struct girl { int x, y; bool operator<(const girl &b) const { return (x ^ b.x) ? x < b.x : y < b.y; } } a[poi]; int b[poi], ans, h, w, n, tans; set<pair<int, int>> s; inline int re() { char x = getchar(); int k = 1, y = 0; while (x < '0' || x > '9') { if (x == '-') k = -1; x = getchar(); } while (x >= '0' && x <= '9') { y = (y << 3) + (y << 1) + x - '0'; x = getchar(); } return y * k; } void wr(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) wr(x / 10); putchar(x % 10 + '0'); } int lookfor(int st) { int x = a[st].x; for (int i = st;; i++) { if (a[i].x != x) break; s.erase(make_pair(b[a[i].y]--, a[i].y)); s.insert(make_pair(b[a[i].y], a[i].y)); } ans = (*--s.end()).first; for (int i = st;; i++) { if (a[i].x != x) return i; ans++; s.erase(make_pair(b[a[i].y]++, a[i].y)); s.insert(make_pair(b[a[i].y], a[i].y)); } } signed main() { // freopen("lca.in","r",stdin); // freopen("lca.out","w",stdout); h = re(), w = re(), n = re(); for (int i = 1; i <= n; i++) { a[i].x = re(), a[i].y = re(); b[a[i].y]++; } for (int i = 1; i <= w; i++) s.insert(make_pair(b[a[i].y], a[i].y)); sort(a + 1, a + n + 1); for (int i = 1; i <= n;) { i = lookfor(i); tans = max(ans, tans); } wr(tans); return 0; }
replace
1
2
1
2
0
p02580
C++
Time Limit Exceeded
/* -*- coding: utf-8 -*- * * e.cc: E - Bomber */ #include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; /* constant */ const int MAX_H = 300000; const int MAX_W = 300000; const int MAX_M = 300000; /* typedef */ typedef vector<int> vi; typedef pair<int, int> pii; /* global variables */ pii ps[MAX_M]; int cs[MAX_M], ycs[MAX_H], xcs[MAX_W]; /* subroutines */ /* main */ int main() { int h, w, m; scanf("%d%d%d", &h, &w, &m); for (int i = 0; i < m; i++) { int y, x; scanf("%d%d", &y, &x); y--, x--; ps[i] = pii(y, x); } sort(ps, ps + m); int n = 0; for (int i = 0; i < m;) { int j = i + 1; while (j < m && ps[i] == ps[j]) j++; ps[n] = ps[i]; cs[n] = j - i; n++; i = j; } for (int i = 0; i < n; i++) { ycs[ps[i].first] += cs[i]; xcs[ps[i].second] += cs[i]; } // for (int i = 0; i < h; i++) printf("%d ", ycs[i]); putchar('\n'); // for (int i = 0; i < w; i++) printf("%d ", xcs[i]); putchar('\n'); int maxyc = -1, maxxc = -1; vi maxys, maxxs; for (int y = 0; y < h; y++) { if (maxyc < ycs[y]) maxyc = ycs[y], maxys.clear(), maxys.push_back(y); else if (maxyc == ycs[y]) maxys.push_back(y); } for (int x = 0; x < w; x++) { if (maxxc < xcs[x]) maxxc = xcs[x], maxxs.clear(), maxxs.push_back(x); else if (maxxc == xcs[x]) maxxs.push_back(x); } int maxc = 0; for (vi::iterator yit = maxys.begin(); yit != maxys.end(); yit++) for (vi::iterator xit = maxxs.begin(); xit != maxxs.end(); xit++) { int c = maxyc + maxxc; pii p(*yit, *xit); int k = lower_bound(ps, ps + n, p) - ps; if (k < n && ps[k] == p) c -= cs[k]; if (maxc < c) maxc = c; } printf("%d\n", maxc); return 0; }
/* -*- coding: utf-8 -*- * * e.cc: E - Bomber */ #include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; /* constant */ const int MAX_H = 300000; const int MAX_W = 300000; const int MAX_M = 300000; /* typedef */ typedef vector<int> vi; typedef pair<int, int> pii; /* global variables */ pii ps[MAX_M]; int cs[MAX_M], ycs[MAX_H], xcs[MAX_W]; /* subroutines */ /* main */ int main() { int h, w, m; scanf("%d%d%d", &h, &w, &m); for (int i = 0; i < m; i++) { int y, x; scanf("%d%d", &y, &x); y--, x--; ps[i] = pii(y, x); } sort(ps, ps + m); int n = 0; for (int i = 0; i < m;) { int j = i + 1; while (j < m && ps[i] == ps[j]) j++; ps[n] = ps[i]; cs[n] = j - i; n++; i = j; } for (int i = 0; i < n; i++) { ycs[ps[i].first] += cs[i]; xcs[ps[i].second] += cs[i]; } // for (int i = 0; i < h; i++) printf("%d ", ycs[i]); putchar('\n'); // for (int i = 0; i < w; i++) printf("%d ", xcs[i]); putchar('\n'); int maxyc = -1, maxxc = -1; vi maxys, maxxs; for (int y = 0; y < h; y++) { if (maxyc < ycs[y]) maxyc = ycs[y], maxys.clear(), maxys.push_back(y); else if (maxyc == ycs[y]) maxys.push_back(y); } for (int x = 0; x < w; x++) { if (maxxc < xcs[x]) maxxc = xcs[x], maxxs.clear(), maxxs.push_back(x); else if (maxxc == xcs[x]) maxxs.push_back(x); } int maxc = 0; for (vi::iterator yit = maxys.begin(); yit != maxys.end(); yit++) for (vi::iterator xit = maxxs.begin(); xit != maxxs.end(); xit++) { int c = maxyc + maxxc; pii p(*yit, *xit); int k = lower_bound(ps, ps + n, p) - ps; if (k >= n || ps[k] != p) { maxc = c; break; } c -= cs[k]; if (maxc < c) maxc = c; } printf("%d\n", maxc); return 0; }
replace
97
99
97
102
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); ++i) #define trav(a, x) for (auto &a : x) #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; const ll mod = 1000000007; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // head int main() { ios::sync_with_stdio(false); cin.tie(0); // find most common row, most common column, then set<pair<int, int>> ps; int r, c, m; cin >> r >> c >> m; vector<int> rows(r + 1); vector<int> cols(c + 1); for (int i = 0; i < m; i++) { int y, x; cin >> y >> x; rows[y]++; cols[x]++; ps.insert(mp(y, x)); } vector<int> indexRows; vector<int> indexCols; int bestRow = 0; int bestCol = 0; for (int i = 1; i <= r; i++) { if (rows[i] == bestRow) { indexRows.pb(i); } else if (rows[i] > bestRow) { indexRows.clear(); indexRows.pb(i); bestRow = rows[i]; } } for (int i = 1; i <= c; i++) { if (cols[i] == bestCol) { indexCols.pb(i); } else if (cols[i] > bestCol) { indexCols.clear(); indexCols.pb(i); bestCol = cols[i]; } } int ans = 0; trav(x, indexRows) { trav(y, indexCols) { if (ps.count(mp(x, y))) { ans = max(ans, bestRow + bestCol - 1); } else { ans = max(ans, bestRow + bestCol); } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); ++i) #define trav(a, x) for (auto &a : x) #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; const ll mod = 1000000007; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // head int main() { ios::sync_with_stdio(false); cin.tie(0); // find most common row, most common column, then set<pair<int, int>> ps; int r, c, m; cin >> r >> c >> m; vector<int> rows(r + 1); vector<int> cols(c + 1); for (int i = 0; i < m; i++) { int y, x; cin >> y >> x; rows[y]++; cols[x]++; ps.insert(mp(y, x)); } vector<int> indexRows; vector<int> indexCols; int bestRow = 0; int bestCol = 0; for (int i = 1; i <= r; i++) { if (rows[i] == bestRow) { indexRows.pb(i); } else if (rows[i] > bestRow) { indexRows.clear(); indexRows.pb(i); bestRow = rows[i]; } } for (int i = 1; i <= c; i++) { if (cols[i] == bestCol) { indexCols.pb(i); } else if (cols[i] > bestCol) { indexCols.clear(); indexCols.pb(i); bestCol = cols[i]; } } int ans = 0; trav(x, indexRows) { trav(y, indexCols) { if (ps.count(mp(x, y))) { ans = max(ans, bestRow + bestCol - 1); } else { ans = max(ans, bestRow + bestCol); cout << ans << endl; return 0; } } } cout << ans << endl; return 0; }
insert
70
70
70
72
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int N = 300004; int cnth[N], cntw[N], x[N], y[N]; map<int, bool> mp[N]; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int h, w, m; cin >> h >> w >> m; for (int i = 0; i < m; i++) { cin >> x[i] >> y[i]; mp[x[i]][y[i]] = true; cnth[x[i]]++, cntw[y[i]]++; } int mxh = 0, mxw = 0; for (int i = 0; i < N; i++) { mxh = max(mxh, cnth[i]); mxw = max(mxw, cntw[i]); } vector<int> hall, wall; for (int i = 0; i < N; i++) { if (cnth[i] == mxh) { hall.push_back(i); } if (cntw[i] == mxw) { wall.push_back(i); } } int cnt = 0, mx = 0; for (int i = 0; i < hall.size(); i++) { for (int j = 0; j < wall.size(); j++) { mx = max(mx, mxh + mxw - mp[hall[i]][wall[j]]); } } cout << mx; }
#include <bits/stdc++.h> using namespace std; const int N = 300004; int cnth[N], cntw[N], x[N], y[N]; map<int, bool> mp[N]; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int h, w, m; cin >> h >> w >> m; for (int i = 0; i < m; i++) { cin >> x[i] >> y[i]; mp[x[i]][y[i]] = true; cnth[x[i]]++, cntw[y[i]]++; } int mxh = 0, mxw = 0; for (int i = 0; i < N; i++) { mxh = max(mxh, cnth[i]); mxw = max(mxw, cntw[i]); } vector<int> hall, wall; for (int i = 0; i < N; i++) { if (cnth[i] == mxh) { hall.push_back(i); } if (cntw[i] == mxw) { wall.push_back(i); } } if (hall.size() * wall.size() > m) { cout << mxh + mxw << endl; return 0; } int cnt = 0, mx = 0; for (int i = 0; i < hall.size(); i++) { for (int j = 0; j < wall.size(); j++) { mx = max(mx, mxh + mxw - mp[hall[i]][wall[j]]); } } cout << mx; }
insert
33
33
33
37
TLE
p02580
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef int itn; const ll LINF = 1e18; const int INF = 1e9; // マクロ定義 #define vvint(vec, n, m, l) \ vector<vector<int>> vec(n, vector<int>(m, l)); // lで初期化 #define vvll(vec, n, m, l) vector<vector<ll>> vec(n, vector<ll>(m, l)); #define vint vector<int> #define pint pair<int, int> #define rep(i, a) for (ll i = 0; i < (a); i++) #define all(x) (x).begin(), (x).end() #define debug system("pause") // デバッグ用 #define ret return 0 template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using Graph = vector<vector<ll>>; #define ketasitei setprecision(15) // 15桁表示 const ll MOD = 1000000007; const double PI = 3.1415926535897932; int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll h, w, m; cin >> h >> w >> m; vector<ll> x(m), y(m); vector<ll> xx(h, 0), yy(w, 0); rep(i, m) { cin >> x[i] >> y[i]; xx[x[i] - 1]++; yy[y[i] - 1]++; } ll maxx = 0, maxy = 0; rep(i, h) { if (maxx < xx[i]) { maxx = xx[i]; } } ll kohox = 0; rep(i, h) { if (maxx == x[i]) kohox++; } rep(i, w) { if (maxy < yy[i]) maxy = yy[i]; } ll kohoy = 0; rep(i, w) { if (maxy == yy[i]) kohoy++; } ll ans = kohox * kohoy; rep(i, m) { if (maxx + maxy == xx[x[i] - 1] + yy[y[i] - 1]) ans--; } if (ans) cout << maxx + maxy << endl; else cout << maxx + maxy - 1 << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef int itn; const ll LINF = 1e18; const int INF = 1e9; // マクロ定義 #define vvint(vec, n, m, l) \ vector<vector<int>> vec(n, vector<int>(m, l)); // lで初期化 #define vvll(vec, n, m, l) vector<vector<ll>> vec(n, vector<ll>(m, l)); #define vint vector<int> #define pint pair<int, int> #define rep(i, a) for (ll i = 0; i < (a); i++) #define all(x) (x).begin(), (x).end() #define debug system("pause") // デバッグ用 #define ret return 0 template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using Graph = vector<vector<ll>>; #define ketasitei setprecision(15) // 15桁表示 const ll MOD = 1000000007; const double PI = 3.1415926535897932; int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll h, w, m; cin >> h >> w >> m; vector<ll> x(m), y(m); vector<ll> xx(h, 0), yy(w, 0); rep(i, m) { cin >> x[i] >> y[i]; xx[x[i] - 1]++; yy[y[i] - 1]++; } ll maxx = 0, maxy = 0; rep(i, h) { if (maxx < xx[i]) { maxx = xx[i]; } } ll kohox = 0; rep(i, h) { if (maxx == xx[i]) kohox++; } rep(i, w) { if (maxy < yy[i]) maxy = yy[i]; } ll kohoy = 0; rep(i, w) { if (maxy == yy[i]) kohoy++; } ll ans = kohox * kohoy; rep(i, m) { if (maxx + maxy == xx[x[i] - 1] + yy[y[i] - 1]) ans--; } if (ans) cout << maxx + maxy << endl; else cout << maxx + maxy - 1 << endl; return 0; }
replace
80
81
80
81
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5 + 5; ll n, m; map<int, int> x, y; struct node { int x, y; }; node a[maxn]; int main() { std::ios::sync_with_stdio(false); cin >> n >> m; int t; cin >> t; for (int i = 1; i <= t; i++) { cin >> a[i].x >> a[i].y; x[a[i].x]++; y[a[i].y]++; } int maxx = 0, maxy = 0; for (int i = 1; i <= t; i++) maxx = max(maxx, x[a[i].x]), maxy = max(maxy, y[a[i].y]); if (x.size() == 1 || y.size() == 1) { cout << t << endl; } else { if (maxx == 1 && maxy == 1) { cout << 2 << endl; } else { ll x1 = 0, x2 = 0, y1 = 0, y2 = 0; map<int, int>::iterator it; for (it = x.begin(); it != x.end(); it++) { if (it->second == maxx) x1++; else if (it->second == maxx - 1) x2++; } for (it = y.begin(); it != y.end(); it++) { if (it->second == maxy) y1++; else if (it->second == maxy - 1) y2++; } ll ans1 = 0, ans2 = 0; ans1 = x1 * y1; ans2 = x2 * y1 + x1 * y2; for (int i = 1; i <= t; i++) { if (maxx + maxy == x[a[i].x] + y[a[i].y]) { ans1--; ans2++; } else if (maxx + maxy - 1 == x[a[i].x] + y[a[i].y]) { ans2--; } } if (ans1) { cout << maxx + maxy << endl; } else { cout << maxx + maxy - 1 << endl; } } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 5e5 + 5; ll n, m; map<int, int> x, y; struct node { int x, y; }; node a[maxn]; int main() { std::ios::sync_with_stdio(false); cin >> n >> m; int t; cin >> t; for (int i = 1; i <= t; i++) { cin >> a[i].x >> a[i].y; x[a[i].x]++; y[a[i].y]++; } int maxx = 0, maxy = 0; for (int i = 1; i <= t; i++) maxx = max(maxx, x[a[i].x]), maxy = max(maxy, y[a[i].y]); if (x.size() == 1 || y.size() == 1) { cout << t << endl; } else { if (maxx == 1 && maxy == 1) { cout << 2 << endl; } else { ll x1 = 0, x2 = 0, y1 = 0, y2 = 0; map<int, int>::iterator it; for (it = x.begin(); it != x.end(); it++) { if (it->second == maxx) x1++; else if (it->second == maxx - 1) x2++; } for (it = y.begin(); it != y.end(); it++) { if (it->second == maxy) y1++; else if (it->second == maxy - 1) y2++; } ll ans1 = 0, ans2 = 0; ans1 = x1 * y1; ans2 = x2 * y1 + x1 * y2; for (int i = 1; i <= t; i++) { if (maxx + maxy == x[a[i].x] + y[a[i].y]) { ans1--; ans2++; } else if (maxx + maxy - 1 == x[a[i].x] + y[a[i].y]) { ans2--; } } if (ans1) { cout << maxx + maxy << endl; } else { cout << maxx + maxy - 1 << endl; } } } }
replace
3
4
3
4
0
p02580
C++
Runtime Error
#include <algorithm> #include <bitset> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; using vll = vector<long long>; using sll = set<long long>; const long long ll_max = 9223372036854775807; const long long ll_min = -9223372036854775807; const int int_max = 2147483647; template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> map<T, T> getPrimeFactor(T n) { map<T, T> res; for (T i = 2; i * i <= n; ++i) { while (n % i == 0) { res[i]++; n /= i; } } if (n != 1) res[n] = 1; return res; } template <typename T> bool IsPrimeNumber(T num) { if (num <= 2) return true; else if (num % 2 == 0) return false; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // セグメント木 学習中 template <class T> class SegmentTree { int n; // 葉の数 vector<T> data; // データを格納するvector T def; // 初期値かつ単位元 function<T(T, T)> operation; // 区間クエリで使う処理 function<T(T, T)> update; // 点更新で使う処理 // 区間[a,b)の総和。ノードk=[l,r)に着目している。 T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; // 交差しない if (a <= l && r <= b) return data[k]; // a,l,r,bの順で完全に含まれる else { return operation( _query(a, b, 2 * k + 1, l, (l + r) / 2), _query(a, b, 2 * k + 2, (l + r) / 2, r)); // 左右を分割して再帰 } } public: // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数, // _update:更新関数 SegmentTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector<T>(2 * n - 1, def); } // 場所i(0-indexed)の値をxで更新 void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } // [a, b)の区間クエリを実行 T query(int a, int b) { return _query(a, b, 0, 0, n); } // 添字でアクセス T operator[](int i) { return data[i + n - 1]; } }; // 繰り返し二乗法 ll pow2(ll n, ll p, ll mod) { if (p == 0 || n == 1) { return 1; } else { ll ret = pow2(n * n % mod, p / 2, mod); if (p % 2 == 1) { ret *= n; } return ret % mod; } } #define rep(i, s, e) for (ll i = s; i < e; i++) #define repeq(i, s, e) for (ll i = s; i <= e; i++) int main() { ll H, W, M; cin >> H >> W >> M; map<ll, ll> r, c; vector<vector<bool>> dic(H + 1, vector<bool>(W + 1, false)); rep(i, 0, M) { ll h, w; cin >> h >> w; r[h]++; c[w]++; dic[h][w] = true; } ll max_val = 0; vll rp; for (auto x : r) { if (max_val == x.second) { rp.push_back(x.first); } else if (max_val < x.second) { max_val = r[x.first]; rp = {x.first}; } } max_val = 0; vll cp; for (auto y : c) { if (max_val == y.second) { cp.push_back(y.first); } else if (max_val < y.second) { max_val = y.second; cp = {y.first}; } } ll ans = 0; for (auto x : rp) { for (auto y : cp) { if (dic[x][y]) { ans = r[x] + c[y] - 1; } else { cout << r[x] + c[y] << endl; return 0; } } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; using vll = vector<long long>; using sll = set<long long>; const long long ll_max = 9223372036854775807; const long long ll_min = -9223372036854775807; const int int_max = 2147483647; template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> map<T, T> getPrimeFactor(T n) { map<T, T> res; for (T i = 2; i * i <= n; ++i) { while (n % i == 0) { res[i]++; n /= i; } } if (n != 1) res[n] = 1; return res; } template <typename T> bool IsPrimeNumber(T num) { if (num <= 2) return true; else if (num % 2 == 0) return false; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // セグメント木 学習中 template <class T> class SegmentTree { int n; // 葉の数 vector<T> data; // データを格納するvector T def; // 初期値かつ単位元 function<T(T, T)> operation; // 区間クエリで使う処理 function<T(T, T)> update; // 点更新で使う処理 // 区間[a,b)の総和。ノードk=[l,r)に着目している。 T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; // 交差しない if (a <= l && r <= b) return data[k]; // a,l,r,bの順で完全に含まれる else { return operation( _query(a, b, 2 * k + 1, l, (l + r) / 2), _query(a, b, 2 * k + 2, (l + r) / 2, r)); // 左右を分割して再帰 } } public: // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数, // _update:更新関数 SegmentTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector<T>(2 * n - 1, def); } // 場所i(0-indexed)の値をxで更新 void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } // [a, b)の区間クエリを実行 T query(int a, int b) { return _query(a, b, 0, 0, n); } // 添字でアクセス T operator[](int i) { return data[i + n - 1]; } }; // 繰り返し二乗法 ll pow2(ll n, ll p, ll mod) { if (p == 0 || n == 1) { return 1; } else { ll ret = pow2(n * n % mod, p / 2, mod); if (p % 2 == 1) { ret *= n; } return ret % mod; } } #define rep(i, s, e) for (ll i = s; i < e; i++) #define repeq(i, s, e) for (ll i = s; i <= e; i++) int main() { ll H, W, M; cin >> H >> W >> M; map<ll, ll> r, c; map<ll, map<ll, bool>> dic; rep(i, 0, M) { ll h, w; cin >> h >> w; r[h]++; c[w]++; dic[h][w] = true; } ll max_val = 0; vll rp; for (auto x : r) { if (max_val == x.second) { rp.push_back(x.first); } else if (max_val < x.second) { max_val = r[x.first]; rp = {x.first}; } } max_val = 0; vll cp; for (auto y : c) { if (max_val == y.second) { cp.push_back(y.first); } else if (max_val < y.second) { max_val = y.second; cp = {y.first}; } } ll ans = 0; for (auto x : rp) { for (auto y : cp) { if (dic[x][y]) { ans = r[x] + c[y] - 1; } else { cout << r[x] + c[y] << endl; return 0; } } } cout << ans << endl; return 0; }
replace
142
143
142
143
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; /* s.find_by_order(k) ---> returns iterator to the element at index(from 0) k s.order_of_key(val) ---> number of elements that are strictly smaller than the given value */ typedef long long int ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> vi; typedef vector<long long int> vl; typedef vector<vector<int>> vvi; typedef vector<vector<long long int>> vvl; typedef pair<int, int> pii; typedef pair<long long int, long long int> pll; typedef vector<pair<int, int>> vii; typedef vector<pair<long long int, long long int>> vll; #define fastIO() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define test() \ long long int tc; \ cin >> tc; \ cin.ignore(); \ while (tc--) #define ff first #define ss second #define pb push_back #define pf push_front #define mp make_pair #define MOD 1000000007 #define SMOD 998244353 #define HASH 18014398241046527 #define pq priority_queue #define all(x) x.begin(), x.end() #define SP(x) setprecision(x) #define sp " " #define inp(a) \ ll a; \ cin >> a; \ cin.ignore() #define inps(a, b) \ ll a, b; \ cin >> a >> b; \ cin.ignore() #define out(a) cout << SP(20) << a << '\n' #define outs(a, b) cout << SP(20) << a << " " << b << '\n' #define ins insert #define er erase #define lb lower_bound #define ub upper_bound #define printclock \ cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n"; #define inpa(a, n) \ ll a[n]; \ for (int i = 0; i < n; i++) { \ cin >> a[i]; \ } #define inpv(a, n) \ vl a; \ for (int i = 0; i < n; i++) { \ inp(x); \ a.pb(x); \ } #define outa(a, n) \ for (int i = 0; i < n; i++) { \ cout << a[i] << " "; \ } \ cout << '\n'; #define outv(v) \ for (auto i : v) { \ cout << i << " "; \ } \ cout << '\n'; set<char> vow = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}; ll xpow(ll n, ll m) { if (m == 0) { return 1; } else { ll x = xpow(n, m / 2); if (m & 1) { return x * x * n; } else { return x * x; } } } ll xmod(ll a, ll m) { return (((a % m) + m) % m); } ll xmodpow(ll n, ll m, ll y) { if (m == 0) { return 1; } else { ll x = xmodpow(n, m / 2, y); if (m & 1) { return xmod((xmod((xmod(x, y) * xmod(x, y)), y) * xmod(n, y)), y); } else { return xmod((xmod(x, y) * xmod(x, y)), y); } } } template <typename T> ll SIZEOF(T a) { return (ll)a.size(); } ll xlcm(ll a, ll b) { return (a / __gcd(a, b)) * b; } ll dx[] = {1, 0, -1, 0}; ll dy[] = {0, 1, 0, -1}; const int N = 100005; void SOLVE() { ll n, m, num; cin >> n >> m >> num; map<ll, ll> row; map<ll, ll> col; map<pll, bool> vis; for (ll i = 1; i <= num; i++) { ll x, y; cin >> x >> y; row[x]++; col[y]++; vis[{x, y}] = 1; } vll a, b; for (auto i : row) { a.pb({i.ss, i.ff}); } for (auto i : col) { b.pb({i.ss, i.ff}); } sort(all(a)); sort(all(b)); reverse(all(a)); reverse(all(b)); ll x = a[0].ff; ll y = b[0].ff; vector<ll> A, B; for (auto i : a) { if (i.ff == x) { A.pb(i.ss); } } for (auto i : b) { if (i.ff == y) { B.pb(i.ss); } } ll ans = x + y; bool check = 1; for (auto i : A) { for (auto j : B) { if (!vis[{i, j}]) { check = 0; } } } if (check) { ans--; } cout << ans << '\n'; } int main() { fastIO(); // #ifndef ONLINE_JUDGE // freopen("i.txt", "r", stdin); // freopen("o.txt", "w", stdout); // #endif ll TC = 1; // cin >> TC; for (ll tc1 = 1; tc1 <= TC; tc1++) { // cout << "Case #" << tc1 << ": "; SOLVE(); } printclock; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; /* s.find_by_order(k) ---> returns iterator to the element at index(from 0) k s.order_of_key(val) ---> number of elements that are strictly smaller than the given value */ typedef long long int ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> vi; typedef vector<long long int> vl; typedef vector<vector<int>> vvi; typedef vector<vector<long long int>> vvl; typedef pair<int, int> pii; typedef pair<long long int, long long int> pll; typedef vector<pair<int, int>> vii; typedef vector<pair<long long int, long long int>> vll; #define fastIO() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define test() \ long long int tc; \ cin >> tc; \ cin.ignore(); \ while (tc--) #define ff first #define ss second #define pb push_back #define pf push_front #define mp make_pair #define MOD 1000000007 #define SMOD 998244353 #define HASH 18014398241046527 #define pq priority_queue #define all(x) x.begin(), x.end() #define SP(x) setprecision(x) #define sp " " #define inp(a) \ ll a; \ cin >> a; \ cin.ignore() #define inps(a, b) \ ll a, b; \ cin >> a >> b; \ cin.ignore() #define out(a) cout << SP(20) << a << '\n' #define outs(a, b) cout << SP(20) << a << " " << b << '\n' #define ins insert #define er erase #define lb lower_bound #define ub upper_bound #define printclock \ cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n"; #define inpa(a, n) \ ll a[n]; \ for (int i = 0; i < n; i++) { \ cin >> a[i]; \ } #define inpv(a, n) \ vl a; \ for (int i = 0; i < n; i++) { \ inp(x); \ a.pb(x); \ } #define outa(a, n) \ for (int i = 0; i < n; i++) { \ cout << a[i] << " "; \ } \ cout << '\n'; #define outv(v) \ for (auto i : v) { \ cout << i << " "; \ } \ cout << '\n'; set<char> vow = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}; ll xpow(ll n, ll m) { if (m == 0) { return 1; } else { ll x = xpow(n, m / 2); if (m & 1) { return x * x * n; } else { return x * x; } } } ll xmod(ll a, ll m) { return (((a % m) + m) % m); } ll xmodpow(ll n, ll m, ll y) { if (m == 0) { return 1; } else { ll x = xmodpow(n, m / 2, y); if (m & 1) { return xmod((xmod((xmod(x, y) * xmod(x, y)), y) * xmod(n, y)), y); } else { return xmod((xmod(x, y) * xmod(x, y)), y); } } } template <typename T> ll SIZEOF(T a) { return (ll)a.size(); } ll xlcm(ll a, ll b) { return (a / __gcd(a, b)) * b; } ll dx[] = {1, 0, -1, 0}; ll dy[] = {0, 1, 0, -1}; const int N = 100005; void SOLVE() { ll n, m, num; cin >> n >> m >> num; map<ll, ll> row; map<ll, ll> col; map<pll, bool> vis; for (ll i = 1; i <= num; i++) { ll x, y; cin >> x >> y; row[x]++; col[y]++; vis[{x, y}] = 1; } vll a, b; for (auto i : row) { a.pb({i.ss, i.ff}); } for (auto i : col) { b.pb({i.ss, i.ff}); } sort(all(a)); sort(all(b)); reverse(all(a)); reverse(all(b)); ll x = a[0].ff; ll y = b[0].ff; vector<ll> A, B; for (auto i : a) { if (i.ff == x) { A.pb(i.ss); } } for (auto i : b) { if (i.ff == y) { B.pb(i.ss); } } ll ans = x + y; bool check = 1; for (auto i : A) { for (auto j : B) { if (!vis[{i, j}]) { check = 0; break; } } } if (check) { ans--; } cout << ans << '\n'; } int main() { fastIO(); // #ifndef ONLINE_JUDGE // freopen("i.txt", "r", stdin); // freopen("o.txt", "w", stdout); // #endif ll TC = 1; // cin >> TC; for (ll tc1 = 1; tc1 <= TC; tc1++) { // cout << "Case #" << tc1 << ": "; SOLVE(); } printclock; }
insert
159
159
159
160
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define endl '\n' #define rep(i, n) for (int i = 0; i < n; i++) #define all(v) v.begin(), v.end() #define F first #define S second ll n, m, m1; ll solve() { cin >> n >> m >> m1; map<ll, vector<pair<ll, ll>>> mr, mc; map<pair<ll, ll>, bool> m2; for (ll i = 0; i < m1; i++) { ll x, y; cin >> x >> y; x--; y--; m2[{x, y}] = true; mr[x].push_back({x, y}); mc[y].push_back({x, y}); } vector<ll> vr, vc; ll maxr = 0; ll maxc = 0; for (auto x : mr) { maxr = max(maxr, (ll)x.second.size()); } for (auto x : mc) { maxc = max(maxc, (ll)x.second.size()); } for (auto x : mr) { if ((ll)x.second.size() == maxr) { vr.push_back(x.first); } } for (auto x : mc) { if ((ll)x.second.size() == maxc) { vc.push_back(x.first); } } bool temp = false; for (ll i = 0; i < vr.size(); i++) { for (ll j = 0; j < vc.size(); j++) { if (m2[{vr[i], vc[j]}] == 0) { temp = true; break; } } } if (temp) { cout << maxr + maxc << endl; } else { cout << maxr + maxc - 1 << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t = 1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define endl '\n' #define rep(i, n) for (int i = 0; i < n; i++) #define all(v) v.begin(), v.end() #define F first #define S second ll n, m, m1; void solve() { cin >> n >> m >> m1; map<ll, vector<pair<ll, ll>>> mr, mc; map<pair<ll, ll>, bool> m2; for (ll i = 0; i < m1; i++) { ll x, y; cin >> x >> y; x--; y--; m2[{x, y}] = true; mr[x].push_back({x, y}); mc[y].push_back({x, y}); } vector<ll> vr, vc; ll maxr = 0; ll maxc = 0; for (auto x : mr) { maxr = max(maxr, (ll)x.second.size()); } for (auto x : mc) { maxc = max(maxc, (ll)x.second.size()); } for (auto x : mr) { if ((ll)x.second.size() == maxr) { vr.push_back(x.first); } } for (auto x : mc) { if ((ll)x.second.size() == maxc) { vc.push_back(x.first); } } bool temp = false; for (ll i = 0; i < vr.size(); i++) { for (ll j = 0; j < vc.size(); j++) { if (m2[{vr[i], vc[j]}] == 0) { temp = true; break; } } } if (temp) { cout << maxr + maxc << endl; } else { cout << maxr + maxc - 1 << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t = 1; while (t--) { solve(); } }
replace
9
10
9
10
0
p02580
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (a); i > (b); i--) #define ALL(a) (a).begin(), (a).end() const int SIZE = 300000; int main() { int H, W, M; cin >> H >> W >> M; int hc[SIZE] = {}, wc[SIZE] = {}; pii hw[SIZE] = {}; REP(i, M) { int h, w; cin >> h >> w; h--; w--; hc[h]++; wc[w]++; hw[i] = {h, w}; } vector<pii> phc, pwc; REP(i, SIZE) { phc.push_back({hc[i], i}); pwc.push_back({wc[i], i}); } sort(ALL(phc), greater<pii>()); sort(ALL(pwc), greater<pii>()); int hcnt, wcnt; vector<int> ht, wt; REP(i, SIZE) { hcnt = phc[i].first; ht.push_back(phc[i].second); if (i == SIZE - 1) break; if (phc[i].first != phc[i + 1].first) break; } REP(i, SIZE) { wcnt = pwc[i].first; wt.push_back(pwc[i].second); if (i == SIZE - 1) break; if (pwc[i].first != pwc[i + 1].first) break; } sort(ALL(ht)); sort(ALL(wt)); int cnt = 0; REP(i, M) { int h, w; h = hw[i].first; w = hw[i].second; if (find(ALL(ht), h) != ht.end() && find(ALL(wt), w) != wt.end()) cnt++; } ll ans = hcnt + wcnt; if (cnt == ht.size() * wt.size()) ans--; cout << ans << endl; }
#include <algorithm> #include <iostream> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (a); i > (b); i--) #define ALL(a) (a).begin(), (a).end() const int SIZE = 300000; int main() { int H, W, M; cin >> H >> W >> M; int hc[SIZE] = {}, wc[SIZE] = {}; pii hw[SIZE] = {}; REP(i, M) { int h, w; cin >> h >> w; h--; w--; hc[h]++; wc[w]++; hw[i] = {h, w}; } vector<pii> phc, pwc; REP(i, SIZE) { phc.push_back({hc[i], i}); pwc.push_back({wc[i], i}); } sort(ALL(phc), greater<pii>()); sort(ALL(pwc), greater<pii>()); int hcnt, wcnt; vector<int> ht, wt; REP(i, SIZE) { hcnt = phc[i].first; ht.push_back(phc[i].second); if (i == SIZE - 1) break; if (phc[i].first != phc[i + 1].first) break; } REP(i, SIZE) { wcnt = pwc[i].first; wt.push_back(pwc[i].second); if (i == SIZE - 1) break; if (pwc[i].first != pwc[i + 1].first) break; } sort(ALL(ht)); sort(ALL(wt)); int cnt = 0; REP(i, M) { int h, w; h = hw[i].first; w = hw[i].second; if (binary_search(ALL(ht), h) && binary_search(ALL(wt), w)) cnt++; } ll ans = hcnt + wcnt; if (cnt == ht.size() * wt.size()) ans--; cout << ans << endl; }
replace
67
68
67
68
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define froop1(a, n) for (int i = a; i < n; i++) #define froop2(a, n) for (int i = a; i > n; i--) #define ll long long #define pq(name, type) priority_queue<type> name #define vec(name, type, length, value) vector<type> name(length, value) #define vec2(name, type, length, width, value) \ vector<vector<type>> name(length, vector<type>(width, value)); int main() { ll H, W, M; cin >> H >> W >> M; vector<ll> h; vector<ll> w; vector<ll> Wid(W, 0); vector<ll> Hei(H, 0); ll hmax = 0, wmax = 0; ll c1 = 0, c2 = 0; froop1(0, M) { ll a, b; cin >> a >> b; h.push_back(a); w.push_back(b); Wid.at(b - 1)++; Hei.at(a - 1)++; if (hmax < Hei.at(a - 1)) { hmax = Hei.at(a - 1); c1 = 1; } else if (hmax == Hei.at(a - 1)) { c1++; } if (wmax < Wid.at(b - 1)) { wmax = Wid.at(b - 1); c2 = 1; } else if (wmax == Wid.at(b - 1)) { c2++; } } ll pat = c1 * c2; int sw = 0; while (h.size() != 0 && w.size() != 0) { ll n = h.at(0) - 1; ll m = w.at(0) - 1; h.erase(h.begin()); w.erase(w.begin()); if (Wid.at(m) == wmax && Hei.at(n) == hmax) pat--; } if (pat == 0) { cout << hmax + wmax - 1 << endl; } else { cout << hmax + wmax << endl; } }
#include <bits/stdc++.h> using namespace std; #define froop1(a, n) for (int i = a; i < n; i++) #define froop2(a, n) for (int i = a; i > n; i--) #define ll long long #define pq(name, type) priority_queue<type> name #define vec(name, type, length, value) vector<type> name(length, value) #define vec2(name, type, length, width, value) \ vector<vector<type>> name(length, vector<type>(width, value)); int main() { ll H, W, M; cin >> H >> W >> M; vector<ll> h; vector<ll> w; vector<ll> Wid(W, 0); vector<ll> Hei(H, 0); ll hmax = 0, wmax = 0; ll c1 = 0, c2 = 0; froop1(0, M) { ll a, b; cin >> a >> b; h.push_back(a); w.push_back(b); Wid.at(b - 1)++; Hei.at(a - 1)++; if (hmax < Hei.at(a - 1)) { hmax = Hei.at(a - 1); c1 = 1; } else if (hmax == Hei.at(a - 1)) { c1++; } if (wmax < Wid.at(b - 1)) { wmax = Wid.at(b - 1); c2 = 1; } else if (wmax == Wid.at(b - 1)) { c2++; } } ll pat = c1 * c2; int sw = 0; for (int i = 0; i < M; i++) { ll n = h.at(i) - 1; ll m = w.at(i) - 1; if (Wid.at(m) == wmax && Hei.at(n) == hmax) pat--; } if (pat == 0) { cout << hmax + wmax - 1 << endl; } else { cout << hmax + wmax << endl; } }
replace
44
49
44
47
TLE
p02580
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; using P = pair<int, int>; typedef long long ll; int main() { int h, w, n; cin >> h >> w >> n; vector<int> hs(h), ws(w); set<P> s; for (int i = 0; i < n; i++) { int r, c; cin >> r >> c; r--; c--; hs[r]++; ws[c]++; s.emplace(r, c); } int mh = 0, mw = 0; for (int i = 0; i < h; i++) { mh = max(mh, hs[i]); } for (int i = 0; i < w; i++) { mw = max(mw, ws[i]); } vector<int> is, js; for (int i = 0; i < h; i++) { if (mh == hs[i]) { is.push_back(i); } } for (int i = 0; i < w; i++) { if (mw == ws[i]) { js.push_back(i); } } int ans = mh + mw; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s.count(P(is[i], js[j]))) { continue; } cout << ans << endl; return 0; } } --ans; cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; using P = pair<int, int>; typedef long long ll; int main() { int h, w, n; cin >> h >> w >> n; vector<int> hs(h), ws(w); set<P> s; for (int i = 0; i < n; i++) { int r, c; cin >> r >> c; r--; c--; hs[r]++; ws[c]++; s.emplace(r, c); } int mh = 0, mw = 0; for (int i = 0; i < h; i++) { mh = max(mh, hs[i]); } for (int i = 0; i < w; i++) { mw = max(mw, ws[i]); } vector<int> is, js; for (int i = 0; i < h; i++) { if (mh == hs[i]) { is.push_back(i); } } for (int i = 0; i < w; i++) { if (mw == ws[i]) { js.push_back(i); } } int ans = mh + mw; for (int i = 0; i < is.size(); i++) { for (int j = 0; j < js.size(); j++) { if (s.count(P(is[i], js[j]))) { continue; } cout << ans << endl; return 0; } } --ans; cout << ans << endl; return 0; }
replace
45
47
45
47
0
p02580
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; #define endl "\n" typedef long long int ll; #define f first #define s second inline void fastio() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } inline void setPrecision(int n) { cout.precision(n); } // DEBUG #define dbg(x) cerr << (#x) << ": " << x << endl #define dbgV(x) \ cerr << (#x) << ": "; \ for (auto it : x) \ cerr << it << " "; \ cerr << endl; #define dbgS(x) \ cerr << (#x) << ": "; \ for (auto it : x) \ cerr << it << " "; \ cerr << endl; #define dbgM(x) \ cerr << (#x) << ": "; \ for (auto it : x) \ cerr << "[" << it.f << ", " << it.s << "] "; \ cerr << endl; #define dbg2D(x) \ cerr << (#x) << ": \n"; \ for (auto y : x) { \ for (auto it : y) \ cerr << it << " "; \ cerr << endl; \ } \ cerr << endl; #define dbgA(x, n) \ cerr << (#x) << ": "; \ for (int i = 0; i < n; ++i) \ cerr << x[i] << " "; \ cerr << endl; #define dbgVP(x) \ cerr << (#x) << ": "; \ for (auto it : x) \ cerr << "[" << it.f << ", " << it.s << "] "; \ cerr << endl; ll INF = 1e10; int MOD = 1e9 + 7; int main() { fastio(); int h, w, m; cin >> h >> w >> m; map<int, int> x, y; set<pair<int, int>> t; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; x[a]++; y[b]++; t.insert({a, b}); } int mx = 0; for (auto it : x) { mx = max(mx, it.s); } int my = 0; for (auto it : y) { my = max(my, it.s); } set<pair<int, int>> px, py; for (auto it : x) if (it.s == mx) px.insert({it.f, it.s}); for (auto it : y) { if (it.s == my) py.insert({it.f, it.s}); } int ans = 0; for (auto it1 : px) { for (auto it2 : py) { ans = max(ans, it1.s + it2.s - (int)t.count({it1.f, it2.f})); } } cout << ans; return 0; } /* */
#include "bits/stdc++.h" using namespace std; #define endl "\n" typedef long long int ll; #define f first #define s second inline void fastio() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } inline void setPrecision(int n) { cout.precision(n); } // DEBUG #define dbg(x) cerr << (#x) << ": " << x << endl #define dbgV(x) \ cerr << (#x) << ": "; \ for (auto it : x) \ cerr << it << " "; \ cerr << endl; #define dbgS(x) \ cerr << (#x) << ": "; \ for (auto it : x) \ cerr << it << " "; \ cerr << endl; #define dbgM(x) \ cerr << (#x) << ": "; \ for (auto it : x) \ cerr << "[" << it.f << ", " << it.s << "] "; \ cerr << endl; #define dbg2D(x) \ cerr << (#x) << ": \n"; \ for (auto y : x) { \ for (auto it : y) \ cerr << it << " "; \ cerr << endl; \ } \ cerr << endl; #define dbgA(x, n) \ cerr << (#x) << ": "; \ for (int i = 0; i < n; ++i) \ cerr << x[i] << " "; \ cerr << endl; #define dbgVP(x) \ cerr << (#x) << ": "; \ for (auto it : x) \ cerr << "[" << it.f << ", " << it.s << "] "; \ cerr << endl; ll INF = 1e10; int MOD = 1e9 + 7; int main() { fastio(); int h, w, m; cin >> h >> w >> m; map<int, int> x, y; set<pair<int, int>> t; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; x[a]++; y[b]++; t.insert({a, b}); } int mx = 0; for (auto it : x) { mx = max(mx, it.s); } int my = 0; for (auto it : y) { my = max(my, it.s); } set<pair<int, int>> px, py; for (auto it : x) if (it.s == mx) px.insert({it.f, it.s}); for (auto it : y) { if (it.s == my) py.insert({it.f, it.s}); } int ans = 0; for (auto it1 : px) { for (auto it2 : py) { ans = max(ans, it1.s + it2.s - (int)t.count({it1.f, it2.f})); if (ans == it1.s + it2.s) break; } } cout << ans; return 0; } /* */
insert
92
92
92
94
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int h, w, m; cin >> h >> w >> m; int mxr = -1, mxc = -1; vector<vector<int>> row(h), colum(w); vector<int> mxh, mxw; rep(i, m) { int hi, wi; cin >> hi >> wi; hi--; wi--; row[hi].push_back(wi); colum[wi].push_back(hi); mxr = max(mxr, (int)row[hi].size()); mxc = max(mxc, (int)colum[wi].size()); } rep(i, h) { if (mxr == row[i].size()) mxh.push_back(i); } vector<int> cnt(w, 0); rep(j, w) { if (mxc == colum[j].size()) { mxw.push_back(j); rep(k, colum[j].size()) cnt[colum[j][k]]++; } } int ans = 0; rep(i, mxh.size()) { if (cnt[mxh[i]] != mxw.size()) { ans++; break; } } ans += mxr + (mxc - 1); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int h, w, m; cin >> h >> w >> m; int mxr = -1, mxc = -1; vector<vector<int>> row(h), colum(w); vector<int> mxh, mxw; rep(i, m) { int hi, wi; cin >> hi >> wi; hi--; wi--; row[hi].push_back(wi); colum[wi].push_back(hi); mxr = max(mxr, (int)row[hi].size()); mxc = max(mxc, (int)colum[wi].size()); } rep(i, h) { if (mxr == row[i].size()) mxh.push_back(i); } vector<int> cnt(h, 0); rep(j, w) { if (mxc == colum[j].size()) { mxw.push_back(j); rep(k, colum[j].size()) cnt[colum[j][k]]++; } } int ans = 0; rep(i, mxh.size()) { if (cnt[mxh[i]] != mxw.size()) { ans++; break; } } ans += mxr + (mxc - 1); cout << ans << endl; return 0; }
replace
28
29
28
29
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using ll = long long; using ld = long double; #define F first #define S second const ll mod = 1e9 + 7; const ll INF = 922337203685477; #define pb push_back #define deb(x) cout << '>' << #x << ':' << x << endl; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); #define maxN 200007 using namespace std; int main() { fastio; ll n = 0, m = 0, bombs = 0; cin >> n >> m >> bombs; vector<ll> row(n, 0); vector<ll> col(m, 0); set<pair<ll, ll>> s; for (ll i = 0; i < bombs; ++i) { ll r = 0, c = 0; cin >> r >> c; --r, --c; s.insert({r, c}); ++row[r], ++col[c]; } ll rmax = *max_element(row.begin(), row.end()); ll cmax = *max_element(col.begin(), col.end()); vector<ll> row_ind, col_ind; for (ll i = 0; i < n; ++i) { if (row[i] == rmax) row_ind.pb(i); } for (ll i = 0; i < m; ++i) { if (col[i] == cmax) col_ind.pb(i); } ll destroyed = 0; for (auto i : row_ind) { for (auto j : col_ind) { if (s.count({i, j})) destroyed = max(destroyed, row[i] + col[j] - 1); else destroyed = max(destroyed, row[i] + col[j]); } } cout << destroyed; }
#include <bits/stdc++.h> using ll = long long; using ld = long double; #define F first #define S second const ll mod = 1e9 + 7; const ll INF = 922337203685477; #define pb push_back #define deb(x) cout << '>' << #x << ':' << x << endl; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); #define maxN 200007 using namespace std; int main() { fastio; ll n = 0, m = 0, bombs = 0; cin >> n >> m >> bombs; vector<ll> row(n, 0); vector<ll> col(m, 0); set<pair<ll, ll>> s; for (ll i = 0; i < bombs; ++i) { ll r = 0, c = 0; cin >> r >> c; --r, --c; s.insert({r, c}); ++row[r], ++col[c]; } ll rmax = *max_element(row.begin(), row.end()); ll cmax = *max_element(col.begin(), col.end()); vector<ll> row_ind, col_ind; for (ll i = 0; i < n; ++i) { if (row[i] == rmax) row_ind.pb(i); } for (ll i = 0; i < m; ++i) { if (col[i] == cmax) col_ind.pb(i); } if (row_ind.size() * col_ind.size() > bombs) { cout << rmax + cmax; return 0; } ll destroyed = 0; for (auto i : row_ind) { for (auto j : col_ind) { if (s.count({i, j})) destroyed = max(destroyed, row[i] + col[j] - 1); else destroyed = max(destroyed, row[i] + col[j]); } } cout << destroyed; }
insert
39
39
39
43
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long LL; int hcnt[300005] = {}; int wcnt[300005] = {}; vector<int> hp, wp; map<pair<int, int>, int> coors; int main() { int h, w; cin >> h >> w; int m; cin >> m; int hm = 0, wm = 0; for (int i = 0; i < m; ++i) { int hh, ww; scanf("%d%d", &hh, &ww); hm = max(++hcnt[hh], hm); wm = max(++wcnt[ww], wm); coors.insert({{hh, ww}, 0}); } for (int i = 1; i <= h; ++i) { if (hm == hcnt[i]) hp.push_back(i); } for (int j = 1; j <= w; ++j) { if (wm == wcnt[j]) wp.push_back(j); } int ans = 0; for (int i : hp) { for (int j : wp) { ans = max(ans, hm + wm - (coors.count({i, j}) ? 1 : 0)); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; int hcnt[300005] = {}; int wcnt[300005] = {}; vector<int> hp, wp; map<pair<int, int>, int> coors; int main() { int h, w; cin >> h >> w; int m; cin >> m; int hm = 0, wm = 0; for (int i = 0; i < m; ++i) { int hh, ww; scanf("%d%d", &hh, &ww); hm = max(++hcnt[hh], hm); wm = max(++wcnt[ww], wm); coors.insert({{hh, ww}, 0}); } for (int i = 1; i <= h; ++i) { if (hm == hcnt[i]) hp.push_back(i); } for (int j = 1; j <= w; ++j) { if (wm == wcnt[j]) wp.push_back(j); } int ans = 0; for (int i : hp) { for (int j : wp) { ans = max(ans, hm + wm - (coors.count({i, j}) ? 1 : 0)); if (ans == hm + wm) break; } } cout << ans << endl; return 0; }
insert
39
39
39
41
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define I inline void using namespace std; using ll = long long; using ld = long double; const int N = 2e6 + 7; // How interesting! int n, m, k; int col[N], row[N]; vector<pair<int, int>> ed; map<pair<int, int>, int> mp; int main() { ios_base::sync_with_stdio(0); cin.tie(0); // freopen("in.in", "r" , stdin) ; cin >> n >> m >> k; for (int i = 0; i < k; i++) { int u, v; cin >> u >> v; ed.push_back({u, v}); row[u]++; col[v]++; mp[{u, v}] = 1; } std::vector<int> vecr, vecc; int mxr = 0, mxc = 0; for (int i = 1; i <= n; i++) { if (row[i] == mxr) { vecr.push_back(i); } else if (row[i] > mxr) vecr = {i}, mxr = row[i]; } for (int i = 1; i <= m; i++) { if (col[i] == mxc) { vecc.push_back(i); } else if (col[i] > mxc) vecc = {i}, mxc = col[i]; } int ans = 0; for (auto u : vecr) { for (auto v : vecc) { ans = max(row[u] + col[v] - mp[{u, v}], ans); } } cout << ans; return 0; }
#include <bits/stdc++.h> #define I inline void using namespace std; using ll = long long; using ld = long double; const int N = 2e6 + 7; // How interesting! int n, m, k; int col[N], row[N]; vector<pair<int, int>> ed; map<pair<int, int>, int> mp; int main() { ios_base::sync_with_stdio(0); cin.tie(0); // freopen("in.in", "r" , stdin) ; cin >> n >> m >> k; for (int i = 0; i < k; i++) { int u, v; cin >> u >> v; ed.push_back({u, v}); row[u]++; col[v]++; mp[{u, v}] = 1; } std::vector<int> vecr, vecc; int mxr = 0, mxc = 0; for (int i = 1; i <= n; i++) { if (row[i] == mxr) { vecr.push_back(i); } else if (row[i] > mxr) vecr = {i}, mxr = row[i]; } for (int i = 1; i <= m; i++) { if (col[i] == mxc) { vecc.push_back(i); } else if (col[i] > mxc) vecc = {i}, mxc = col[i]; } int ans = 0; for (auto u : vecr) { for (auto v : vecc) { int k = mp[{u, v}]; ans = max(row[u] + col[v] - k, ans); if (!k) { cout << ans; return 0; } } } cout << ans; return 0; }
replace
53
54
53
59
TLE
p02580
C++
Runtime Error
// Template #include <bits/stdc++.h> #define rep_override(x, y, z, name, ...) name #define rep2(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, r) for (int i = (l); i < (r); ++i) #define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define per(i, n) for (int i = (n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; constexpr int inf = 1001001001; constexpr ll INF = 3003003003003003003; template <typename T> inline bool chmin(T &x, const T &y) { if (x > y) { x = y; return 1; } return 0; } template <typename T> inline bool chmax(T &x, const T &y) { if (x < y) { x = y; return 1; } return 0; } struct IOSET { IOSET() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); } } ioset; // Segment Tree template <typename Operator> struct SegmentTree { Operator OP; using NodeType = decltype(OP.NodeE); int length; vector<NodeType> node; SegmentTree(int N) { length = 1; while (length < N) length <<= 1; node.assign(length << 1, OP.NodeE); } SegmentTree(vector<NodeType> &vec) { length = 1; while (length < vec.size()) length <<= 1; node.assign(2 * length, OP.NodeE); rep(i, vec.size()) node[i + length] = vec[i]; for (int i = length - 1; i > 0; --i) node[i] = OP.func(node[(i << 1) + 0], node[(i << 1) + 1]); } void update(int idx, NodeType val) { idx += length; node[idx] = OP.change(node[idx], val); while (idx >>= 1) node[idx] = OP.func(node[(idx << 1) + 0], node[(idx << 1) + 1]); } NodeType get(int l, int r) { l += length; r += length; NodeType vl = OP.NodeE, vr = OP.NodeE; while (r > l) { if (l & 1) vl = OP.func(vl, node[l++]); if (r & 1) vr = OP.func(node[--r], vr); l >>= 1; r >>= 1; } return OP.func(vl, vr); } }; struct RMQ { using NodeType = int; NodeType NodeE = 0; NodeType change(NodeType x, NodeType y) { return y; } NodeType func(NodeType x, NodeType y) { return max(x, y); } }; // Main int main() { int h, w, m; cin >> h >> w >> m; vector<int> x(m), y(m); rep(i, m) { cin >> x[i] >> y[i]; --x[i]; --y[i]; } vector<vector<int>> g(w); rep(i, m) g[y[i]].push_back(x[i]); vector<int> cnt1(h, 0), cnt2(w, 0); rep(i, m) { ++cnt1[x[i]]; ++cnt2[y[i]]; } SegmentTree<RMQ> st(cnt1); int ans = 0; rep(i, w) { for (int n : g[i]) st.update(n, cnt1[n] - 1); int mx = st.get(0, m); chmax(ans, mx + cnt2[i]); for (int n : g[i]) st.update(n, cnt1[n]); } cout << ans << "\n"; return 0; }
// Template #include <bits/stdc++.h> #define rep_override(x, y, z, name, ...) name #define rep2(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, r) for (int i = (l); i < (r); ++i) #define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define per(i, n) for (int i = (n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; constexpr int inf = 1001001001; constexpr ll INF = 3003003003003003003; template <typename T> inline bool chmin(T &x, const T &y) { if (x > y) { x = y; return 1; } return 0; } template <typename T> inline bool chmax(T &x, const T &y) { if (x < y) { x = y; return 1; } return 0; } struct IOSET { IOSET() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); } } ioset; // Segment Tree template <typename Operator> struct SegmentTree { Operator OP; using NodeType = decltype(OP.NodeE); int length; vector<NodeType> node; SegmentTree(int N) { length = 1; while (length < N) length <<= 1; node.assign(length << 1, OP.NodeE); } SegmentTree(vector<NodeType> &vec) { length = 1; while (length < vec.size()) length <<= 1; node.assign(2 * length, OP.NodeE); rep(i, vec.size()) node[i + length] = vec[i]; for (int i = length - 1; i > 0; --i) node[i] = OP.func(node[(i << 1) + 0], node[(i << 1) + 1]); } void update(int idx, NodeType val) { idx += length; node[idx] = OP.change(node[idx], val); while (idx >>= 1) node[idx] = OP.func(node[(idx << 1) + 0], node[(idx << 1) + 1]); } NodeType get(int l, int r) { l += length; r += length; NodeType vl = OP.NodeE, vr = OP.NodeE; while (r > l) { if (l & 1) vl = OP.func(vl, node[l++]); if (r & 1) vr = OP.func(node[--r], vr); l >>= 1; r >>= 1; } return OP.func(vl, vr); } }; struct RMQ { using NodeType = int; NodeType NodeE = 0; NodeType change(NodeType x, NodeType y) { return y; } NodeType func(NodeType x, NodeType y) { return max(x, y); } }; // Main int main() { int h, w, m; cin >> h >> w >> m; vector<int> x(m), y(m); rep(i, m) { cin >> x[i] >> y[i]; --x[i]; --y[i]; } vector<vector<int>> g(w); rep(i, m) g[y[i]].push_back(x[i]); vector<int> cnt1(h, 0), cnt2(w, 0); rep(i, m) { ++cnt1[x[i]]; ++cnt2[y[i]]; } SegmentTree<RMQ> st(cnt1); int ans = 0; rep(i, w) { for (int n : g[i]) st.update(n, cnt1[n] - 1); int mx = st.get(0, h); chmax(ans, mx + cnt2[i]); for (int n : g[i]) st.update(n, cnt1[n]); } cout << ans << "\n"; return 0; }
replace
106
107
106
107
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; // long long using ll = long long; // pair<int, int> using PII = pair<int, int>; // 最大値、mod const int MOD = 1000000007; const int mod = 1000000007; const int INF = 1000000000; const long long LINF = 1e18; const int MAX = 510000; // 出力系 #define print(x) cout << x << endl #define prints(x) cout << fixed << setprecision(20) << x << endl #define printc(x) cout << setw(2) << setfill('0') << x << endl; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl // 配列入力 vector<long long> vecin(ll n) { vector<long long> res(n); for (int i = 0; i < n; i++) cin >> res[i]; return res; } // begin() end() #define all(x) (x).begin(), (x).end() // for #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rrep(i, a, b) for (int i = (a); i > (b); i--) #define rep(i, a, b) for (int i = (a); i < (b); i++) // 最大公約数 ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } // 最小公倍数 unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; } // a = max(a, b), a = min(a, b) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // num ^ pow(mod取る) ll pow_mod(ll num, ll pow, ll mod) { ll prod = 1; num %= mod; while (pow > 0) { if (pow & 1) prod = prod * num % mod; num = num * num % mod; pow >>= 1; } return prod; } // 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度) // COMinit() // COM(x, y) // とコンビで使う // テーブルを作る前処理 long long 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; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 重みつきUnionFInd template <class Abel> struct GUnionFind { vector<int> par; vector<int> rank; vector<Abel> diff_weight; GUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x) { root(x); return diff_weight[x]; } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y) { return weight(y) - weight(x); } }; // UnionFind struct UnionFind { vector<int> par; vector<int> rank; vector<ll> Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x) { return Size[root(x)]; } }; // modint構造体 struct Mint { int val; Mint inv() const { int tmp, a = val, b = mod, x = 1, y = 0; while (b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y); return Mint(x); } public: Mint() : val(0) {} Mint(ll x) { if ((val = x % mod) < 0) val += mod; } Mint pow(ll t) { Mint res = 1, b = *this; while (t) { if (t & 1) res *= b; b *= b; t >>= 1; } return res; } Mint &operator+=(const Mint &x) { if ((val += x.val) >= mod) val -= mod; return *this; } Mint &operator-=(const Mint &x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; } Mint &operator*=(const Mint &x) { val = (ll)val * x.val % mod; return *this; } Mint &operator/=(const Mint &x) { return *this *= x.inv(); } bool operator==(const Mint &x) const { return val == x.val; } bool operator!=(const Mint &x) const { return val != x.val; } bool operator<(const Mint &x) const { return val < x.val; } bool operator<=(const Mint &x) const { return val <= x.val; } bool operator>(const Mint &x) const { return val > x.val; } bool operator>=(const Mint &x) const { return val >= x.val; } Mint operator+(const Mint &x) const { return Mint(*this) += x; } Mint operator-(const Mint &x) const { return Mint(*this) -= x; } Mint operator*(const Mint &x) const { return Mint(*this) *= x; } Mint operator/(const Mint &x) const { return Mint(*this) /= x; } }; struct factorial { vector<Mint> Fact, Finv; public: // factorial fact(10000010); // fact.nCr(a, b) // 「fact」の部分は自由に名前変更可能 factorial(int maxx) { Fact.resize(maxx + 1), Finv.resize(maxx + 1); Fact[0] = Mint(1); rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1); Finv[maxx] = Mint(1) / Fact[maxx]; rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i; } Mint fact(int n, bool inv = 0) { if (inv) return Finv[n]; else return Fact[n]; } Mint nPr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[n - r]; } Mint nCr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[r] * Finv[n - r]; } }; // 1 * 2 * 3 .... * n (mod) ll modfact(ll n) { if (n <= 1) return 1; return (n * modfact(n - 1)) % MOD; } // kが角度だった場合:cos(k * (PI / 180)); // const double PI = acos(-1);のまま使うと円周率(M_PIもあるよ) const double PI = acos(-1); // 多次元 vector 生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5); template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } // 素因数分解 vector<pair<long long, int>> factorize(long long n) { vector<pair<long long, int>> res; for (long long i = 2; i * i <= n; ++i) { if (n % i) continue; res.emplace_back(i, 0); while (n % i == 0) { n /= i; res.back().second++; } } if (n != 1) res.emplace_back(n, 1); return res; } // 素数判定 bool primejudge(long long a) { if (a <= 1) return false; for (long long i = 2; i * i <= a; i++) { if (a % i == 0) return false; } return true; } //  累積和 // vector<long long>sums(vector<int>n){ // vector<long long>res(n.size() + 1, 0); // for(int i = 0; i < n.size(); i++) res[i + 1] = n[i] + res[i]; // return res; // } int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0}; int main() { int H, W, M; cin >> H >> W >> M; vector<int> row(H, 0); vector<int> line(W, 0); set<PII> p; while (M--) { int y, x; cin >> y >> x; y--; x--; row[y]++; line[x]++; p.insert({y, x}); } ll mr = -1; set<int> sr; ll ml = -1; set<int> sl; REP(i, H) { if (row[i] > mr) mr = row[i], sr.clear(), sr.insert(i); else if (row[i] == mr) sr.insert(i); } REP(i, W) { if (line[i] > ml) ml = line[i], sl.clear(), sl.insert(i); else if (line[i] == ml) sl.insert(i); } ll ans = mr + ml - 1; bool flag = false; for (auto a : sr) { for (auto b : sl) { if (!p.count(make_pair(a, b))) flag = true; } } if (flag) ans++; print(ans); return 0; }
#include <bits/stdc++.h> using namespace std; // long long using ll = long long; // pair<int, int> using PII = pair<int, int>; // 最大値、mod const int MOD = 1000000007; const int mod = 1000000007; const int INF = 1000000000; const long long LINF = 1e18; const int MAX = 510000; // 出力系 #define print(x) cout << x << endl #define prints(x) cout << fixed << setprecision(20) << x << endl #define printc(x) cout << setw(2) << setfill('0') << x << endl; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl // 配列入力 vector<long long> vecin(ll n) { vector<long long> res(n); for (int i = 0; i < n; i++) cin >> res[i]; return res; } // begin() end() #define all(x) (x).begin(), (x).end() // for #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rrep(i, a, b) for (int i = (a); i > (b); i--) #define rep(i, a, b) for (int i = (a); i < (b); i++) // 最大公約数 ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } // 最小公倍数 unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; } // a = max(a, b), a = min(a, b) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // num ^ pow(mod取る) ll pow_mod(ll num, ll pow, ll mod) { ll prod = 1; num %= mod; while (pow > 0) { if (pow & 1) prod = prod * num % mod; num = num * num % mod; pow >>= 1; } return prod; } // 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度) // COMinit() // COM(x, y) // とコンビで使う // テーブルを作る前処理 long long 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; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 重みつきUnionFInd template <class Abel> struct GUnionFind { vector<int> par; vector<int> rank; vector<Abel> diff_weight; GUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x) { root(x); return diff_weight[x]; } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y) { return weight(y) - weight(x); } }; // UnionFind struct UnionFind { vector<int> par; vector<int> rank; vector<ll> Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x) { return Size[root(x)]; } }; // modint構造体 struct Mint { int val; Mint inv() const { int tmp, a = val, b = mod, x = 1, y = 0; while (b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y); return Mint(x); } public: Mint() : val(0) {} Mint(ll x) { if ((val = x % mod) < 0) val += mod; } Mint pow(ll t) { Mint res = 1, b = *this; while (t) { if (t & 1) res *= b; b *= b; t >>= 1; } return res; } Mint &operator+=(const Mint &x) { if ((val += x.val) >= mod) val -= mod; return *this; } Mint &operator-=(const Mint &x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; } Mint &operator*=(const Mint &x) { val = (ll)val * x.val % mod; return *this; } Mint &operator/=(const Mint &x) { return *this *= x.inv(); } bool operator==(const Mint &x) const { return val == x.val; } bool operator!=(const Mint &x) const { return val != x.val; } bool operator<(const Mint &x) const { return val < x.val; } bool operator<=(const Mint &x) const { return val <= x.val; } bool operator>(const Mint &x) const { return val > x.val; } bool operator>=(const Mint &x) const { return val >= x.val; } Mint operator+(const Mint &x) const { return Mint(*this) += x; } Mint operator-(const Mint &x) const { return Mint(*this) -= x; } Mint operator*(const Mint &x) const { return Mint(*this) *= x; } Mint operator/(const Mint &x) const { return Mint(*this) /= x; } }; struct factorial { vector<Mint> Fact, Finv; public: // factorial fact(10000010); // fact.nCr(a, b) // 「fact」の部分は自由に名前変更可能 factorial(int maxx) { Fact.resize(maxx + 1), Finv.resize(maxx + 1); Fact[0] = Mint(1); rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1); Finv[maxx] = Mint(1) / Fact[maxx]; rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i; } Mint fact(int n, bool inv = 0) { if (inv) return Finv[n]; else return Fact[n]; } Mint nPr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[n - r]; } Mint nCr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[r] * Finv[n - r]; } }; // 1 * 2 * 3 .... * n (mod) ll modfact(ll n) { if (n <= 1) return 1; return (n * modfact(n - 1)) % MOD; } // kが角度だった場合:cos(k * (PI / 180)); // const double PI = acos(-1);のまま使うと円周率(M_PIもあるよ) const double PI = acos(-1); // 多次元 vector 生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5); template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } // 素因数分解 vector<pair<long long, int>> factorize(long long n) { vector<pair<long long, int>> res; for (long long i = 2; i * i <= n; ++i) { if (n % i) continue; res.emplace_back(i, 0); while (n % i == 0) { n /= i; res.back().second++; } } if (n != 1) res.emplace_back(n, 1); return res; } // 素数判定 bool primejudge(long long a) { if (a <= 1) return false; for (long long i = 2; i * i <= a; i++) { if (a % i == 0) return false; } return true; } //  累積和 // vector<long long>sums(vector<int>n){ // vector<long long>res(n.size() + 1, 0); // for(int i = 0; i < n.size(); i++) res[i + 1] = n[i] + res[i]; // return res; // } int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0}; int main() { int H, W, M; cin >> H >> W >> M; vector<int> row(H, 0); vector<int> line(W, 0); set<PII> p; while (M--) { int y, x; cin >> y >> x; y--; x--; row[y]++; line[x]++; p.insert({y, x}); } ll mr = -1; set<int> sr; ll ml = -1; set<int> sl; REP(i, H) { if (row[i] > mr) mr = row[i], sr.clear(), sr.insert(i); else if (row[i] == mr) sr.insert(i); } REP(i, W) { if (line[i] > ml) ml = line[i], sl.clear(), sl.insert(i); else if (line[i] == ml) sl.insert(i); } ll ans = mr + ml; int cnt = 0; for (auto a : p) { if (sr.count(a.first) && sl.count(a.second)) cnt++; } if (cnt == sl.size() * sr.size()) ans--; print(ans); return 0; }
replace
369
379
369
377
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int h, w, m; cin >> h >> w >> m; vector<int> vh(h + 1, 0); vector<int> vw(w + 1, 0); unordered_map<string, int> u; for (int i = 0; i < m; i++) { int l, r; cin >> l >> r; vh[l]++; vw[r]++; string temp = to_string(l) + " " + to_string(r); u[temp]++; } int m1 = 0; int m2 = 0; for (int i = 0; i <= h; i++) { if (vh[i] > m1) { m1 = vh[i]; } } for (int i = 0; i <= w; i++) { if (vw[i] > m2) { m2 = vw[i]; } } vector<int> l1; vector<int> r1; for (int i = 0; i <= h; i++) { if (vh[i] == m1) { l1.push_back(i); } } for (int i = 0; i <= w; i++) { if (vw[i] == m2) { r1.push_back(i); } } int ans = 0; for (int i = 0; i < l1.size(); i++) { for (int j = 0; j < r1.size(); j++) { string temp = to_string(l1[i]) + " " + to_string(r1[j]); if (u.find(temp) != u.end()) { ans = max(ans, m1 + m2 - 1); } else { ans = max(ans, m1 + m2); } } } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int h, w, m; cin >> h >> w >> m; vector<int> vh(h + 1, 0); vector<int> vw(w + 1, 0); unordered_map<string, int> u; for (int i = 0; i < m; i++) { int l, r; cin >> l >> r; vh[l]++; vw[r]++; string temp = to_string(l) + " " + to_string(r); u[temp]++; } int m1 = 0; int m2 = 0; for (int i = 0; i <= h; i++) { if (vh[i] > m1) { m1 = vh[i]; } } for (int i = 0; i <= w; i++) { if (vw[i] > m2) { m2 = vw[i]; } } vector<int> l1; vector<int> r1; for (int i = 0; i <= h; i++) { if (vh[i] == m1) { l1.push_back(i); } } for (int i = 0; i <= w; i++) { if (vw[i] == m2) { r1.push_back(i); } } int ans = 0; for (int i = 0; i < l1.size(); i++) { for (int j = 0; j < r1.size(); j++) { string temp = to_string(l1[i]) + " " + to_string(r1[j]); if (u.find(temp) != u.end()) { ans = max(ans, m1 + m2 - 1); } else { ans = max(ans, m1 + m2); break; } } } cout << ans << "\n"; }
insert
51
51
51
52
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define ff first #define ss second #define ll long long #define ll_MAX LONG_LONG_MAX #define ll_MIN LONG_LONG_MIN #define pi pair<ll, ll> #define endl "\n" #define MAXN 100005 using namespace std; ll h, w, m, a, b; vector<ll> v, v1; unordered_map<ll, ll> r, c; unordered_map<ll, ll> mm; void solve() { cin >> h >> w >> m; ll mr = 0, mc = 0; while (m--) { cin >> a >> b; ll t = a * 1e9 + b; mm[t]++; r[a]++; c[b]++; mr = max(mr, r[a]); mc = max(mc, c[b]); } for (ll i = 1; i <= h; i++) { if (r[i] == mr) v.pb(i); } for (ll i = 1; i <= w; i++) { if (c[i] == mc) v1.pb(i); } ll ans = 0; for (ll i = 0; i < v.size(); i++) { for (ll j = 0; j < v1.size(); j++) { ll t = v[i] * 1e9 + v1[j]; if (mm[t] == 1) ans = max(ans, r[v[i]] + c[v1[j]] - 1); else ans = max(ans, r[v[i]] + c[v1[j]]); } } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); }
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define ff first #define ss second #define ll long long #define ll_MAX LONG_LONG_MAX #define ll_MIN LONG_LONG_MIN #define pi pair<ll, ll> #define endl "\n" #define MAXN 100005 using namespace std; ll h, w, m, a, b; vector<ll> v, v1; unordered_map<ll, ll> r, c; unordered_map<ll, ll> mm; void solve() { cin >> h >> w >> m; ll mr = 0, mc = 0; while (m--) { cin >> a >> b; ll t = a * 1e9 + b; mm[t]++; r[a]++; c[b]++; mr = max(mr, r[a]); mc = max(mc, c[b]); } for (ll i = 1; i <= h; i++) { if (r[i] == mr) v.pb(i); } for (ll i = 1; i <= w; i++) { if (c[i] == mc) v1.pb(i); } ll ans = 0; if (v.size() + v1.size() > 3e5) { cout << mr + mc << endl; return; } for (ll i = 0; i < v.size(); i++) { for (ll j = 0; j < v1.size(); j++) { ll t = v[i] * 1e9 + v1[j]; if (mm[t] == 1) ans = max(ans, r[v[i]] + c[v1[j]] - 1); else ans = max(ans, r[v[i]] + c[v1[j]]); } } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); }
insert
39
39
39
43
TLE
p02580
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <forward_list> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <tuple> #include <utility> #include <vector> #define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i)) using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll INF = (1ll << 60); int main(void) { int h, w; cin >> h >> w; ll m; cin >> m; map<ll, ll> r, c; map<P, bool> flag; ll r_max = 0, c_max = 0; ll ri, ci; vector<int> a(m), b(m); for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; flag[{a[i], b[i]}] = true; r[a[i]]++; r_max = max(r_max, r[a[i]]); c[b[i]]++; c_max = max(c_max, c[b[i]]); } set<ll> x, y; for (int i = 1; i <= h; i++) { if (r[i] == r_max) { x.insert(i); } } for (int i = 1; i <= w; i++) { if (c[i] == c_max) { y.insert(i); } } bool z = false; for (auto &&i : x) { for (auto &&j : y) { if (flag[{i, j}] == false) { z = true; } } } if (z) { cout << r_max + c_max << endl; } else { cout << r_max + c_max - 1 << endl; } }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <forward_list> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <tuple> #include <utility> #include <vector> #define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i)) using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll INF = (1ll << 60); int main(void) { int h, w; cin >> h >> w; ll m; cin >> m; map<ll, ll> r, c; map<P, bool> flag; ll r_max = 0, c_max = 0; ll ri, ci; vector<int> a(m), b(m); for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; flag[{a[i], b[i]}] = true; r[a[i]]++; r_max = max(r_max, r[a[i]]); c[b[i]]++; c_max = max(c_max, c[b[i]]); } set<ll> x, y; for (int i = 1; i <= h; i++) { if (r[i] == r_max) { x.insert(i); } } for (int i = 1; i <= w; i++) { if (c[i] == c_max) { y.insert(i); } } bool z = false; for (auto &&i : x) { for (auto &&j : y) { if (flag[{i, j}] == false) { z = true; break; } } } if (z) { cout << r_max + c_max << endl; } else { cout << r_max + c_max - 1 << endl; } }
insert
67
67
67
68
TLE
p02580
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define rrep(i, a) for (ll i = ll(a - 1); i >= 0; --i) #define all(x) (x).begin(), (x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(), (V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } inline void Yes(bool condition) { if (condition) PRINT("Yes"); else PRINT("No"); } template <class itr> void cins(itr first, itr last) { for (auto i = first; i != last; i++) { cin >> (*i); } } template <class itr> void array_output(itr start, itr goal) { string ans = "", k = " "; for (auto i = start; i != goal; i++) ans += to_string(*i) + k; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; } const ll INF = 1e18; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll EPS = 1e-10; int sgn(const double a) { return (a < -EPS ? -1 : (a > EPS ? +1 : 0)); } typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> tri; typedef pair<double, double> point; typedef complex<double> Point; const ll MAX = 30000; constexpr ll nx[5] = {-2, -1, 0, 1, 2}; constexpr ll ny[5] = {-2, -1, 0, 1, 2}; int main() { cin.tie(0); ios::sync_with_stdio(false); ll h, w, m; cin >> h >> w >> m; vector<ll> x(h, 0), y(w, 0); map<P, bool> ex; ll s, t; rep(i, m) { cin >> s >> t; s--; t--; x[s]++; y[t]++; ex[P(s, t)] = 1; } ll mx = 0, my = 0, mi, mj; rep(i, h) { if (chmax(mx, x[i])) mi = i; if (chmax(my, y[i])) mj = i; } ll ans = 0; rep(i, w) { ll c = mx + y[i]; if (ex[P(mi, i)]) c--; chmax(ans, c); } rep(i, h) { ll c = my + x[i]; if (ex[P(i, mj)]) c--; chmax(ans, c); } PRINT(ans); }
#include <algorithm> #include <assert.h> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define rrep(i, a) for (ll i = ll(a - 1); i >= 0; --i) #define all(x) (x).begin(), (x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(), (V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } inline void Yes(bool condition) { if (condition) PRINT("Yes"); else PRINT("No"); } template <class itr> void cins(itr first, itr last) { for (auto i = first; i != last; i++) { cin >> (*i); } } template <class itr> void array_output(itr start, itr goal) { string ans = "", k = " "; for (auto i = start; i != goal; i++) ans += to_string(*i) + k; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; } const ll INF = 1e18; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll EPS = 1e-10; int sgn(const double a) { return (a < -EPS ? -1 : (a > EPS ? +1 : 0)); } typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> tri; typedef pair<double, double> point; typedef complex<double> Point; const ll MAX = 30000; constexpr ll nx[5] = {-2, -1, 0, 1, 2}; constexpr ll ny[5] = {-2, -1, 0, 1, 2}; int main() { cin.tie(0); ios::sync_with_stdio(false); ll h, w, m; cin >> h >> w >> m; vector<ll> x(h, 0), y(w, 0); map<P, bool> ex; ll s, t; rep(i, m) { cin >> s >> t; s--; t--; x[s]++; y[t]++; ex[P(s, t)] = 1; } ll mx = 0, my = 0, mi, mj; rep(i, h) { if (chmax(mx, x[i])) mi = i; } rep(i, w) { if (chmax(my, y[i])) mj = i; } ll ans = 0; rep(i, w) { ll c = mx + y[i]; if (ex[P(mi, i)]) c--; chmax(ans, c); } rep(i, h) { ll c = my + x[i]; if (ex[P(i, mj)]) c--; chmax(ans, c); } PRINT(ans); }
insert
97
97
97
99
0
p02580
C++
Runtime Error
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */ // codeforces #include <bits/stdc++.h> // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define mp make_pair #define pb push_back #define sz(v) ((int)v.size()) #define all(v) v.begin(), v.end() void parseArray(ll *A, ll n) { for (ll K = 0; K < n; K++) { cin >> A[K]; } } ll modInverse(ll a, ll b) { return 1 < a ? b - modInverse(b % a, a) * b / a : 1; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ld dist(ld x, ld y, ld a, ld b) { return sqrt((x - a) * (x - a) + (y - b) * (y - b)); } void debug(ll *a, ll n) { for (ll k = 0; k < n; k++) { cerr << a[k] << " "; } cout << "\n"; } #define PI 3.14159265358979323846 #define FF first #define SS second int main() { FASTIO; ll h, w, n; cin >> h >> w >> n; ll x[333333], y[333333]; memset(x, 0, sizeof x); memset(y, 0, sizeof y); vector<ll> M[333333]; set<pair<ll, ll>> sorted; for (int k = 0; k < n; k++) { ll a, b; cin >> a >> b; x[a]++, y[b]++; M[a].pb(b); } for (int k = 0; k < 333333; k++) { if (y[k]) sorted.insert(mp(y[k], k)); } ll ans = 0; ll cur = n; for (int k = 0; k < 333333; k++) { if (M[k].empty()) { ans = max(ans, x[k]); continue; } map<ll, ll> cnt; for (ll e : M[k]) { cnt[e]++; } for (const auto &it : cnt) { sorted.erase(sorted.lower_bound(mp(y[it.first], 0))); sorted.insert(mp(y[it.first] - it.second, cur++)); } ans = max(ans, x[k] + sorted.rbegin()->first); for (const auto &it : cnt) { sorted.erase(sorted.lower_bound(mp(y[it.first] - it.second, 0))); sorted.insert(mp(y[it.first], cur++)); } } cout << ans << endl; return 0; }
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */ // codeforces #include <bits/stdc++.h> // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define mp make_pair #define pb push_back #define sz(v) ((int)v.size()) #define all(v) v.begin(), v.end() void parseArray(ll *A, ll n) { for (ll K = 0; K < n; K++) { cin >> A[K]; } } ll modInverse(ll a, ll b) { return 1 < a ? b - modInverse(b % a, a) * b / a : 1; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ld dist(ld x, ld y, ld a, ld b) { return sqrt((x - a) * (x - a) + (y - b) * (y - b)); } void debug(ll *a, ll n) { for (ll k = 0; k < n; k++) { cerr << a[k] << " "; } cout << "\n"; } #define PI 3.14159265358979323846 #define FF first #define SS second int main() { FASTIO; ll h, w, n; cin >> h >> w >> n; ll x[333333], y[333333]; memset(x, 0, sizeof x); memset(y, 0, sizeof y); vector<ll> M[333333]; set<pair<ll, ll>> sorted; for (int k = 0; k < n; k++) { ll a, b; cin >> a >> b; x[a]++, y[b]++; M[a].pb(b); } for (int k = 0; k < 333333; k++) { if (y[k]) sorted.insert(mp(y[k], k)); } ll ans = 0; ll cur = 3333333; for (int k = 0; k < 333333; k++) { if (M[k].empty()) { ans = max(ans, x[k]); continue; } map<ll, ll> cnt; for (ll e : M[k]) { cnt[e]++; } for (const auto &it : cnt) { sorted.erase(sorted.lower_bound(mp(y[it.first], 0))); sorted.insert(mp(y[it.first] - it.second, cur++)); } ans = max(ans, x[k] + sorted.rbegin()->first); for (const auto &it : cnt) { sorted.erase(sorted.lower_bound(mp(y[it.first] - it.second, 0))); sorted.insert(mp(y[it.first], cur++)); } } cout << ans << endl; return 0; }
replace
58
59
58
59
-11
p02580
C++
Time Limit Exceeded
/** * author: otera **/ #include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; // #define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const int inf = 1e9 + 7; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<int, int> P; typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back #define debug(x) cerr << #x << " = " << (x) << endl; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int h, w, m; void solve() { cin >> h >> w >> m; vector<int> cnth(h, 0), cntw(w, 0); map<P, bool> mp; rep(i, m) { int x, y; cin >> x >> y; --x, --y; mp[P{x, y}] = 1; cnth[x]++, cntw[y]++; } set<int> sex, sey; int mah = -1; rep(i, h) { if (chmax(mah, cnth[i])) { sex.clear(); sex.insert(i); } else if (mah == cnth[i]) { sex.insert(i); } } int maw = -1; rep(i, w) { if (chmax(maw, cntw[i])) { sey.clear(); sey.insert(i); } else if (maw == cntw[i]) { sey.insert(i); } } int ans = mah + maw; bool check = 1; for (auto x : sex) { for (auto y : sey) { if (!mp[P{x, y}]) { check = 0; } } } if (check) --ans; cout << ans << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(10); // int t; cin >> t; rep(i, t)solve(); solve(); return 0; }
/** * author: otera **/ #include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; // #define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const int inf = 1e9 + 7; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<int, int> P; typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back #define debug(x) cerr << #x << " = " << (x) << endl; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int h, w, m; void solve() { cin >> h >> w >> m; vector<int> cnth(h, 0), cntw(w, 0); map<P, bool> mp; rep(i, m) { int x, y; cin >> x >> y; --x, --y; mp[P{x, y}] = 1; cnth[x]++, cntw[y]++; } set<int> sex, sey; int mah = -1; rep(i, h) { if (chmax(mah, cnth[i])) { sex.clear(); sex.insert(i); } else if (mah == cnth[i]) { sex.insert(i); } } int maw = -1; rep(i, w) { if (chmax(maw, cntw[i])) { sey.clear(); sey.insert(i); } else if (maw == cntw[i]) { sey.insert(i); } } int ans = mah + maw; bool check = 1; for (auto x : sex) { for (auto y : sey) { if (!mp[P{x, y}]) { check = 0; break; } } } if (check) --ans; cout << ans << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(10); // int t; cin >> t; rep(i, t)solve(); solve(); return 0; }
insert
105
105
105
106
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back const int maxn = 1e5 + 10; int x, y, r[maxn], c[maxn]; vector<int> rr, cc; set<pair<int, int>> st; void solve() { int h, w, m; cin >> h >> w >> m; int mr = 0, mc = 0; for (int i = 0; i < m; i++) { cin >> x >> y; st.insert(make_pair(x, y)); r[x]++; c[y]++; if (mr < r[x]) { mr = r[x]; rr.clear(); rr.pb(x); } else if (mr == r[x]) { rr.pb(x); } if (mc < c[y]) { mc = c[y]; cc.clear(); cc.pb(y); } else if (mc == c[y]) { cc.pb(y); } } for (int i : rr) for (int j : cc) { if (st.count(make_pair(i, j))) continue; else { cout << mr + mc; return; } } cout << mr + mc - 1; } signed main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back const int maxn = 3e5 + 10; int x, y, r[maxn], c[maxn]; vector<int> rr, cc; set<pair<int, int>> st; void solve() { int h, w, m; cin >> h >> w >> m; int mr = 0, mc = 0; for (int i = 0; i < m; i++) { cin >> x >> y; st.insert(make_pair(x, y)); r[x]++; c[y]++; if (mr < r[x]) { mr = r[x]; rr.clear(); rr.pb(x); } else if (mr == r[x]) { rr.pb(x); } if (mc < c[y]) { mc = c[y]; cc.clear(); cc.pb(y); } else if (mc == c[y]) { cc.pb(y); } } for (int i : rr) for (int j : cc) { if (st.count(make_pair(i, j))) continue; else { cout << mr + mc; return; } } cout << mr + mc - 1; } signed main() { solve(); return 0; }
replace
5
6
5
6
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const static ll INF = 1e15; #define rep(i, n) for (int i = 0; i < (int)(n); i++) // __uint128_t const ll MOD = 1e9 + 7; int main() { ll H, W, M; cin >> H >> W >> M; map<ll, ll> MH, MW; vector<pair<ll, ll>> V(H + 1); for (int i = 0; i < M; i++) { ll h, w; cin >> h >> w; MH[h]++; MW[w]++; V[i] = {h, w}; } ll ans = 0; ll MAX1 = 0, MAX2 = 0; set<ll> VH, VW; for (auto p : MH) MAX1 = max(MAX1, p.second); for (auto p : MH) if (p.second == MAX1) VH.insert(p.first); for (auto p : MW) MAX2 = max(MAX2, p.second); for (auto p : MW) if (p.second == MAX2) VW.insert(p.first); ll cnt = 0, SIZE = VH.size() * VW.size(); for (auto p : V) { ll h = p.first, w = p.second; if (VH.find(h) != VH.end() && VW.find(w) != VW.end()) cnt++; } if (cnt == SIZE) cout << MAX1 + MAX2 - 1 << endl; else cout << MAX1 + MAX2 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const static ll INF = 1e15; #define rep(i, n) for (int i = 0; i < (int)(n); i++) // __uint128_t const ll MOD = 1e9 + 7; int main() { ll H, W, M; cin >> H >> W >> M; map<ll, ll> MH, MW; vector<pair<ll, ll>> V(M); for (int i = 0; i < M; i++) { ll h, w; cin >> h >> w; MH[h]++; MW[w]++; V[i] = {h, w}; } ll ans = 0; ll MAX1 = 0, MAX2 = 0; set<ll> VH, VW; for (auto p : MH) MAX1 = max(MAX1, p.second); for (auto p : MH) if (p.second == MAX1) VH.insert(p.first); for (auto p : MW) MAX2 = max(MAX2, p.second); for (auto p : MW) if (p.second == MAX2) VW.insert(p.first); ll cnt = 0, SIZE = VH.size() * VW.size(); for (auto p : V) { ll h = p.first, w = p.second; if (VH.find(h) != VH.end() && VW.find(w) != VW.end()) cnt++; } if (cnt == SIZE) cout << MAX1 + MAX2 - 1 << endl; else cout << MAX1 + MAX2 << endl; }
replace
12
13
12
13
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() using ll = long long; const int INF = 1 << 30; const ll INFll = 1LL << 62; const int mod = int(1e9) + 7; using P = pair<ll, ll>; using ld = long double; int main() { int H, W, m; cin >> H >> W >> m; int mxh = 0, mxw = 0; ll MX = 300010; vector<int> ch(MX, 0); vector<int> cw(MX, 0); map<P, bool> mp; for (int i = 0; i < m; ++i) { int h, w; cin >> h >> w; h--; w--; ch[h]++; cw[w]++; mxh = max(mxh, ch[h]); mxw = max(mxw, cw[w]); mp[{h, w}] = true; } vector<int> x; vector<int> y; for (int i = 0; i <= H; ++i) { if (mxh == ch[i]) x.push_back(i); } for (int j = 0; j <= W; ++j) { if (mxw == cw[j]) y.push_back(j); } ll ans = mxh + mxw; bool exist = false; for (auto i : x) { for (auto j : y) { if (!mp[{i, j}]) exist = true; } } if (!exist) ans--; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() using ll = long long; const int INF = 1 << 30; const ll INFll = 1LL << 62; const int mod = int(1e9) + 7; using P = pair<ll, ll>; using ld = long double; int main() { int H, W, m; cin >> H >> W >> m; int mxh = 0, mxw = 0; ll MX = 300010; vector<int> ch(MX, 0); vector<int> cw(MX, 0); map<P, bool> mp; for (int i = 0; i < m; ++i) { int h, w; cin >> h >> w; h--; w--; ch[h]++; cw[w]++; mxh = max(mxh, ch[h]); mxw = max(mxw, cw[w]); mp[{h, w}] = true; } vector<int> x; vector<int> y; for (int i = 0; i <= H; ++i) { if (mxh == ch[i]) x.push_back(i); } for (int j = 0; j <= W; ++j) { if (mxw == cw[j]) y.push_back(j); } ll ans = mxh + mxw; bool exist = false; ll k = x.size() * y.size(); // 交点の数 if (k > m) { cout << ans << endl; return 0; } for (auto i : x) { for (auto j : y) { if (!mp[{i, j}]) exist = true; } } if (!exist) ans--; cout << ans << endl; }
insert
42
42
42
47
TLE
p02580
C++
Time Limit Exceeded
using namespace std; #include <bits/stdc++.h> typedef long long ll; typedef long double ld; typedef double db; typedef string str; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<db, db> pd; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<ll> vl; typedef vector<db> vd; typedef vector<str> vs; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<pd> vpd; typedef set<int> si; typedef set<ll> sl; typedef map<int, int> mii; #define mp make_pair #define sz(x) (int)x.size() #define len(x) (int)x.size() #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define rsz resize #define ins insert #define ft front() #define bk back() // #define pf push_front // #define pb push_back #define eb emplace_back #define ep emplace #define lb lower_bound #define ub upper_bound #define vfor(i, a, b) for (int i = (a); i < (b); ++i) #define f0r(i, a) vfor(i, 0, a) #define rof(i, a, b) for (int i = (b)-1; i >= (a); --i) #define r0f(i, a) rof(i, 0, a) #define trav(a, x) for (auto &a : x) #define def(fname, rtype, args, ...) \ function<rtype args> fname = [__VA_ARGS__] args #define boost() cin.tie(0), cin.sync_with_stdio(0) template <class T> void binstf(T &found, T a, T b, function<bool(T)> test, bool TF = true) { T i = a, j = b; bool da = test(a), db = test(b); if ((da != TF) or (db == TF)) { cerr << "---[BS: TF = " << TF << "]---" << endl; cerr << a << "->" << da << endl; cerr << b << "->" << db << endl; } while (j - i > 1) { T m = (i + j) / 2; if (test(m) == TF) i = m; else j = m; } found = i; if (not TF) found++; } #define binsft(a, b, c, d) binstf(a, b, c, d, false); template <class T> T dpow(T a, T power) { T result = 1; while (power) { if (power % 2) result *= a; power /= 2, a = a * a; } return result; } const ld PI = acos((ld)-1); mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template <class T> bool reorder(T &a, T &b) { return (a > b) ? swap(a, b), 1 : 0; } // INPUT template <class A> void re(complex<A> &c); template <class A, class B> void re(pair<A, B> &p); template <class A> void re(vector<A> &v); template <class A, size_t SZ> void re(array<A, SZ> &a); #define ore(type, x) \ type x; \ re(x); #define ire(x) ore(int, x); #define vire(x) ore(vi, x); #define lre(x) ore(ll, x); template <class T> void re(T &x) { cin >> x; } void re(db &d) { str t; re(t); d = stod(t); } void re(ld &d) { str t; re(t); d = stold(t); } template <class H, class... T> void re(H &h, T &...t) { re(h); re(t...); } template <class A> void re(complex<A> &c) { A a, b; re(a, b); c = {a, b}; } template <class A, class B> void re(pair<A, B> &p) { re(p.first, p.second); } template <class A> void re(vector<A> &x) { trav(a, x) re(a); } template <class A, size_t SZ> void re(array<A, SZ> &x) { trav(a, x) re(a); } template <class T> T gcd(T a, T b) { a = a < 0 ? -a : a; b = b < 0 ? -b : b; if (a * b == 0) return max(a, b); else return gcd(min(a, b), max(a, b) % min(a, b)); } const int MODE107 = 1000000007; template <class T> T modop(T a, T mode = MODE107) { a = a % mode; if (a < 0) a += mode; return a; } template <class T> T inv(T a, T mode = MODE107) { T coefa = 1, coefb = 0; T aa = a, bb = mode; while (aa != 1) { if (aa > bb) swap(coefa, coefb), swap(aa, bb); T cc = bb / aa; bb -= cc * aa, coefb -= cc * coefa; swap(coefa, coefb), swap(aa, bb); } return coefa; } const int uplrDX[] = {-1, 1, 0, 0}; const int uplrDY[] = {0, 0, -1, 1}; #define ts to_string str ts(char c) { return str(1, c); } str ts(bool b) { return b ? "true" : "false"; } str ts(const char *s) { return (str)s; } str ts(str s) { return s; } template <class A> str ts(complex<A> c) { stringstream ss; ss << c; return ss.str(); } str ts(vector<bool> v) { str res = "{"; f0r(i, sz(v)) res += char('0' + v[i]); res += "}"; return res; } template <size_t SZ> str ts(bitset<SZ> b) { str res = ""; f0r(i, SZ) res += char('0' + b[i]); return res; } template <class A, class B> str ts(pair<A, B> p); template <class T> str ts(T v) { // containers with begin(), end() bool fst = 1; str res = "{"; for (const auto &x : v) { if (!fst) res += ", "; fst = 0; res += ts(x); } res += "}"; return res; } template <class A, class B> str ts(pair<A, B> p) { return "(" + ts(p.first) + ", " + ts(p.second) + ")"; } // OUTPUT template <class A> void pr(A x) { cout << ts(x); } template <class H, class... T> void pr(const H &h, const T &...t) { pr(h); pr(t...); } void ps() { pr("\n"); } // print w/ spaces template <class H, class... T> void ps(const H &h, const T &...t) { pr(h); if (sizeof...(t)) pr(" "); ps(t...); } // DEBUG void DBG() { cerr << "]" << endl; } template <class H, class... T> void DBG(H h, T... t) { cerr << ts(h); if (sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef LOCAL // compile with -DLOCAL #define dbg(...) \ cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", \ DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif // REINITIALIZE ARRAYS BETWEEN TCs /** * Description: Use in place of \texttt{complex<T>}. * Source: http://codeforces.com/blog/entry/22175, KACTL * Verification: various */ typedef int T; int sgn(T a) { return (a > 0) - (a < 0); } T sq(T a) { return a * a; } // using namespace Point; typedef unsigned long long ull; class trie { public: map<char, trie> l; void add(string t) { if (t.length() > 0) { l[t[0]].add(t.substr(1)); } } bool contains(string t) { if (not l.count(t[0])) return false; return l[t[0]].contains(t.substr(1)); } }; template <class T> class rq { /* range query */ vector<vector<T>> content; function<T(T, T)> op; public: rq(vector<T> &orig, function<T(T, T)> operation) { op = operation; int size = 1; content.emplace_back(orig); while (size < orig.size()) { size *= 2; content.emplace_back(0); auto &todo = content.back(), &from = content[content.size() - 2]; f0r(i, sz(from) - size / 2) { todo.eb(op(from[i], from[i + size / 2])); //[i ~ i+s[ = [i, i+s/2[ + [i+s/2,i+s[ } } } T query(int i, int j) { //[i,j[ if (j <= i or j > content[0].size() or i < 0 or i >= content[0].size()) { cerr << "i=" << i << endl; cerr << "j=" << j << endl; throw "bad i j"; } tie(i, j) = mp(min(i, j), max(i, j)); int size = 1, pow = 0; while (size * 2 < j - i) { size *= 2, pow++; } assert(pow < content.size()); auto &c = content[pow]; assert(i < c.size() and i >= 0); assert(j - size < c.size() and j - size >= 0); T dbg = op(content[pow][i], content[pow][j - size]); return dbg; } }; template <class T> class maxflow { public: typedef T unit; int src, drn; // source and drain node id vector<vi> adj, radj; map<pi, unit> lims; map<pi, unit> rlims; // will contain solution after solve() void genradj() { radj.resize(sz(adj)); f0r(from, sz(adj)) { trav(to, adj[from]) { radj[to].emplace_back(from); } } } unit solve() { while (true) { map<int, pair<pi, unit>> backtrack; bool found = false; set<int> seen; // bfs from src queue<pair<int, unit>> todo; todo.emplace(src, -1); while (not todo.empty()) { int from = todo.front().first; unit bottleneck = todo.front().second; todo.pop(); if (from == drn) { found = true; break; } trav(to, adj[from]) { pi edge = mp(from, to); unit bn = min(bottleneck, lims[edge]); if (bn and not seen.count(to)) { seen.emplace(to); todo.emplace(to, bn); backtrack[to] = mp(edge, bn); } } trav(to, radj[from]) { pi edge = mp(to, from); unit bn = min(bottleneck, rlims[edge]); if (bn and not seen.count(to)) { seen.emplace(to); todo.emplace(to, bn); backtrack[to] = mp(edge, bn); } } } if (not found) break; else { list<pi> edges; int to = drn; unit flow = backtrack[to].second; while (to != src) { pi edge = backtrack[to].first; int from = edge.first + edge.second - to; edges.emplace_front(edge); to = from; } int from = src; trav(e, edges) { if (e.first == from) rlims[e] += flow, lims[e] -= flow; else rlims[e] -= flow, lims[e] += flow; from = e.first + e.second - from; } } } unit res = 0; trav(to, adj[src]) res += rlims[mp(src, to)]; return res; } }; template <class T> class SuffArr { public: vector<vi> pow2ranks; int loop; int n; SuffArr() {} SuffArr(vector<T> &in, int loop_) { reset(in, loop_); } SuffArr(string &in, int loop_) { vector<T> cached; trav(c, in) cached.emplace_back(c); reset(cached, loop_); } void reset(string &in, int loop_) { vector<T> cached; trav(c, in) cached.emplace_back(c); reset(cached, loop_); } void reset(vector<T> &in, int loop_) { // N chars in charspace K loop = loop_, n = in.size(); pow2ranks.clear(); { vector<pair<T, int>> initial; map<T, queue<int>> shelf; f0r(i, n) shelf[in[i]].emplace(i); // logK per write, NlogK for (pair<const T, queue<int>> &kv : shelf) { auto &block = kv.second; while (not block.empty()) initial.emplace_back(kv.first, block.front()), block.pop(); } int uid = 0, val = initial[0].first; pow2ranks.emplace_back(), pow2ranks.back().resize(n); trav(e, initial) { // N if (val < e.first) uid++; pow2ranks[0][e.second] = uid, val = e.first; } } int pow = 0, sz = 1; vector<queue<pair<pi, int>>> shelf(n); //(rank1,rank2),index while (sz < n) { // logN loops int newpow = pow + 1, newsz = sz * 2; pow2ranks.emplace_back(), pow2ranks.back().resize(n); auto &oldrank = pow2ranks[pow], &newrank = pow2ranks[newpow]; vector<pair<pi, int>> tobesorted; f0r(i, n) { // N int j = sanitize(i + sz); tobesorted.emplace_back(mp(mp(oldrank[i], oldrank[j]), i)); } trav(e, tobesorted) shelf[e.first.second].emplace(e); // N tobesorted.clear(); trav(block, shelf) while (not block.empty()) { auto e = block.front(); block.pop(); tobesorted.emplace_back(e); } trav(e, tobesorted) shelf[e.first.first].emplace(e); // N tobesorted.clear(); trav(block, shelf) while (not block.empty()) { auto e = block.front(); block.pop(); tobesorted.emplace_back(e); } int uid = 0; pi val = tobesorted[0].first; trav(e, tobesorted) { if (val < e.first) uid++; newrank[e.second] = uid, val = e.first; } pow = newpow, sz = newsz; } } inline int sanitize(int i) { int excess = max(i - n + 1, 0); i -= ((excess % loop > 0) + (excess / loop)) * loop; return i; } inline pair<int, int> query(int i, int len = -1) { // log len time i = sanitize(i); if (len == -1) { return mp(pow2ranks.back()[i], pow2ranks.back()[i]); } if (len == 0) { return mp(0, 0); } else { int sz = 1, pow = 0; while ((sz << 1) < len) sz = sz << 1, pow++; // log len time int j = sanitize(i + len - sz); return mp(pow2ranks[pow][i], pow2ranks[pow][j]); } } }; auto __tic__ = chrono::high_resolution_clock::now(); void tic() { __tic__ = chrono::high_resolution_clock::now(); } int toc() { int elapsed = chrono::duration_cast<chrono::microseconds>( chrono::high_resolution_clock::now() - __tic__) .count(); return elapsed; } void precalc() { // start here } // helper fuctions here void solve(int ti) { // start here int h, w, m; re(h, w, m); vi hcount(h, 0); vi wcount(w, 0); set<pi> targets; f0r(i, m) { int x, y; re(x, y); x--, y--; hcount[x]++; wcount[y]++; targets.emplace(x, y); } int besth = 0, bestw = 0; trav(e, hcount) ckmax(besth, e); trav(e, wcount) ckmax(bestw, e); vi xs, ys; f0r(i, h) if (hcount[i] == besth) xs.eb(i); f0r(i, w) if (wcount[i] == bestw) ys.eb(i); int best = 0; trav(x, xs) trav(y, ys) ckmax(best, besth + bestw - (int)targets.count(mp(x, y))); ps(best); } int main() { precalc(); bool online = true; #ifdef OFFLINE online = false; if (online) boost(); string testinputs[] = { R"( 2 3 3 2 2 1 1 1 3 )", // R"(3 2 // 1 1 0 // 1 2 // 1 3 // //)", }; // TODO trav(testinput, testinputs) { istringstream iss(testinput); cout << "---local mode---" << endl; cin.rdbuf(iss.rdbuf()); #endif // setIO("A"); int T = 1; { // re(T); } vfor(i, 1, T + 1) { // cout << "Case #" << i << ": ";//Google Code jam solve(i); } #ifdef OFFLINE } #endif }
using namespace std; #include <bits/stdc++.h> typedef long long ll; typedef long double ld; typedef double db; typedef string str; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<db, db> pd; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<ll> vl; typedef vector<db> vd; typedef vector<str> vs; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<pd> vpd; typedef set<int> si; typedef set<ll> sl; typedef map<int, int> mii; #define mp make_pair #define sz(x) (int)x.size() #define len(x) (int)x.size() #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define rsz resize #define ins insert #define ft front() #define bk back() // #define pf push_front // #define pb push_back #define eb emplace_back #define ep emplace #define lb lower_bound #define ub upper_bound #define vfor(i, a, b) for (int i = (a); i < (b); ++i) #define f0r(i, a) vfor(i, 0, a) #define rof(i, a, b) for (int i = (b)-1; i >= (a); --i) #define r0f(i, a) rof(i, 0, a) #define trav(a, x) for (auto &a : x) #define def(fname, rtype, args, ...) \ function<rtype args> fname = [__VA_ARGS__] args #define boost() cin.tie(0), cin.sync_with_stdio(0) template <class T> void binstf(T &found, T a, T b, function<bool(T)> test, bool TF = true) { T i = a, j = b; bool da = test(a), db = test(b); if ((da != TF) or (db == TF)) { cerr << "---[BS: TF = " << TF << "]---" << endl; cerr << a << "->" << da << endl; cerr << b << "->" << db << endl; } while (j - i > 1) { T m = (i + j) / 2; if (test(m) == TF) i = m; else j = m; } found = i; if (not TF) found++; } #define binsft(a, b, c, d) binstf(a, b, c, d, false); template <class T> T dpow(T a, T power) { T result = 1; while (power) { if (power % 2) result *= a; power /= 2, a = a * a; } return result; } const ld PI = acos((ld)-1); mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template <class T> bool reorder(T &a, T &b) { return (a > b) ? swap(a, b), 1 : 0; } // INPUT template <class A> void re(complex<A> &c); template <class A, class B> void re(pair<A, B> &p); template <class A> void re(vector<A> &v); template <class A, size_t SZ> void re(array<A, SZ> &a); #define ore(type, x) \ type x; \ re(x); #define ire(x) ore(int, x); #define vire(x) ore(vi, x); #define lre(x) ore(ll, x); template <class T> void re(T &x) { cin >> x; } void re(db &d) { str t; re(t); d = stod(t); } void re(ld &d) { str t; re(t); d = stold(t); } template <class H, class... T> void re(H &h, T &...t) { re(h); re(t...); } template <class A> void re(complex<A> &c) { A a, b; re(a, b); c = {a, b}; } template <class A, class B> void re(pair<A, B> &p) { re(p.first, p.second); } template <class A> void re(vector<A> &x) { trav(a, x) re(a); } template <class A, size_t SZ> void re(array<A, SZ> &x) { trav(a, x) re(a); } template <class T> T gcd(T a, T b) { a = a < 0 ? -a : a; b = b < 0 ? -b : b; if (a * b == 0) return max(a, b); else return gcd(min(a, b), max(a, b) % min(a, b)); } const int MODE107 = 1000000007; template <class T> T modop(T a, T mode = MODE107) { a = a % mode; if (a < 0) a += mode; return a; } template <class T> T inv(T a, T mode = MODE107) { T coefa = 1, coefb = 0; T aa = a, bb = mode; while (aa != 1) { if (aa > bb) swap(coefa, coefb), swap(aa, bb); T cc = bb / aa; bb -= cc * aa, coefb -= cc * coefa; swap(coefa, coefb), swap(aa, bb); } return coefa; } const int uplrDX[] = {-1, 1, 0, 0}; const int uplrDY[] = {0, 0, -1, 1}; #define ts to_string str ts(char c) { return str(1, c); } str ts(bool b) { return b ? "true" : "false"; } str ts(const char *s) { return (str)s; } str ts(str s) { return s; } template <class A> str ts(complex<A> c) { stringstream ss; ss << c; return ss.str(); } str ts(vector<bool> v) { str res = "{"; f0r(i, sz(v)) res += char('0' + v[i]); res += "}"; return res; } template <size_t SZ> str ts(bitset<SZ> b) { str res = ""; f0r(i, SZ) res += char('0' + b[i]); return res; } template <class A, class B> str ts(pair<A, B> p); template <class T> str ts(T v) { // containers with begin(), end() bool fst = 1; str res = "{"; for (const auto &x : v) { if (!fst) res += ", "; fst = 0; res += ts(x); } res += "}"; return res; } template <class A, class B> str ts(pair<A, B> p) { return "(" + ts(p.first) + ", " + ts(p.second) + ")"; } // OUTPUT template <class A> void pr(A x) { cout << ts(x); } template <class H, class... T> void pr(const H &h, const T &...t) { pr(h); pr(t...); } void ps() { pr("\n"); } // print w/ spaces template <class H, class... T> void ps(const H &h, const T &...t) { pr(h); if (sizeof...(t)) pr(" "); ps(t...); } // DEBUG void DBG() { cerr << "]" << endl; } template <class H, class... T> void DBG(H h, T... t) { cerr << ts(h); if (sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef LOCAL // compile with -DLOCAL #define dbg(...) \ cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", \ DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif // REINITIALIZE ARRAYS BETWEEN TCs /** * Description: Use in place of \texttt{complex<T>}. * Source: http://codeforces.com/blog/entry/22175, KACTL * Verification: various */ typedef int T; int sgn(T a) { return (a > 0) - (a < 0); } T sq(T a) { return a * a; } // using namespace Point; typedef unsigned long long ull; class trie { public: map<char, trie> l; void add(string t) { if (t.length() > 0) { l[t[0]].add(t.substr(1)); } } bool contains(string t) { if (not l.count(t[0])) return false; return l[t[0]].contains(t.substr(1)); } }; template <class T> class rq { /* range query */ vector<vector<T>> content; function<T(T, T)> op; public: rq(vector<T> &orig, function<T(T, T)> operation) { op = operation; int size = 1; content.emplace_back(orig); while (size < orig.size()) { size *= 2; content.emplace_back(0); auto &todo = content.back(), &from = content[content.size() - 2]; f0r(i, sz(from) - size / 2) { todo.eb(op(from[i], from[i + size / 2])); //[i ~ i+s[ = [i, i+s/2[ + [i+s/2,i+s[ } } } T query(int i, int j) { //[i,j[ if (j <= i or j > content[0].size() or i < 0 or i >= content[0].size()) { cerr << "i=" << i << endl; cerr << "j=" << j << endl; throw "bad i j"; } tie(i, j) = mp(min(i, j), max(i, j)); int size = 1, pow = 0; while (size * 2 < j - i) { size *= 2, pow++; } assert(pow < content.size()); auto &c = content[pow]; assert(i < c.size() and i >= 0); assert(j - size < c.size() and j - size >= 0); T dbg = op(content[pow][i], content[pow][j - size]); return dbg; } }; template <class T> class maxflow { public: typedef T unit; int src, drn; // source and drain node id vector<vi> adj, radj; map<pi, unit> lims; map<pi, unit> rlims; // will contain solution after solve() void genradj() { radj.resize(sz(adj)); f0r(from, sz(adj)) { trav(to, adj[from]) { radj[to].emplace_back(from); } } } unit solve() { while (true) { map<int, pair<pi, unit>> backtrack; bool found = false; set<int> seen; // bfs from src queue<pair<int, unit>> todo; todo.emplace(src, -1); while (not todo.empty()) { int from = todo.front().first; unit bottleneck = todo.front().second; todo.pop(); if (from == drn) { found = true; break; } trav(to, adj[from]) { pi edge = mp(from, to); unit bn = min(bottleneck, lims[edge]); if (bn and not seen.count(to)) { seen.emplace(to); todo.emplace(to, bn); backtrack[to] = mp(edge, bn); } } trav(to, radj[from]) { pi edge = mp(to, from); unit bn = min(bottleneck, rlims[edge]); if (bn and not seen.count(to)) { seen.emplace(to); todo.emplace(to, bn); backtrack[to] = mp(edge, bn); } } } if (not found) break; else { list<pi> edges; int to = drn; unit flow = backtrack[to].second; while (to != src) { pi edge = backtrack[to].first; int from = edge.first + edge.second - to; edges.emplace_front(edge); to = from; } int from = src; trav(e, edges) { if (e.first == from) rlims[e] += flow, lims[e] -= flow; else rlims[e] -= flow, lims[e] += flow; from = e.first + e.second - from; } } } unit res = 0; trav(to, adj[src]) res += rlims[mp(src, to)]; return res; } }; template <class T> class SuffArr { public: vector<vi> pow2ranks; int loop; int n; SuffArr() {} SuffArr(vector<T> &in, int loop_) { reset(in, loop_); } SuffArr(string &in, int loop_) { vector<T> cached; trav(c, in) cached.emplace_back(c); reset(cached, loop_); } void reset(string &in, int loop_) { vector<T> cached; trav(c, in) cached.emplace_back(c); reset(cached, loop_); } void reset(vector<T> &in, int loop_) { // N chars in charspace K loop = loop_, n = in.size(); pow2ranks.clear(); { vector<pair<T, int>> initial; map<T, queue<int>> shelf; f0r(i, n) shelf[in[i]].emplace(i); // logK per write, NlogK for (pair<const T, queue<int>> &kv : shelf) { auto &block = kv.second; while (not block.empty()) initial.emplace_back(kv.first, block.front()), block.pop(); } int uid = 0, val = initial[0].first; pow2ranks.emplace_back(), pow2ranks.back().resize(n); trav(e, initial) { // N if (val < e.first) uid++; pow2ranks[0][e.second] = uid, val = e.first; } } int pow = 0, sz = 1; vector<queue<pair<pi, int>>> shelf(n); //(rank1,rank2),index while (sz < n) { // logN loops int newpow = pow + 1, newsz = sz * 2; pow2ranks.emplace_back(), pow2ranks.back().resize(n); auto &oldrank = pow2ranks[pow], &newrank = pow2ranks[newpow]; vector<pair<pi, int>> tobesorted; f0r(i, n) { // N int j = sanitize(i + sz); tobesorted.emplace_back(mp(mp(oldrank[i], oldrank[j]), i)); } trav(e, tobesorted) shelf[e.first.second].emplace(e); // N tobesorted.clear(); trav(block, shelf) while (not block.empty()) { auto e = block.front(); block.pop(); tobesorted.emplace_back(e); } trav(e, tobesorted) shelf[e.first.first].emplace(e); // N tobesorted.clear(); trav(block, shelf) while (not block.empty()) { auto e = block.front(); block.pop(); tobesorted.emplace_back(e); } int uid = 0; pi val = tobesorted[0].first; trav(e, tobesorted) { if (val < e.first) uid++; newrank[e.second] = uid, val = e.first; } pow = newpow, sz = newsz; } } inline int sanitize(int i) { int excess = max(i - n + 1, 0); i -= ((excess % loop > 0) + (excess / loop)) * loop; return i; } inline pair<int, int> query(int i, int len = -1) { // log len time i = sanitize(i); if (len == -1) { return mp(pow2ranks.back()[i], pow2ranks.back()[i]); } if (len == 0) { return mp(0, 0); } else { int sz = 1, pow = 0; while ((sz << 1) < len) sz = sz << 1, pow++; // log len time int j = sanitize(i + len - sz); return mp(pow2ranks[pow][i], pow2ranks[pow][j]); } } }; auto __tic__ = chrono::high_resolution_clock::now(); void tic() { __tic__ = chrono::high_resolution_clock::now(); } int toc() { int elapsed = chrono::duration_cast<chrono::microseconds>( chrono::high_resolution_clock::now() - __tic__) .count(); return elapsed; } void precalc() { // start here } // helper fuctions here void solve(int ti) { // start here int h, w, m; re(h, w, m); vi hcount(h, 0); vi wcount(w, 0); set<pi> targets; f0r(i, m) { int x, y; re(x, y); x--, y--; hcount[x]++; wcount[y]++; targets.emplace(x, y); } int besth = 0, bestw = 0; trav(e, hcount) ckmax(besth, e); trav(e, wcount) ckmax(bestw, e); vi xs, ys; f0r(i, h) if (hcount[i] == besth) xs.eb(i); f0r(i, w) if (wcount[i] == bestw) ys.eb(i); int crosscount = 0; trav(t, targets) { if (hcount[t.first] == besth and wcount[t.second] == bestw) crosscount++; } if ((ll)crosscount < (ll)sz(xs) * (ll)sz(ys)) ps(besth + bestw); else ps(besth + bestw - 1); } int main() { precalc(); bool online = true; #ifdef OFFLINE online = false; if (online) boost(); string testinputs[] = { R"( 2 3 3 2 2 1 1 1 3 )", // R"(3 2 // 1 1 0 // 1 2 // 1 3 // //)", }; // TODO trav(testinput, testinputs) { istringstream iss(testinput); cout << "---local mode---" << endl; cin.rdbuf(iss.rdbuf()); #endif // setIO("A"); int T = 1; { // re(T); } vfor(i, 1, T + 1) { // cout << "Case #" << i << ": ";//Google Code jam solve(i); } #ifdef OFFLINE } #endif }
replace
552
556
552
561
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long map<int, int> row, col; vector<int> a, b; map<pair<int, int>, int> mp; signed main() { int n, m, k; cin >> n >> m >> k; int maxn_row = -1, maxn_col = -1; for (int i = 0; i < k; i++) { int x, y; cin >> x >> y; row[x]++, col[y]++; maxn_row = max(maxn_row, row[x]); maxn_col = max(maxn_col, col[y]); mp[make_pair(x, y)] = 1; } for (int i = 1; i <= n; i++) if (maxn_row == row[i]) a.push_back(i); for (int i = 1; i <= m; i++) if (maxn_col == col[i]) b.push_back(i); int maxn = 0; for (int i = 0; i < a.size(); i++) for (int j = 0; j < b.size(); j++) maxn = max(maxn, row[a[i]] + col[b[j]] - mp[make_pair(a[i], b[j])]); cout << maxn; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long map<int, int> row, col; vector<int> a, b; map<pair<int, int>, int> mp; signed main() { int n, m, k; cin >> n >> m >> k; int maxn_row = -1, maxn_col = -1; for (int i = 0; i < k; i++) { int x, y; cin >> x >> y; row[x]++, col[y]++; maxn_row = max(maxn_row, row[x]); maxn_col = max(maxn_col, col[y]); mp[make_pair(x, y)] = 1; } for (int i = 1; i <= n; i++) if (maxn_row == row[i]) a.push_back(i); for (int i = 1; i <= m; i++) if (maxn_col == col[i]) b.push_back(i); int maxn = 0; sort(a.begin(), a.end(), greater<int>()), sort(b.begin(), b.end(), greater<int>()); for (int i = 0; i < a.size(); i++) { for (int j = 0; j < b.size(); j++) { if (!mp[make_pair(a[i], b[j])]) { cout << max(maxn, row[a[i]] + col[b[j]]); return 0; } else { maxn = max(maxn, row[a[i]] + col[b[j]] - 1); } } } cout << maxn; return 0; }
replace
26
29
26
39
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; int row[30020]; int maxi[30020]; int col[30020]; vector<pii> cols; map<pii, int> m; int main() { int H, W, M, ans = 0; scanf("%d%d%d", &H, &W, &M); for (int i = 0, x, y; i < M; i++) { scanf("%d%d", &x, &y); m[{x, y}] = 1; row[x]++; col[y]++; } for (int i = 1; i <= W; i++) { cols.push_back({col[i], i}); } sort(cols.begin(), cols.end(), greater<pii>()); for (int i = 1; i <= H; i++) { for (int j = 0; j < W; j++) { if (!m.count({i, cols[j].second})) { maxi[i] = max(maxi[i], cols[j].first + row[i]); break; } else { maxi[i] = max(maxi[i], cols[j].first + row[i] - 1); } } ans = max(ans, maxi[i]); } printf("%d", ans); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; int row[300020]; int maxi[300020]; int col[300020]; vector<pii> cols; map<pii, int> m; int main() { int H, W, M, ans = 0; scanf("%d%d%d", &H, &W, &M); for (int i = 0, x, y; i < M; i++) { scanf("%d%d", &x, &y); m[{x, y}] = 1; row[x]++; col[y]++; } for (int i = 1; i <= W; i++) { cols.push_back({col[i], i}); } sort(cols.begin(), cols.end(), greater<pii>()); for (int i = 1; i <= H; i++) { for (int j = 0; j < W; j++) { if (!m.count({i, cols[j].second})) { maxi[i] = max(maxi[i], cols[j].first + row[i]); break; } else { maxi[i] = max(maxi[i], cols[j].first + row[i] - 1); } } ans = max(ans, maxi[i]); } printf("%d", ans); }
replace
5
8
5
8
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define endl '\n' typedef pair<int, int> P; typedef long long ll; set<P> Check; int H[30005], W[30005]; int main() { // cin.tie(0); // ios_base::sync_with_stdio(false); int h, w, m; cin >> h >> w; cin >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; Check.insert(make_pair(x, y)); H[x]++; W[y]++; } int hmax = 0, wmax = 0; for (int x = 1; x <= h; x++) { if (H[x] > hmax) hmax = H[x]; } for (int y = 1; y <= w; y++) { if (W[y] > wmax) wmax = W[y]; } // cout << "max " << hmax << " " << wmax <<endl; int hnum = 0, wnum = 0; vector<int> hval, wval; for (int x = 1; x <= h; x++) { if (H[x] == hmax) { hval.push_back(x); hnum++; // cout << x << " "; } } // cout <<endl; for (int y = 1; y <= w; y++) { if (W[y] == wmax) { wval.push_back(y); wnum++; // cout << y << " "; } } // cout << endl; // cout << "cal" << endl; for (int i = 0; i < hnum; i++) { for (int j = 0; j < wnum; j++) { // cout <<hval[i] << " " << wval[j] <<endl; if (Check.count(make_pair(hval[i], wval[j])) == 0) { cout << hmax + wmax; // cout << "hello"; return 0; } } } cout << hmax + wmax - 1; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define endl '\n' typedef pair<int, int> P; typedef long long ll; set<P> Check; int H[300005], W[300005]; int main() { // cin.tie(0); // ios_base::sync_with_stdio(false); int h, w, m; cin >> h >> w; cin >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; Check.insert(make_pair(x, y)); H[x]++; W[y]++; } int hmax = 0, wmax = 0; for (int x = 1; x <= h; x++) { if (H[x] > hmax) hmax = H[x]; } for (int y = 1; y <= w; y++) { if (W[y] > wmax) wmax = W[y]; } // cout << "max " << hmax << " " << wmax <<endl; int hnum = 0, wnum = 0; vector<int> hval, wval; for (int x = 1; x <= h; x++) { if (H[x] == hmax) { hval.push_back(x); hnum++; // cout << x << " "; } } // cout <<endl; for (int y = 1; y <= w; y++) { if (W[y] == wmax) { wval.push_back(y); wnum++; // cout << y << " "; } } // cout << endl; // cout << "cal" << endl; for (int i = 0; i < hnum; i++) { for (int j = 0; j < wnum; j++) { // cout <<hval[i] << " " << wval[j] <<endl; if (Check.count(make_pair(hval[i], wval[j])) == 0) { cout << hmax + wmax; // cout << "hello"; return 0; } } } cout << hmax + wmax - 1; return 0; }
replace
7
8
7
8
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; bool bad(const pair<int, int> &p1, const pair<int, int> &p2) { return p1.first > p2.first; } void solve() { int H, W, M; cin >> H >> W >> M; vector<int> row(H, 0); vector<int> col(W, 0); set<pair<int, int>> st; for (int i = 0; i < M; ++i) { int h, w; cin >> h >> w; h--; w--; row[h]++; col[w]++; st.insert({h, w}); } set<pair<int, int>, greater<pair<int, int>>> st1; set<pair<int, int>, greater<pair<int, int>>> st2; for (int i = 0; i < H; ++i) { if (row[i] == 0) continue; st1.emplace(row[i], i); } for (int i = 0; i < W; ++i) { if (col[i] == 0) continue; st2.emplace(col[i], i); } int ans = 0; for (auto it1 = st1.begin(); it1 != st1.end(); ++it1) { if (bad(*st1.begin(), *it1)) break; for (auto it2 = st2.begin(); it2 != st2.end(); ++it2) { if (bad(*st2.begin(), *it2)) break; int temp = it1->first + it2->first; if (st.count({it1->second, it2->second})) { temp--; } ans = max(ans, temp); } } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; bool bad(const pair<int, int> &p1, const pair<int, int> &p2) { return p1.first > p2.first; } void solve() { int H, W, M; cin >> H >> W >> M; vector<int> row(H, 0); vector<int> col(W, 0); set<pair<int, int>> st; for (int i = 0; i < M; ++i) { int h, w; cin >> h >> w; h--; w--; row[h]++; col[w]++; st.insert({h, w}); } set<pair<int, int>, greater<pair<int, int>>> st1; set<pair<int, int>, greater<pair<int, int>>> st2; for (int i = 0; i < H; ++i) { if (row[i] == 0) continue; st1.emplace(row[i], i); } for (int i = 0; i < W; ++i) { if (col[i] == 0) continue; st2.emplace(col[i], i); } int ans = 0; for (auto it1 = st1.begin(); it1 != st1.end(); ++it1) { if (bad(*st1.begin(), *it1)) break; for (auto it2 = st2.begin(); it2 != st2.end(); ++it2) { if (bad(*st2.begin(), *it2)) break; int temp = it1->first + it2->first; if (st.count({it1->second, it2->second})) { temp--; } if (ans > temp) { cout << ans << endl; return; } ans = max(ans, temp); } } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; while (t--) { solve(); } }
insert
47
47
47
51
TLE
p02580
C++
Runtime Error
#include <memory.h> #include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> using namespace std; #define MOD 1000000007 int main() { int h, w; cin >> h >> w; int m; cin >> m; int hcnt[300010] = {}; int wcnt[300010] = {}; set<pair<int, int>> s; for (int i = 0; i < m; i++) { int hi, wi; cin >> hi >> wi; hi--; wi--; s.insert(make_pair(hi, wi)); hcnt[hi]++; wcnt[wi]++; } vector<pair<int, int>> sortedHcnt; vector<pair<int, int>> sortedWcnt; for (int i = 0; i < h; i++) { if (hcnt[i] > 0) sortedHcnt.push_back(make_pair(hcnt[i], i)); } for (int i = 0; i < w; i++) { if (wcnt[i] > 0) sortedWcnt.push_back(make_pair(wcnt[i], i)); } sort(sortedHcnt.begin(), sortedHcnt.end()); sort(sortedWcnt.begin(), sortedWcnt.end()); int ans = 0; int sh = sortedHcnt.size(); int sw = sortedWcnt.size(); for (int i = sh - 1; i >= 0; i--) { if (sortedHcnt[i].first != sortedHcnt[sh - 1].first) { break; } for (int j = sw - 1; j >= 0; j--) { if (sortedWcnt[j].first != sortedWcnt[sw - 1].first) { break; } int res = sortedHcnt[i].first + sortedWcnt[j].first; if (s.find(make_pair(sortedHcnt[i].second, sortedWcnt[i].second)) != s.end()) { res--; ans = max(ans, res); } else { cout << res << endl; return 0; } } } cout << ans << endl; }
#include <memory.h> #include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> using namespace std; #define MOD 1000000007 int main() { int h, w; cin >> h >> w; int m; cin >> m; int hcnt[300010] = {}; int wcnt[300010] = {}; set<pair<int, int>> s; for (int i = 0; i < m; i++) { int hi, wi; cin >> hi >> wi; hi--; wi--; s.insert(make_pair(hi, wi)); hcnt[hi]++; wcnt[wi]++; } vector<pair<int, int>> sortedHcnt; vector<pair<int, int>> sortedWcnt; for (int i = 0; i < h; i++) { if (hcnt[i] > 0) sortedHcnt.push_back(make_pair(hcnt[i], i)); } for (int i = 0; i < w; i++) { if (wcnt[i] > 0) sortedWcnt.push_back(make_pair(wcnt[i], i)); } sort(sortedHcnt.begin(), sortedHcnt.end()); sort(sortedWcnt.begin(), sortedWcnt.end()); int ans = 0; int sh = sortedHcnt.size(); int sw = sortedWcnt.size(); for (int i = sh - 1; i >= 0; i--) { if (sortedHcnt[i].first != sortedHcnt[sh - 1].first) { break; } for (int j = sw - 1; j >= 0; j--) { if (sortedWcnt[j].first != sortedWcnt[sw - 1].first) { break; } int res = sortedHcnt[i].first + sortedWcnt[j].first; if (s.find(make_pair(sortedHcnt[i].second, sortedWcnt[j].second)) != s.end()) { res--; ans = max(ans, res); } else { cout << res << endl; return 0; } } } cout << ans << endl; }
replace
66
67
66
67
0
p02580
C++
Runtime Error
/* ABC026 高橋君の給料 DFS int dfs(int n,vector<vector<int>> G){ int mi = 1000000000; int ma = 0; int w,v; for(int i=0;i<G[n].size();i++){ v = G[n][i]; if(G[v].size() == 0)w = 1; else w = dfs(v,G); mi = min(mi,w); ma = max(ma,w); } return mi + ma + 1; } int main() { int n; cin >> n; Graph G(n+1); for(int i=2;i<=n;i++){ int a; cin >> a; G[a].push_back(i); } int ans = dfs(1,G); cout << ans << endl; } */ // 素因数分解 // ABC169-D - Div Game /* int main() { ll n; cin >> n; vector<pair<ll,ll> > res; for(ll i = 2;i*i <= n;i++){ if(n % i !=0) continue; ll ex = 0;// 指数 //割れる限り割り続ける while(n % i ==0){ ex++; n /=i; } //その結果をpush res.push_back({i,ex}); } //最後に残った数について if(n !=1) res.push_back({n,1}); // cout << n << ":"; // for (auto p : res) { // for (int i = 0; i < p.second; ++i) cout << " " << p.first; // } // cout << endl; ll times = 0; for (auto p : res) { int count = 1; int cnt = 0; while(p.second > cnt){ // cout << p.second << endl; p.second -=count; count++; cnt ++; } times += cnt; } cout << times << endl; } */ // ABC146 //二分探索 /*int main() { ll a,b,x; cin >> a >> b >> x; ll left = 0; ll right = 1000000001; while(right - left > 1){ ll mid = (left + right ) /2; if(a * mid + b * ketasuu(mid) > x) right = mid; else left = mid; // cout << left << " " << right << endl; } cout << left << endl; } */ // ABC_128_B// pair型の中にpair型 /*int main() { int n; cin >> n; vector<pair<pair<string,int>,int>> a(n); for(int i=0;i<n;i++){ string s; cin >> s; int num; cin >> num; num = num * -1; a.at(i).first.first = s; a.at(i).first.second = num; a.at(i).second = i; } sort(a.begin(), a.end()); for(int i=0;i<n;i++){ cout << a.at(i).second +1 << endl; } } */ // ABC_058_Cのように // s.at(j) == a のとき // cout << s.at(j)-'0' - 49 << endl; // とすると、「0」を出力してくれる。 →もっといいほかの方法はないの? // 全bit探索を入れよう!! /*ABC_167_C skill up などを参考に… //https://qiita.com/hareku/items/3d08511eab56a481c7db int main() { int n = 3; // {0, 1, ..., n-1} の部分集合の全探索 for (int bit = 0; bit < (1<<n); ++bit) { vector<int> S; for (int i = 0; i < n; ++i) { if (bit & (1<<i)) { // 列挙に i が含まれるか S.push_back(i); } } cout << bit << ": {"; for (int i = 0; i < (int)S.size(); ++i) { cout << S[i] << " "; } cout << "}" << endl; } } */ // next_permutation(順列列挙) /*https://note.com/memenekokaburi/n/nf0201d6002cd //https://scrapbox.io/ganariya/AtCoderGrandContest022_A%E5%95%8F%E9%A1%8C300%E7%82%B9%E3%80%8CDiverse_Word%E3%80%8D_(copy) //https://atcoder.jp/contests/agc022/tasks/agc022_a ABC_150_Cなど。 int main() { int n; cin >> n ; vector<int>array = {}; for(int i=0;i<n;i++){ array.push_back(i); } do{ for(int i=0; i<n; i++){ cout << array.at(i); if(i!=n-1)cout<<" "; } cout<<endl; }while(next_permutation(array.begin(),array.end())); return 0; } */ // ABC126_Cのように関数でdouble型で返ってきてほしい場合はdouble // kan_halfのようにかく /* //ABC_041_C// pair型 int main() { int n; cin >> n; vector<pair<int,int>>a(n); for(int i=0;i<n;i++){ int num; cin >> num; a.at(i).first = num; a.at(i).second = i; } sort(a.begin(), a.end()); reverse(a.begin(),a.end()); for(int i=0;i<n;i++){ cout << a.at(i).second + 1<< endl; } } */ /*ABC_068_C //boolの配列を使って bool s[200050] = {}; bool t[200050] = {}; int main() { ll n, m; cin >> n >> m; for (int i = 0; i < m; i++){ ll a, b; cin >> a >> b; if (a == 1) { t[b] = true; } if (b == n) { s[a] = true; } } for (int i = 0; i < 200050; i++){ if (s[i] && t[i]) { cout << "POSSIBLE" << endl; return 0; } } cout << "IMPOSSIBLE" << endl; return 0; } */ // int32 4 signed, signed int, int -2,147,483,648 ~ 2,147,483,647 = // 2*10^9 再帰関数 ABC_029_C /* void f(int rest , string s){ if(rest == 0){ cout << s << endl; } else{ for(char moji = 'a' ;moji <='c' ; moji++){ f(rest-1,s+moji); } } } int main() { int n; cin >> n; f(n, ""); } */ // 連想配列 ARC_081_Cの解答 //ABC073でも復習できます。 /* int main() { ll n; cin >> n; vector<ll>a(n); rep(i,n) cin>>a.at(i); map<ll,ll>mp; rep(i,n){ mp[a.at(i)]++; } ll one = 0; ll two = 0; for(auto p:mp){ // cout << p.first << " " << p.second << endl; if(p.second >= 2){ if(one <= p.first){ two = one; one = p.first; } } if(p.second >= 4){ if(one <= p.first){ two = p.first; one = p.first; } } } // cout << one << endl; // cout << two << endl; // cout << endl; cout << one * two << endl; } */ // 関数 /* ll gcd(ll a, ll b){ if (a%b == 0){ return(b); } else{ return(gcd(b, a%b)); } } ll lcm(ll a, ll b){ // return a * b / gcd(a, b); return a / gcd(a, b)* b; } int kan_hyaku(int n){ int kurai = 0; for(int i=0;i<3;i++){ kurai = n%10; n /=10; } return kurai; } int kan_ju(int n){ int kurai = 0; for(int i=0;i<2;i++){ kurai = n%10; n /=10; } return kurai; } int kan_ichi(int n){ int kurai = 0; for(int i=0;i<1;i++){ kurai = n%10; n /=10; } return kurai; } ll keta(ll n){ ll wa = 1; while(n>0){ wa *=10; n--; } return wa; } double kan_half(int n){ double wa = 1; while(n>0){ // cout << "TEST"<<endl; wa *= 0.5; // cout << wa << endl; n--; } return wa; } ll facctorialMethod(ll k){ ll sum = 1; for (ll i = 1; i <= k; ++i) { sum = sum%1000000007 * i%1000000007; } return sum; } int zorocheck(string s){ int count = 0; rep(i,s.size()){ if(s.at(i) == s.at(0)) count++; } if(count ==s.size()){ return 1; } else{ return 0; } } int sannobekijou(int n){ int wa = 1; while(n>0){ n--; wa *=3; } return wa; } ll ketasuu(ll k){ ll wa = 0; while(k > 0){ k /=10; wa++; } return wa; } ll beki(ll f,ll num){ ll wa = 1; while(num > 0){ wa *= f; num--; // cout << wa << endl; } return wa; } ll fibona(ll num){ vector<ll>c(3); c.at(0) = 1; c.at(1) = 2; c.at(2) = 3; if(num == 1){ return c.at(0); } else if(num == 2){ return c.at(1); } else if(num == 3){ return c.at(2); } else{ for(ll i = 3; i < num;i++){ // cout << " tes " << endl; ll tmp; tmp = c.at(1) + c.at(2); tmp %= 1000000007; c.at(0) = c.at(1); c.at(1) = c.at(2); c.at(2) = tmp; } return c.at(2); } } */ // 桁数を指定して出力する方法 // #include <iomanip>//これをincludeしておかないといけない // cout << fixed << setprecision(20)<< ans << endl; // s.at(0) = toupper(s.at(0));//小文字なら大文字へ//大文字の場合はそのまま // s.at(i) = tolower(s.at(i));//大文字なら小文字へ//小文字の場合はそのまま // getline(cin, s); //空白文字を含むものをまとめて入力できる。 // s配列に格納した単語を、辞書順にソートする // sort(s.begin(), s.end()); // string t = "keyence";//で文字列を格納できる // s.empty() //emptyなら1を出力 入っていれば0を出力 /*//ABC018-B 部分的にreverseをかける解法 int main() { string s; cin >> s; int n; cin >> n; vector<int>a(n); vector<int>b(n); rep(i,n) cin>>a.at(i)>>b.at(i); rep(i,n)a.at(i)--; rep(i,n)b.at(i)--; string t; rep(i,n){ t = s; for(int k=0;k<=b.at(i)-a.at(i);k++){ t.at(a.at(i)+k) = s.at(b.at(i)-k); } s = t; } cout << s << endl; } *///ABC018-B // cout << char(i+48) << // endl;//なぜかaは47と得る時がある。+48で出力もaにできる。 cout << char(97) << // endl;//アスキーコードでaを出力 // sort(b.begin(), b.end());//bという配列を小さい方からソート // reverse(b.begin(), b.end());//bという配列をリターン /*01 02 03 12 13 23 と6回見ていくパターン for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ } } */ // vector<vector<int>> a(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言 // 10のi乗pow(10, i);//ただしdouble型のため注意 /*string s; stringでの文字列を数字型に変える方法 cin >> s; rep(i,s.size()-2) { int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0'; */ /* int n; cin >> n; vector<int>a(n); rep(i,n) cin >> a.at(i); */ // cout << fixed << setprecision(10)<< ans << endl; // 数字から文字列に変換 a.at(0) = std::to_string(111); #include <bits/stdc++.h> #include <iomanip> //これをincludeしておかないといけない #include <iostream> #include <queue> #include <vector> using namespace std; using Graph = vector<vector<int>>; typedef long long ll; typedef long double lld; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define PI 3.14159265359 #define MOD 1000000007 int main() { int h, w, m; cin >> h >> w >> m; // vector<vector<int>> a(h, // vector<int>(w));//int型の2次元配列(3×4要素の)の宣言 vector<int> h_sum(h); vector<int> w_sum(w); vector<int> w_check(w); vector<pair<int, int>> a(m); rep(i, m) { int k, t; cin >> k >> t; --k; --t; h_sum.at(k)++; w_sum.at(t)++; a.at(i).first = k; a.at(i).second = t; } int ma_h = 0; int ma_w = 0; int ma_h_i = 0; int ma_w_j = 0; rep(i, h) { ma_h = max(ma_h, h_sum.at(i)); } rep(i, h) { ma_w = max(ma_w, w_sum.at(i)); } vector<int> ma_h_only; vector<int> ma_w_only; rep(i, h) { if (h_sum.at(i) == ma_h) { ma_h_only.push_back(i); } } rep(i, w) { if (w_sum.at(i) == ma_w) { ma_w_only.push_back(i); } } int flag = 0; rep(i, ma_h_only.size()) { rep(j, ma_w_only.size()) { rep(p, m) { // cout << ma_h_only.at(i) << "&&" << a.at(p).first << endl; // cout << ma_w_only.at(j) << "&&" << a.at(p).second << endl; if (ma_h_only.at(i) != a.at(p).first && ma_w_only.at(j) != a.at(p).second) { flag = 1; } } } } int ans = ma_h + ma_w; if (flag == 1) cout << ans - 1 << endl; else cout << ans << endl; }
/* ABC026 高橋君の給料 DFS int dfs(int n,vector<vector<int>> G){ int mi = 1000000000; int ma = 0; int w,v; for(int i=0;i<G[n].size();i++){ v = G[n][i]; if(G[v].size() == 0)w = 1; else w = dfs(v,G); mi = min(mi,w); ma = max(ma,w); } return mi + ma + 1; } int main() { int n; cin >> n; Graph G(n+1); for(int i=2;i<=n;i++){ int a; cin >> a; G[a].push_back(i); } int ans = dfs(1,G); cout << ans << endl; } */ // 素因数分解 // ABC169-D - Div Game /* int main() { ll n; cin >> n; vector<pair<ll,ll> > res; for(ll i = 2;i*i <= n;i++){ if(n % i !=0) continue; ll ex = 0;// 指数 //割れる限り割り続ける while(n % i ==0){ ex++; n /=i; } //その結果をpush res.push_back({i,ex}); } //最後に残った数について if(n !=1) res.push_back({n,1}); // cout << n << ":"; // for (auto p : res) { // for (int i = 0; i < p.second; ++i) cout << " " << p.first; // } // cout << endl; ll times = 0; for (auto p : res) { int count = 1; int cnt = 0; while(p.second > cnt){ // cout << p.second << endl; p.second -=count; count++; cnt ++; } times += cnt; } cout << times << endl; } */ // ABC146 //二分探索 /*int main() { ll a,b,x; cin >> a >> b >> x; ll left = 0; ll right = 1000000001; while(right - left > 1){ ll mid = (left + right ) /2; if(a * mid + b * ketasuu(mid) > x) right = mid; else left = mid; // cout << left << " " << right << endl; } cout << left << endl; } */ // ABC_128_B// pair型の中にpair型 /*int main() { int n; cin >> n; vector<pair<pair<string,int>,int>> a(n); for(int i=0;i<n;i++){ string s; cin >> s; int num; cin >> num; num = num * -1; a.at(i).first.first = s; a.at(i).first.second = num; a.at(i).second = i; } sort(a.begin(), a.end()); for(int i=0;i<n;i++){ cout << a.at(i).second +1 << endl; } } */ // ABC_058_Cのように // s.at(j) == a のとき // cout << s.at(j)-'0' - 49 << endl; // とすると、「0」を出力してくれる。 →もっといいほかの方法はないの? // 全bit探索を入れよう!! /*ABC_167_C skill up などを参考に… //https://qiita.com/hareku/items/3d08511eab56a481c7db int main() { int n = 3; // {0, 1, ..., n-1} の部分集合の全探索 for (int bit = 0; bit < (1<<n); ++bit) { vector<int> S; for (int i = 0; i < n; ++i) { if (bit & (1<<i)) { // 列挙に i が含まれるか S.push_back(i); } } cout << bit << ": {"; for (int i = 0; i < (int)S.size(); ++i) { cout << S[i] << " "; } cout << "}" << endl; } } */ // next_permutation(順列列挙) /*https://note.com/memenekokaburi/n/nf0201d6002cd //https://scrapbox.io/ganariya/AtCoderGrandContest022_A%E5%95%8F%E9%A1%8C300%E7%82%B9%E3%80%8CDiverse_Word%E3%80%8D_(copy) //https://atcoder.jp/contests/agc022/tasks/agc022_a ABC_150_Cなど。 int main() { int n; cin >> n ; vector<int>array = {}; for(int i=0;i<n;i++){ array.push_back(i); } do{ for(int i=0; i<n; i++){ cout << array.at(i); if(i!=n-1)cout<<" "; } cout<<endl; }while(next_permutation(array.begin(),array.end())); return 0; } */ // ABC126_Cのように関数でdouble型で返ってきてほしい場合はdouble // kan_halfのようにかく /* //ABC_041_C// pair型 int main() { int n; cin >> n; vector<pair<int,int>>a(n); for(int i=0;i<n;i++){ int num; cin >> num; a.at(i).first = num; a.at(i).second = i; } sort(a.begin(), a.end()); reverse(a.begin(),a.end()); for(int i=0;i<n;i++){ cout << a.at(i).second + 1<< endl; } } */ /*ABC_068_C //boolの配列を使って bool s[200050] = {}; bool t[200050] = {}; int main() { ll n, m; cin >> n >> m; for (int i = 0; i < m; i++){ ll a, b; cin >> a >> b; if (a == 1) { t[b] = true; } if (b == n) { s[a] = true; } } for (int i = 0; i < 200050; i++){ if (s[i] && t[i]) { cout << "POSSIBLE" << endl; return 0; } } cout << "IMPOSSIBLE" << endl; return 0; } */ // int32 4 signed, signed int, int -2,147,483,648 ~ 2,147,483,647 = // 2*10^9 再帰関数 ABC_029_C /* void f(int rest , string s){ if(rest == 0){ cout << s << endl; } else{ for(char moji = 'a' ;moji <='c' ; moji++){ f(rest-1,s+moji); } } } int main() { int n; cin >> n; f(n, ""); } */ // 連想配列 ARC_081_Cの解答 //ABC073でも復習できます。 /* int main() { ll n; cin >> n; vector<ll>a(n); rep(i,n) cin>>a.at(i); map<ll,ll>mp; rep(i,n){ mp[a.at(i)]++; } ll one = 0; ll two = 0; for(auto p:mp){ // cout << p.first << " " << p.second << endl; if(p.second >= 2){ if(one <= p.first){ two = one; one = p.first; } } if(p.second >= 4){ if(one <= p.first){ two = p.first; one = p.first; } } } // cout << one << endl; // cout << two << endl; // cout << endl; cout << one * two << endl; } */ // 関数 /* ll gcd(ll a, ll b){ if (a%b == 0){ return(b); } else{ return(gcd(b, a%b)); } } ll lcm(ll a, ll b){ // return a * b / gcd(a, b); return a / gcd(a, b)* b; } int kan_hyaku(int n){ int kurai = 0; for(int i=0;i<3;i++){ kurai = n%10; n /=10; } return kurai; } int kan_ju(int n){ int kurai = 0; for(int i=0;i<2;i++){ kurai = n%10; n /=10; } return kurai; } int kan_ichi(int n){ int kurai = 0; for(int i=0;i<1;i++){ kurai = n%10; n /=10; } return kurai; } ll keta(ll n){ ll wa = 1; while(n>0){ wa *=10; n--; } return wa; } double kan_half(int n){ double wa = 1; while(n>0){ // cout << "TEST"<<endl; wa *= 0.5; // cout << wa << endl; n--; } return wa; } ll facctorialMethod(ll k){ ll sum = 1; for (ll i = 1; i <= k; ++i) { sum = sum%1000000007 * i%1000000007; } return sum; } int zorocheck(string s){ int count = 0; rep(i,s.size()){ if(s.at(i) == s.at(0)) count++; } if(count ==s.size()){ return 1; } else{ return 0; } } int sannobekijou(int n){ int wa = 1; while(n>0){ n--; wa *=3; } return wa; } ll ketasuu(ll k){ ll wa = 0; while(k > 0){ k /=10; wa++; } return wa; } ll beki(ll f,ll num){ ll wa = 1; while(num > 0){ wa *= f; num--; // cout << wa << endl; } return wa; } ll fibona(ll num){ vector<ll>c(3); c.at(0) = 1; c.at(1) = 2; c.at(2) = 3; if(num == 1){ return c.at(0); } else if(num == 2){ return c.at(1); } else if(num == 3){ return c.at(2); } else{ for(ll i = 3; i < num;i++){ // cout << " tes " << endl; ll tmp; tmp = c.at(1) + c.at(2); tmp %= 1000000007; c.at(0) = c.at(1); c.at(1) = c.at(2); c.at(2) = tmp; } return c.at(2); } } */ // 桁数を指定して出力する方法 // #include <iomanip>//これをincludeしておかないといけない // cout << fixed << setprecision(20)<< ans << endl; // s.at(0) = toupper(s.at(0));//小文字なら大文字へ//大文字の場合はそのまま // s.at(i) = tolower(s.at(i));//大文字なら小文字へ//小文字の場合はそのまま // getline(cin, s); //空白文字を含むものをまとめて入力できる。 // s配列に格納した単語を、辞書順にソートする // sort(s.begin(), s.end()); // string t = "keyence";//で文字列を格納できる // s.empty() //emptyなら1を出力 入っていれば0を出力 /*//ABC018-B 部分的にreverseをかける解法 int main() { string s; cin >> s; int n; cin >> n; vector<int>a(n); vector<int>b(n); rep(i,n) cin>>a.at(i)>>b.at(i); rep(i,n)a.at(i)--; rep(i,n)b.at(i)--; string t; rep(i,n){ t = s; for(int k=0;k<=b.at(i)-a.at(i);k++){ t.at(a.at(i)+k) = s.at(b.at(i)-k); } s = t; } cout << s << endl; } *///ABC018-B // cout << char(i+48) << // endl;//なぜかaは47と得る時がある。+48で出力もaにできる。 cout << char(97) << // endl;//アスキーコードでaを出力 // sort(b.begin(), b.end());//bという配列を小さい方からソート // reverse(b.begin(), b.end());//bという配列をリターン /*01 02 03 12 13 23 と6回見ていくパターン for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ } } */ // vector<vector<int>> a(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言 // 10のi乗pow(10, i);//ただしdouble型のため注意 /*string s; stringでの文字列を数字型に変える方法 cin >> s; rep(i,s.size()-2) { int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0'; */ /* int n; cin >> n; vector<int>a(n); rep(i,n) cin >> a.at(i); */ // cout << fixed << setprecision(10)<< ans << endl; // 数字から文字列に変換 a.at(0) = std::to_string(111); #include <bits/stdc++.h> #include <iomanip> //これをincludeしておかないといけない #include <iostream> #include <queue> #include <vector> using namespace std; using Graph = vector<vector<int>>; typedef long long ll; typedef long double lld; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define PI 3.14159265359 #define MOD 1000000007 int main() { int H, W, M; cin >> H >> W >> M; int h[M], w[M]; int ch[H]{}, cw[W]{}; int r_max = 0; int c_max = 0; for (int i = 0; i < M; i++) { cin >> h[i] >> w[i]; h[i]--; w[i]--; ch[h[i]]++; cw[w[i]]++; r_max = max(r_max, ch[h[i]]); c_max = max(c_max, cw[w[i]]); } ll cnt_r = 0; ll cnt_c = 0; for (int i = 0; i < H; i++) { if (r_max == ch[i]) cnt_r++; } for (int i = 0; i < W; i++) { if (c_max == cw[i]) cnt_c++; } ll v = cnt_r * cnt_c; for (int i = 0; i < M; i++) { if (ch[h[i]] == r_max && cw[w[i]] == c_max) { v--; } } if (v == 0) { cout << r_max + c_max - 1 << "\n"; } else { cout << r_max + c_max << "\n"; } return 0; }
replace
469
525
469
507
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define lli long long int #define double long double #define all(x) x.begin(), x.end() #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define siz(x) x.size() #define prs(x, y) x.find(y) != x.end() #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define forn(i, n) for (int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int INF = 1 << 29; typedef long long ll; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int &n, int b) { n |= two(b); } inline void unset_bit(int &n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; while (n && ++res) n -= n & (-n); return res; } inline int level(int n) { int ans = 0; while (n % 2 == 0) { n /= 2; ans++; } return ans; } map<int, int> col, row; vector<int> vec[300005]; int main() { fast_io // REMOVE FOR interactive problems int h, w, m; cin >> h >> w >> m; while (m--) { int x, y; cin >> x >> y; col[x]++; row[y]++; vec[x].push_back(y); } multiset<int> mult, st; for (auto x : row) mult.insert(x.second); int ansa = 0; for (auto x : col) { int cl = x.first; int siz = x.second; for (auto k : vec[cl]) { int kr = row[k]; mult.erase(mult.find(kr)); st.insert(kr); } int ans = max(siz + (*st.rbegin()) - 1, siz + (*mult.rbegin())); ansa = max(ansa, ans); while (!st.empty()) { mult.insert(*st.begin()); st.erase(st.begin()); } } cout << ansa; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define lli long long int #define double long double #define all(x) x.begin(), x.end() #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define siz(x) x.size() #define prs(x, y) x.find(y) != x.end() #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define forn(i, n) for (int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int INF = 1 << 29; typedef long long ll; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int &n, int b) { n |= two(b); } inline void unset_bit(int &n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; while (n && ++res) n -= n & (-n); return res; } inline int level(int n) { int ans = 0; while (n % 2 == 0) { n /= 2; ans++; } return ans; } map<int, int> col, row; vector<int> vec[300005]; int main() { fast_io // REMOVE FOR interactive problems int h, w, m; cin >> h >> w >> m; while (m--) { int x, y; cin >> x >> y; col[x]++; row[y]++; vec[x].push_back(y); } multiset<int> mult, st; for (auto x : row) mult.insert(x.second); int ansa = 0; for (auto x : col) { int cl = x.first; int siz = x.second; for (auto k : vec[cl]) { int kr = row[k]; mult.erase(mult.find(kr)); st.insert(kr); } if (!st.empty()) ansa = max(ansa, siz + (*st.rbegin()) - 1); if (!mult.empty()) ansa = max(ansa, siz + (*mult.rbegin())); while (!st.empty()) { mult.insert(*st.begin()); st.erase(st.begin()); } } cout << ansa; }
replace
69
71
69
73
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> Pii; typedef pair<int, ll> Pil; typedef pair<ll, ll> Pll; typedef pair<ll, int> Pli; #define fi first #define se second const ll MOD = 1e9 + 7; const ll MOD2 = 998244353; const ll MOD3 = 1812447359; const ll INF = 1ll << 62; const double PI = 2 * asin(1); void yes() { printf("yes\n"); } void no() { printf("no\n"); } void Yes() { printf("Yes\n"); } void No() { printf("No\n"); } void YES() { printf("YES\n"); } void NO() { printf("NO\n"); } int H, W, M; int cntH[int(3e5 + 5)], cntW[int(3e5 + 5)]; Pii PH[int(3e5 + 5)], PW[int(3e5 + 5)]; map<Pii, bool> mp; int main() { cin >> H >> W >> M; for (int i = 0; i < M; i++) { int h, w; cin >> h >> w; cntH[h]++; cntW[w]++; mp[{h, w}] = true; } for (int i = 0; i <= H; i++) PH[i] = {cntH[i], i}; sort(PH, PH + H + 1, greater<Pii>()); for (int i = 0; i <= W; i++) PW[i] = {cntW[i], i}; sort(PW, PW + W + 1, greater<Pii>()); int h = 0, w = 0; while (PH[0].fi == PH[h].fi) h++; while (PW[0].fi == PW[w].fi) w++; int ans = PH[0].fi + PW[0].fi - 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (!mp[{PH[i].se, PW[j].se}]) { ans = PH[0].fi + PW[0].fi; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> Pii; typedef pair<int, ll> Pil; typedef pair<ll, ll> Pll; typedef pair<ll, int> Pli; #define fi first #define se second const ll MOD = 1e9 + 7; const ll MOD2 = 998244353; const ll MOD3 = 1812447359; const ll INF = 1ll << 62; const double PI = 2 * asin(1); void yes() { printf("yes\n"); } void no() { printf("no\n"); } void Yes() { printf("Yes\n"); } void No() { printf("No\n"); } void YES() { printf("YES\n"); } void NO() { printf("NO\n"); } int H, W, M; int cntH[int(3e5 + 5)], cntW[int(3e5 + 5)]; Pii PH[int(3e5 + 5)], PW[int(3e5 + 5)]; map<Pii, bool> mp; int main() { cin >> H >> W >> M; for (int i = 0; i < M; i++) { int h, w; cin >> h >> w; cntH[h]++; cntW[w]++; mp[{h, w}] = true; } for (int i = 0; i <= H; i++) PH[i] = {cntH[i], i}; sort(PH, PH + H + 1, greater<Pii>()); for (int i = 0; i <= W; i++) PW[i] = {cntW[i], i}; sort(PW, PW + W + 1, greater<Pii>()); int h = 0, w = 0; while (PH[0].fi == PH[h].fi) h++; while (PW[0].fi == PW[w].fi) w++; int ans = PH[0].fi + PW[0].fi - 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (!mp[{PH[i].se, PW[j].se}]) { cout << ans + 1 << endl; return 0; } } } cout << ans << endl; return 0; }
replace
59
60
59
61
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin >> #define ll long long #define ln cout << '\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n", a) #define mem(a) memset(a, 0, sizeof(a)) #define all(c) (c).begin(), (c).end() #define iter(c) __typeof((c).begin()) #define rrep(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++) #define rep(i, n) REP(i, 0, n) #define tr(it, c) for (iter(c) it = (c).begin(); it != (c).end(); it++) ll check(ll n, ll m, ll x, ll y) { return x >= 0 && x < n && y >= 0 && y < m; } void pr() { ln; } template <class A, class... B> void pr(const A &a, const B &...b) { cout << a << (sizeof...(b) ? " " : ""); pr(b...); } template <class A> void PR(A a, ll n) { rep(i, n) cout << (i ? " " : "") << a[i]; ln; } const ll MAX = 1e9 + 7, MAXL = 1LL << 61, dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1}, dy[8] = {0, 1, 0, -1, -1, 1, 1, -1}; typedef pair<ll, ll> P; class RMQ2 { public: int n, dat[555555]; void init(int _n) { n = 1; while (n < _n) n *= 2; fill(dat, dat + 2 * n - 1, -MAX); } void update(int k, int a) { k += n - 1; dat[k] = a; while (k > 0) { k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); } } int query(int a, int b) { return query(a, b, 0, 0, n); } int query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return -MAX; if (a <= l && r <= b) return dat[k]; int vl = query(a, b, k * 2 + 1, l, (l + r) / 2); int vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } }; RMQ2 t; void Main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a[n], b[m]; rep(i, k) { int x, y; cin >> x >> y; x--, y--; a[x].pb(y); b[y].pb(x); } t.init(m); rep(i, m) t.update(i, b[i].size()); int ans = 0; rep(i, n) { rep(j, a[i].size()) { ll d = t.query(a[i][j], a[i][j] + 1); t.update(a[i][j], d - 1); } ans = max(ans, (int)a[i].size() + t.query(0, m)); rep(j, a[i].size()) { ll d = t.query(a[i][j], a[i][j] + 1); t.update(a[i][j], d + 1); } } pr(ans); } int main() { ios::sync_with_stdio(0); cin.tie(0); Main(); return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin >> #define ll long long #define ln cout << '\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n", a) #define mem(a) memset(a, 0, sizeof(a)) #define all(c) (c).begin(), (c).end() #define iter(c) __typeof((c).begin()) #define rrep(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++) #define rep(i, n) REP(i, 0, n) #define tr(it, c) for (iter(c) it = (c).begin(); it != (c).end(); it++) ll check(ll n, ll m, ll x, ll y) { return x >= 0 && x < n && y >= 0 && y < m; } void pr() { ln; } template <class A, class... B> void pr(const A &a, const B &...b) { cout << a << (sizeof...(b) ? " " : ""); pr(b...); } template <class A> void PR(A a, ll n) { rep(i, n) cout << (i ? " " : "") << a[i]; ln; } const ll MAX = 1e9 + 7, MAXL = 1LL << 61, dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1}, dy[8] = {0, 1, 0, -1, -1, 1, 1, -1}; typedef pair<ll, ll> P; class RMQ2 { public: int n, dat[1555555]; void init(int _n) { n = 1; while (n < _n) n *= 2; fill(dat, dat + 2 * n - 1, -MAX); } void update(int k, int a) { k += n - 1; dat[k] = a; while (k > 0) { k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); } } int query(int a, int b) { return query(a, b, 0, 0, n); } int query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return -MAX; if (a <= l && r <= b) return dat[k]; int vl = query(a, b, k * 2 + 1, l, (l + r) / 2); int vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } }; RMQ2 t; void Main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a[n], b[m]; rep(i, k) { int x, y; cin >> x >> y; x--, y--; a[x].pb(y); b[y].pb(x); } t.init(m); rep(i, m) t.update(i, b[i].size()); int ans = 0; rep(i, n) { rep(j, a[i].size()) { ll d = t.query(a[i][j], a[i][j] + 1); t.update(a[i][j], d - 1); } ans = max(ans, (int)a[i].size() + t.query(0, m)); rep(j, a[i].size()) { ll d = t.query(a[i][j], a[i][j] + 1); t.update(a[i][j], d + 1); } } pr(ans); } int main() { ios::sync_with_stdio(0); cin.tie(0); Main(); return 0; }
replace
33
34
33
34
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main(int argc, const char *argv[]) { // int h, w, m; cin >> h >> w >> m; vector<pair<int, int>> tgts(m); vector<int> cnt_row(h, 0), cnt_col(w, 0); for (int i = 0; i < m; ++i) { cin >> tgts[i].first >> tgts[i].second; cnt_row[tgts[i].first]++; cnt_col[tgts[i].second]++; } sort(tgts.begin(), tgts.end()); int max_col = *max_element(cnt_col.begin(), cnt_col.end()); int max_row = *max_element(cnt_row.begin(), cnt_row.end()); int cnt1 = 0, cnt2 = 0; vector<int> vr, vc; for (int i = 0; i < cnt_row.size(); i++) { if (cnt_row[i] == max_row) { vr.push_back(i); } } for (int i = 0; i < cnt_col.size(); i++) { if (cnt_col[i] == max_col) { vc.push_back(i); } } for (auto r : vr) { for (auto c : vc) { auto p = make_pair(r, c); if (!binary_search(tgts.begin(), tgts.end(), p)) { cout << max_col + max_row << '\n'; return 0; } } } cout << max_col + max_row - 1 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, const char *argv[]) { // int h, w, m; cin >> h >> w >> m; vector<pair<int, int>> tgts(m); vector<int> cnt_row(h, 0), cnt_col(w, 0); for (int i = 0; i < m; ++i) { cin >> tgts[i].first >> tgts[i].second; tgts[i].first--; tgts[i].second--; cnt_row[tgts[i].first]++; cnt_col[tgts[i].second]++; } sort(tgts.begin(), tgts.end()); int max_col = *max_element(cnt_col.begin(), cnt_col.end()); int max_row = *max_element(cnt_row.begin(), cnt_row.end()); int cnt1 = 0, cnt2 = 0; vector<int> vr, vc; for (int i = 0; i < cnt_row.size(); i++) { if (cnt_row[i] == max_row) { vr.push_back(i); } } for (int i = 0; i < cnt_col.size(); i++) { if (cnt_col[i] == max_col) { vc.push_back(i); } } for (auto r : vr) { for (auto c : vc) { auto p = make_pair(r, c); if (!binary_search(tgts.begin(), tgts.end(), p)) { cout << max_col + max_row << '\n'; return 0; } } } cout << max_col + max_row - 1 << '\n'; return 0; }
insert
13
13
13
15
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++) #define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define bra(first, second) '(' << first << ',' << second << ')' constexpr ll MOD = 1000000007; // constexpr ll MOD = 998244353; ll INF = 1001001001001001001; long double EPS = 1e-9; long double PI = 3.141592653589793238; template <typename T> void remove(std::vector<T> &vector, unsigned int index) { vector.erase(vector.begin() + index); } using Graph = vector<vector<pair<ll, ll>>>; // MOD確認 ll H, W, M; pair<ll, ll> Y[300010]; pair<ll, ll> X[300010]; int main() { cin >> H >> W >> M; map<pair<ll, ll>, ll> mp; rep(i, 300010) { Y[i].second = i; X[i].second = i; } rep(i, M) { ll h, w; cin >> h >> w; h--; w--; mp[make_pair(h, w)]++; Y[h].first++; X[w].first++; } ll ans = 0; sort(X, X + 300010); sort(Y, Y + 300010); reverse(X, X + 300010); reverse(Y, Y + 300010); rep(i, 100) rep(j, M) { ll num = Y[i].first + X[j].first; if (mp[make_pair(Y[i].second, X[j].second)] >= 1) { num--; } ans = max(ans, num); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++) #define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define bra(first, second) '(' << first << ',' << second << ')' constexpr ll MOD = 1000000007; // constexpr ll MOD = 998244353; ll INF = 1001001001001001001; long double EPS = 1e-9; long double PI = 3.141592653589793238; template <typename T> void remove(std::vector<T> &vector, unsigned int index) { vector.erase(vector.begin() + index); } using Graph = vector<vector<pair<ll, ll>>>; // MOD確認 ll H, W, M; pair<ll, ll> Y[300010]; pair<ll, ll> X[300010]; int main() { cin >> H >> W >> M; map<pair<ll, ll>, ll> mp; rep(i, 300010) { Y[i].second = i; X[i].second = i; } rep(i, M) { ll h, w; cin >> h >> w; h--; w--; mp[make_pair(h, w)]++; Y[h].first++; X[w].first++; } ll ans = 0; sort(X, X + 300010); sort(Y, Y + 300010); reverse(X, X + 300010); reverse(Y, Y + 300010); rep(i, 10) rep(j, M) { ll num = Y[i].first + X[j].first; if (mp[make_pair(Y[i].second, X[j].second)] >= 1) { num--; } ans = max(ans, num); } rep(i, M) rep(j, 10) { ll num = Y[i].first + X[j].first; if (mp[make_pair(Y[i].second, X[j].second)] >= 1) { num--; } ans = max(ans, num); } cout << ans << endl; }
replace
48
49
48
56
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++) #define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--) // 定数 #define INF 1000000000 // 10^9:極めて大きい値,∞ // 略記 #define PB push_back // vectorヘの挿入 #define MP make_pair // pairのコンストラクタ #define F first // pairの一つ目の要素 #define S second // pairの二つ目の要素 int h, w, m; int main() { cin >> h >> w >> m; vector<int> yv(h), xv(w); int x, y; set<pair<int, int>> s; rep(i, m) { cin >> y >> x; y--; x--; s.insert(make_pair(y, x)); yv[y]++; xv[x]++; } int ymax = 0; rep(i, h) { ymax = max(ymax, yv[i]); } ll ans = ymax; int xmax = 0; rep(i, w) { xmax = max(xmax, xv[i]); } ans += xmax; rep(i, h) { if (yv[i] == ymax) { rep(j, w) { if (xv[j] == xmax) { if (s.count(make_pair(i, j)) == 0) { cout << ans << endl; return 0; } } } } } cout << ans - 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++) #define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--) // 定数 #define INF 1000000000 // 10^9:極めて大きい値,∞ // 略記 #define PB push_back // vectorヘの挿入 #define MP make_pair // pairのコンストラクタ #define F first // pairの一つ目の要素 #define S second // pairの二つ目の要素 int h, w, m; int main() { cin >> h >> w >> m; vector<int> yv(h), xv(w); int x, y; set<pair<int, int>> s; rep(i, m) { cin >> y >> x; y--; x--; s.insert(make_pair(y, x)); yv[y]++; xv[x]++; } int ymax = *max_element(yv.begin(), yv.end()); int xmax = *max_element(xv.begin(), xv.end()); ll ans = xmax + ymax; vector<int> yvv, xvv; rep(i, h) if (yv[i] == ymax) yvv.push_back(i); rep(i, w) if (xv[i] == xmax) xvv.push_back(i); for (int y : yvv) { for (int x : xvv) { if (s.count(make_pair(y, x)) == 0) { cout << ans << endl; return 0; } } } cout << ans - 1 << endl; return 0; }
replace
34
49
34
47
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define FASTIO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); using namespace std; using ll = long long; int main() { FASTIO int h, w; cin >> h >> w; int m; cin >> m; vector<int> horizontal(w + 1), vertical(h + 1); unordered_map<int, unordered_map<int, bool>> mp; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; mp[a][b] = 1; horizontal[b]++; vertical[a]++; } int mx = 0; vector<int> u, v; mx = *max_element(vertical.begin(), vertical.end()); for (int i = 0; i <= h; i++) { if (mx == vertical[i]) { u.push_back(i); } } mx = *max_element(horizontal.begin(), horizontal.end()); for (int i = 0; i <= w; i++) { if (mx == horizontal[i]) { v.push_back(i); } } for (int i = 0; i < u.size(); i++) { for (int j = 0; j < v.size(); j++) { mx = max(mx, horizontal[v[j]] + vertical[u[i]] - mp[u[i]][v[j]]); } } cout << mx << endl; }
#include <bits/stdc++.h> #define FASTIO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); using namespace std; using ll = long long; int main() { FASTIO int h, w; cin >> h >> w; int m; cin >> m; vector<int> horizontal(w + 1), vertical(h + 1); unordered_map<int, unordered_map<int, bool>> mp; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; mp[a][b] = 1; horizontal[b]++; vertical[a]++; } int mx = 0; vector<int> u, v; mx = *max_element(vertical.begin(), vertical.end()); for (int i = 0; i <= h; i++) { if (mx == vertical[i]) { u.push_back(i); } } mx = *max_element(horizontal.begin(), horizontal.end()); for (int i = 0; i <= w; i++) { if (mx == horizontal[i]) { v.push_back(i); } } for (int i = 0; i < u.size(); i++) { for (int j = 0; j < v.size(); j++) { mx = max(mx, horizontal[v[j]] + vertical[u[i]] - mp[u[i]][v[j]]); if (!mp[u[i]][v[j]]) return cout << mx << endl, 0; } } cout << mx << endl; }
insert
41
41
41
43
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define N 200200 pair<int, int> v[N]; pair<int, int> l[N], c[N]; int i, x, y, ml, mc, h, w, n, ii, jj, j; long long cntc, cntl, ans; map<pair<int, int>, bool> sel; int main() { cin >> h >> w >> n; for (i = 0; i < n; ++i) { cin >> v[i].first >> v[i].second; sel[v[i]] = 1; } for (i = 0; i < h; ++i) l[i + 1].second = i + 1; for (i = 0; i < w; ++i) c[i + 1].second = i + 1; for (i = 0; i < n; ++i) { ++l[v[i].first].first; ++c[v[i].second].first; } sort(l + 1, l + h + 1); sort(c + 1, c + w + 1); i = h; j = w; ans = l[i].first + c[j].first; cntl = 0; cntc = 0; while (i > 0 && l[i].first == l[h].first) { --i; ++cntl; } while (j > 0 && c[j].first == c[w].first) { --j; ++cntc; } if (cntc * cntl > n) { cout << ans; return 0; } else { for (ii = 0; ii < cntl; ++ii) for (jj = 0; jj < cntc; ++jj) { if (!sel[make_pair(l[h - ii].second, c[w - jj].second)]) { cout << ans; return 0; } } } cout << ans - 1; return 0; }
#include <bits/stdc++.h> using namespace std; #define N 300300 pair<int, int> v[N]; pair<int, int> l[N], c[N]; int i, x, y, ml, mc, h, w, n, ii, jj, j; long long cntc, cntl, ans; map<pair<int, int>, bool> sel; int main() { cin >> h >> w >> n; for (i = 0; i < n; ++i) { cin >> v[i].first >> v[i].second; sel[v[i]] = 1; } for (i = 0; i < h; ++i) l[i + 1].second = i + 1; for (i = 0; i < w; ++i) c[i + 1].second = i + 1; for (i = 0; i < n; ++i) { ++l[v[i].first].first; ++c[v[i].second].first; } sort(l + 1, l + h + 1); sort(c + 1, c + w + 1); i = h; j = w; ans = l[i].first + c[j].first; cntl = 0; cntc = 0; while (i > 0 && l[i].first == l[h].first) { --i; ++cntl; } while (j > 0 && c[j].first == c[w].first) { --j; ++cntc; } if (cntc * cntl > n) { cout << ans; return 0; } else { for (ii = 0; ii < cntl; ++ii) for (jj = 0; jj < cntc; ++jj) { if (!sel[make_pair(l[h - ii].second, c[w - jj].second)]) { cout << ans; return 0; } } } cout << ans - 1; return 0; }
replace
3
4
3
4
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define int long long #define ar array #define db double #define pow pw const db pi = 3.14159265358979323846; int pw(int a, int b) { int ans = 1; while (b) { if (b % 2) ans *= a; a *= a; b /= 2; } return (ans); } const int mxn = 3e5 + 7, INF = 1e9 + 7; int m, n, k; int r[mxn], c[mxn]; map<pair<int, int>, int> a; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> m >> n >> k; for (int i = 0; i < k; i++) { int u, v; cin >> u >> v; r[u]++; c[v]++; a[{u, v}] = 1; } int t1 = 0, t2 = 0, ans = 0; vector<int> d, d2; for (int i = 1; i <= m; i++) t1 = max(t1, r[i]); for (int i = 1; i <= m; i++) if (r[i] == t1) d.push_back(i); for (int i = 1; i <= n; i++) t2 = max(t2, c[i]); for (int i = 1; i <= n; i++) if (c[i] == t2) d2.push_back(i); for (int g : d) for (int h : d2) { ans = max(ans, r[g] + c[h] - a[{g, h}]); } cout << ans; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define int long long #define ar array #define db double #define pow pw const db pi = 3.14159265358979323846; int pw(int a, int b) { int ans = 1; while (b) { if (b % 2) ans *= a; a *= a; b /= 2; } return (ans); } const int mxn = 3e5 + 7, INF = 1e9 + 7; int m, n, k; int r[mxn], c[mxn]; map<pair<int, int>, int> a; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> m >> n >> k; for (int i = 0; i < k; i++) { int u, v; cin >> u >> v; r[u]++; c[v]++; a[{u, v}] = 1; } int t1 = 0, t2 = 0, ans = 0; vector<int> d, d2; for (int i = 1; i <= m; i++) t1 = max(t1, r[i]); for (int i = 1; i <= m; i++) if (r[i] == t1) d.push_back(i); for (int i = 1; i <= n; i++) t2 = max(t2, c[i]); for (int i = 1; i <= n; i++) if (c[i] == t2) d2.push_back(i); for (int g : d) for (int h : d2) { if (a[{g, h}] == 0) { ans = max(ans, r[g] + c[h] - a[{g, h}]); cout << ans; return 0; } else ans = max(ans, r[g] + c[h] - a[{g, h}]); } cout << ans; return 0; }
replace
53
54
53
59
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ff first #define ss second #define int long long #define all(x) (x).begin(), (x).end() #define what_is(x) cerr << #x << " is " << x << endl; #define eb emplace_back #define pii pair<int, int> using namespace std; const int mxn = 300005; vector<int> fx(mxn, 0), fy(mxn, 0); void solve() { int h, w, m; cin >> h >> w >> m; set<pii> s; int x, y; while (m--) { cin >> x >> y; fx[x]++, fy[y]++; s.insert({x, y}); } int mx = *max_element(fx.begin(), fx.end()), my = *max_element(fy.begin(), fy.end()); vector<int> xx, yy; for (int i = 1; i <= h; i++) { if (fx[i] == mx) { xx.eb(i); } } for (int i = 1; i <= w; i++) { if (fy[i] == my) { yy.eb(i); } } int res = 0; for (auto &i : xx) { for (auto &j : yy) { res = max(res, mx + my - (s.count({i, j}) == 1)); } } cout << res; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // int t; // cin >> t; // while (t--) solve(); return 0; }
#include <bits/stdc++.h> #define ff first #define ss second #define int long long #define all(x) (x).begin(), (x).end() #define what_is(x) cerr << #x << " is " << x << endl; #define eb emplace_back #define pii pair<int, int> using namespace std; const int mxn = 300005; vector<int> fx(mxn, 0), fy(mxn, 0); void solve() { int h, w, m; cin >> h >> w >> m; set<pii> s; int x, y; while (m--) { cin >> x >> y; fx[x]++, fy[y]++; s.insert({x, y}); } int mx = *max_element(fx.begin(), fx.end()), my = *max_element(fy.begin(), fy.end()); vector<int> xx, yy; for (int i = 1; i <= h; i++) { if (fx[i] == mx) { xx.eb(i); } } for (int i = 1; i <= w; i++) { if (fy[i] == my) { yy.eb(i); } } int res = 0; for (auto &i : xx) { for (auto &j : yy) { if (res == 0) res = max(res, mx + my - (s.count({i, j}) == 1)); if (s.count({i, j}) == 0) { res = max(res, mx + my); break; } } } cout << res; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // int t; // cin >> t; // while (t--) solve(); return 0; }
replace
39
40
39
45
TLE
p02580
C++
Runtime Error
#include <cstring> #include <iostream> #include <string> #include <unordered_map> #include <vector> using namespace std; int main() { const int MAX = 30000; int H, W, M; cin >> H >> W >> M; int h[MAX], w[MAX] = {0}; for (int i = 0; i < M; i++) { cin >> h[i] >> w[i]; h[i]--; w[i]--; } // Create unordered map to reference the existence of a bomb later // The key cannot be pair as long as I don't implement a has function for pair unordered_map<string, int> map; int rows[MAX], cols[MAX] = {0}; int row_best_count = 0; int col_best_count = 0; for (int i = 0; i < M; i++) { string key = to_string(h[i]) + ',' + to_string(w[i]); map[key] = 1; rows[h[i]]++; cols[w[i]]++; row_best_count = max(row_best_count, rows[h[i]]); col_best_count = max(col_best_count, cols[w[i]]); } vector<int> best_rows; vector<int> best_cols; for (int i = 0; i < H; i++) { if (rows[i] == row_best_count) { best_rows.push_back(i); } } for (int i = 0; i < W; i++) { if (cols[i] == col_best_count) { best_cols.push_back(i); } } int ans = row_best_count + col_best_count - 1; for (int r : best_rows) { bool break_signal = false; for (int c : best_cols) { string key = to_string(r) + ',' + to_string(c); if (!map[key]) { ans = row_best_count + col_best_count; break_signal = true; break; } } if (break_signal) break; } cout << ans << endl; }
#include <cstring> #include <iostream> #include <string> #include <unordered_map> #include <vector> using namespace std; int main() { const int MAX = 300000; int H, W, M; cin >> H >> W >> M; int h[MAX], w[MAX] = {0}; for (int i = 0; i < M; i++) { cin >> h[i] >> w[i]; h[i]--; w[i]--; } // Create unordered map to reference the existence of a bomb later // The key cannot be pair as long as I don't implement a has function for pair unordered_map<string, int> map; int rows[MAX], cols[MAX] = {0}; int row_best_count = 0; int col_best_count = 0; for (int i = 0; i < M; i++) { string key = to_string(h[i]) + ',' + to_string(w[i]); map[key] = 1; rows[h[i]]++; cols[w[i]]++; row_best_count = max(row_best_count, rows[h[i]]); col_best_count = max(col_best_count, cols[w[i]]); } vector<int> best_rows; vector<int> best_cols; for (int i = 0; i < H; i++) { if (rows[i] == row_best_count) { best_rows.push_back(i); } } for (int i = 0; i < W; i++) { if (cols[i] == col_best_count) { best_cols.push_back(i); } } int ans = row_best_count + col_best_count - 1; for (int r : best_rows) { bool break_signal = false; for (int c : best_cols) { string key = to_string(r) + ',' + to_string(c); if (!map[key]) { ans = row_best_count + col_best_count; break_signal = true; break; } } if (break_signal) break; } cout << ans << endl; }
replace
9
10
9
10
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main() { int H, W, M; cin >> H >> W >> M; vector<int> g(H), r(W); map<pair<int, int>, int> mp; int gm = 0, rm = 0; for (int i = 0; i < M; i++) { int h, w; cin >> h >> w; g[h - 1]++; r[w - 1]++; mp[make_pair(h - 1, w - 1)]++; gm = max(gm, g[h - 1]); rm = max(rm, r[w - 1]); } vector<int> cg(0), cr(0); for (int i = 0; i < H; i++) { if (g[i] == gm) cg.push_back(i); } for (int i = 0; i < W; i++) { if (r[i] == rm) cr.push_back(i); } int ans = 0; for (int G : cg) { for (int R : cr) { ans = max(ans, gm + rm - mp[make_pair(G, R)]); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main() { int H, W, M; cin >> H >> W >> M; vector<int> g(H), r(W); map<pair<int, int>, int> mp; int gm = 0, rm = 0; for (int i = 0; i < M; i++) { int h, w; cin >> h >> w; g[h - 1]++; r[w - 1]++; mp[make_pair(h - 1, w - 1)]++; gm = max(gm, g[h - 1]); rm = max(rm, r[w - 1]); } vector<int> cg(0), cr(0); for (int i = 0; i < H; i++) { if (g[i] == gm) cg.push_back(i); } for (int i = 0; i < W; i++) { if (r[i] == rm) cr.push_back(i); } int ans = 0; for (int G : cg) { for (int R : cr) { ans = max(ans, gm + rm - mp[make_pair(G, R)]); if (!mp[make_pair(G, R)]) break; } } cout << ans << endl; }
insert
38
38
38
40
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() using ll = long long; string char_to_string(char val) { return string(1, val); } int char_to_int(char val) { return val - '0'; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } bool vector_finder(std::vector<ll> vec, int number) { auto itr = std::find(vec.begin(), vec.end(), number); size_t index = std::distance(vec.begin(), itr); if (index != vec.size()) return true; // 発見できた時 else return false; // 発見できなかった時 } struct edge { ll to, cost; }; int main() { int H, W; cin >> H >> W; int M; cin >> M; vector<int> h(M), w(M); REP(i, M) { cin >> h[i] >> w[i]; h[i]--; w[i]--; } vector<ll> x(H, 0), y(W, 0); REP(i, M) { x[h[i]]++; y[w[i]]++; } ll ans = 0; ll max_x = *max_element(all(x)); ll max_y = *max_element(all(y)); vector<ll> p, q; REP(i, H) if (x[i] == max_x) p.push_back(i); REP(i, W) if (y[i] == max_y) q.push_back(i); ans = max_x + max_y; bool flag = false; ll cnt = 0; REP(i, M) { if (vector_finder(p, h[i]) && vector_finder(q, w[i])) { cnt++; } } if (p.size() * q.size() == cnt) cout << ans - 1 << endl; else cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() using ll = long long; string char_to_string(char val) { return string(1, val); } int char_to_int(char val) { return val - '0'; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } bool vector_finder(std::vector<ll> vec, int number) { auto itr = std::find(vec.begin(), vec.end(), number); size_t index = std::distance(vec.begin(), itr); if (index != vec.size()) return true; // 発見できた時 else return false; // 発見できなかった時 } struct edge { ll to, cost; }; int main() { int H, W; cin >> H >> W; int M; cin >> M; vector<int> h(M), w(M); REP(i, M) { cin >> h[i] >> w[i]; h[i]--; w[i]--; } vector<ll> x(H, 0), y(W, 0); REP(i, M) { x[h[i]]++; y[w[i]]++; } ll ans = 0; ll max_x = *max_element(all(x)); ll max_y = *max_element(all(y)); vector<ll> p, q; REP(i, H) if (x[i] == max_x) p.push_back(i); REP(i, W) if (y[i] == max_y) q.push_back(i); ans = max_x + max_y; bool flag = false; ll cnt = 0; REP(i, M) { if (binary_search(all(p), h[i]) && binary_search(all(q), w[i])) { cnt++; } } if (p.size() * q.size() == cnt) cout << ans - 1 << endl; else cout << ans << endl; }
replace
60
61
60
61
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int h, w, m; typedef pair<int, int> P; // 行与列 unordered_map<int, int> m1; unordered_map<int, int> m2; map<P, int> c; int main() { vector<int> col, row; int ans = 0; int max1 = -1, max2 = -1; int index1, index2; cin >> h >> w >> m; int x, y = 0; for (int i = 0; i < m; i++) { scanf("%d%d", &x, &y); if (!m1.count(x)) { m1[x] = 1; } else { m1[x] += 1; } if (!m2.count(y)) { m2[y] = 1; } else { m2[y] += 1; } max1 = max(max1, m1[x]); max2 = max(max2, m2[y]); c[make_pair(x, y)] = 1; } unordered_map<int, int>::iterator iter; for (iter = m1.begin(); iter != m1.end(); iter++) { if (iter->second == max1) row.push_back(iter->first); } for (iter = m2.begin(); iter != m2.end(); iter++) { if (iter->second == max2) col.push_back(iter->first); } // for(int i = 0;i<row.size();i++){ // cout << row[i] << " "; // } // cout << endl; for (int i = 0; i < row.size(); i++) { for (int j = 0; j < col.size(); j++) { int num; if (c[make_pair(row[i], col[j])] == 1) num = max1 + max2 - 1; else num = max1 + max2; ans = max(ans, num); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int h, w, m; typedef pair<int, int> P; // 行与列 unordered_map<int, int> m1; unordered_map<int, int> m2; map<P, int> c; int main() { vector<int> col, row; int ans = 0; int max1 = -1, max2 = -1; int index1, index2; cin >> h >> w >> m; int x, y = 0; for (int i = 0; i < m; i++) { scanf("%d%d", &x, &y); if (!m1.count(x)) { m1[x] = 1; } else { m1[x] += 1; } if (!m2.count(y)) { m2[y] = 1; } else { m2[y] += 1; } max1 = max(max1, m1[x]); max2 = max(max2, m2[y]); c[make_pair(x, y)] = 1; } unordered_map<int, int>::iterator iter; for (iter = m1.begin(); iter != m1.end(); iter++) { if (iter->second == max1) row.push_back(iter->first); } for (iter = m2.begin(); iter != m2.end(); iter++) { if (iter->second == max2) col.push_back(iter->first); } // for(int i = 0;i<row.size();i++){ // cout << row[i] << " "; // } // cout << endl; for (int i = 0; i < row.size(); i++) { for (int j = 0; j < col.size(); j++) { int num; if (c[make_pair(row[i], col[j])] == 1) num = max1 + max2 - 1; else num = max1 + max2; ans = max(ans, num); if (ans == max1 + max2) break; } } cout << ans << endl; return 0; }
insert
54
54
54
56
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long int using namespace __gnu_pbds; typedef tree<pair<ll, pair<ll, ll>>, null_type, less<pair<ll, pair<ll, ll>>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define me BOSS #define bug() cout << "AIkahne aise" << endl #define PI acos(-1) /* Precode Start Here *\ Sieve void sieve() { for(ll i=3; i<=2000; i+=2) { for(ll j=i*i; j<=4000000; j+=i) A[j]=1; } v.push_back(2); for(ll i=3; i<=4000000; i+=2) if(A[i]==0) v.push_back(i); } Power Function Modulo P ll modPow(ll a, ll x, ll p) { //calculates a^x mod p in logarithmic time. long res = 1; while(x > 0) { if( x % 2 != 0) { res = (res * a) % p; } a = (a * a) % p; x /= 2; } return res; } factorial ll fact(ll n) { ll ans=1; for(ll i=1;i<=n;i++) { ans=(ans*i)%mod; } return ans; } Calculating nCr using Fermats law Theorem ll modInverse(ll a, ll p) { //calculates the modular multiplicative of a mod m. //(assuming p is prime). return modPow(a, p-2, p); } ll modBinomial(ll n, ll k, ll p) { // calculates C(n,k) mod p (assuming p is prime). ll numerator = 1; // n * (n-1) * ... * (n-k+1) for (ll i=0; i<k; i++) { numerator = (numerator * (n-i) ) % p; } ll denominator = 1; // k! for (ll i=1; i<=k; i++) { denominator = (denominator * i) % p; } // numerator / denominator mod p. return ( numerator* modInverse(denominator,p) ) % p; } num of divisor and euler totient ll phi[1000001],mark[1000001],divi[1000001];; void divisorPhi(ll n) { for(int i=1;i<=n;i++) phi[i]=i; for(int i=2;i<=n;i++) { if(!mark[i]) { for(int j=i;j<=n;j+=i) { mark[j]=1; phi[j]*=(1-1/(double)i); } } } for(ll i=1;i<=n;i++) { for(ll j=i;j<=n;j+=i) divi[j]++; } } /* Precode Ends */ #define mod 1000000007 ll A[5000001], B[5000001]; vector<ll> hia; vector<ll> nah; ll rowMap[300001], colMap[300001]; map<pair<ll, ll>, ll> myMap; set<ll> mySet; vector<pair<ll, ll>> vp; priority_queue<ll> pq; priority_queue<ll, vector<ll>, std::greater<ll>> first; ll po(ll a, ll n) { ll ans = 1; for (int i = 1; i <= n; i++) ans *= a; return ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll r, c, m, a, b, row = 0, col = 0; cin >> r >> c >> m; for (int i = 1; i <= m; i++) { cin >> a >> b; rowMap[a]++; colMap[b]++; myMap[make_pair(a, b)] = 1; } for (int i = 1; i <= r; i++) { row = max(row, rowMap[i]); } for (int i = 1; i <= r; i++) { if (row == rowMap[i]) { hia.push_back(i); } } for (int i = 1; i <= c; i++) { col = max(col, colMap[i]); } for (int i = 1; i <= c; i++) { if (col == colMap[i]) { nah.push_back(i); } } ll f = 0; for (int i = 0; i < hia.size(); i++) { for (int j = 0; j < nah.size(); j++) { if (myMap[make_pair(hia[i], nah[j])] == 0) { f = 1; } } } if (f == 1) { cout << row + col << endl; } else cout << row + col - 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long int using namespace __gnu_pbds; typedef tree<pair<ll, pair<ll, ll>>, null_type, less<pair<ll, pair<ll, ll>>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define me BOSS #define bug() cout << "AIkahne aise" << endl #define PI acos(-1) /* Precode Start Here *\ Sieve void sieve() { for(ll i=3; i<=2000; i+=2) { for(ll j=i*i; j<=4000000; j+=i) A[j]=1; } v.push_back(2); for(ll i=3; i<=4000000; i+=2) if(A[i]==0) v.push_back(i); } Power Function Modulo P ll modPow(ll a, ll x, ll p) { //calculates a^x mod p in logarithmic time. long res = 1; while(x > 0) { if( x % 2 != 0) { res = (res * a) % p; } a = (a * a) % p; x /= 2; } return res; } factorial ll fact(ll n) { ll ans=1; for(ll i=1;i<=n;i++) { ans=(ans*i)%mod; } return ans; } Calculating nCr using Fermats law Theorem ll modInverse(ll a, ll p) { //calculates the modular multiplicative of a mod m. //(assuming p is prime). return modPow(a, p-2, p); } ll modBinomial(ll n, ll k, ll p) { // calculates C(n,k) mod p (assuming p is prime). ll numerator = 1; // n * (n-1) * ... * (n-k+1) for (ll i=0; i<k; i++) { numerator = (numerator * (n-i) ) % p; } ll denominator = 1; // k! for (ll i=1; i<=k; i++) { denominator = (denominator * i) % p; } // numerator / denominator mod p. return ( numerator* modInverse(denominator,p) ) % p; } num of divisor and euler totient ll phi[1000001],mark[1000001],divi[1000001];; void divisorPhi(ll n) { for(int i=1;i<=n;i++) phi[i]=i; for(int i=2;i<=n;i++) { if(!mark[i]) { for(int j=i;j<=n;j+=i) { mark[j]=1; phi[j]*=(1-1/(double)i); } } } for(ll i=1;i<=n;i++) { for(ll j=i;j<=n;j+=i) divi[j]++; } } /* Precode Ends */ #define mod 1000000007 ll A[5000001], B[5000001]; vector<ll> hia; vector<ll> nah; ll rowMap[300001], colMap[300001]; map<pair<ll, ll>, ll> myMap; set<ll> mySet; vector<pair<ll, ll>> vp; priority_queue<ll> pq; priority_queue<ll, vector<ll>, std::greater<ll>> first; ll po(ll a, ll n) { ll ans = 1; for (int i = 1; i <= n; i++) ans *= a; return ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll r, c, m, a, b, row = 0, col = 0; cin >> r >> c >> m; for (int i = 1; i <= m; i++) { cin >> a >> b; rowMap[a]++; colMap[b]++; myMap[make_pair(a, b)] = 1; } for (int i = 1; i <= r; i++) { row = max(row, rowMap[i]); } for (int i = 1; i <= r; i++) { if (row == rowMap[i]) { hia.push_back(i); } } for (int i = 1; i <= c; i++) { col = max(col, colMap[i]); } for (int i = 1; i <= c; i++) { if (col == colMap[i]) { nah.push_back(i); } } ll f = 0; for (int i = 0; i < hia.size(); i++) { for (int j = 0; j < nah.size(); j++) { if (myMap[make_pair(hia[i], nah[j])] == 0) { f = 1; break; } } } if (f == 1) { cout << row + col << endl; } else cout << row + col - 1 << endl; return 0; }
insert
154
154
154
155
TLE
p02580
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <string> #include <vector> #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long int #define mod 1000000007 #define inf 1e18 + 42 #define endl "\n" #define pi 3.1415926535897932384626433832795028841971693993751058 #define maxn 100005 #define out1(a) cout << #a << " " << a << endl #define out2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl #define out3(a, b, c) \ cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \ << endl #define rep(i, a, b) for (int i = a; i < b; i++) #define repr(i, a, b) for (int i = a; i >= b; i--) #define fori(it, A) for (auto it = A.begin(); it != A.end(); it++) #define ft first #define sd second #define pb push_back #define mp make_pair #define pq priority_queue #define all(x) (x).begin(), (x).end() #define zero(x) memset(x, 0, sizeof(x)); #define ceil(a, b) (a + b - 1) / b using namespace std; int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } // START OF CODE ->->->->->->-> void solve() { int h, w, m; cin >> h >> w >> m; int mx_r = 0; int mx_c = 0; vector<pair<int, int>> p; map<pair<int, int>, int> chk; map<int, int> f, s; rep(i, 0, m) { int x, y; cin >> x >> y; s[x]++; f[y]++; chk[{x, y}]++; p.pb({x, y}); } vector<int> r, c; fori(it, s) { if (it->sd > mx_r) { mx_r = it->sd; } } fori(it, s) { if (it->sd == mx_r) { r.pb(it->ft); } } fori(it, f) { if (it->sd > mx_c) { mx_c = it->sd; } } fori(it, f) { if (it->sd == mx_c) { c.pb(it->ft); } } // rep(i,0,r.size()){ // out1(r[i]); // } // rep(i,0,c.size()){ // out1(c[i]); // } int ans = 0; rep(i, 0, r.size()) { rep(j, 0, c.size()) { if (chk[{r[i], c[j]}] > 0) { ans = max(ans, mx_r + mx_c - 1); } else { ans = max(ans, mx_r + mx_c); } } } cout << ans << endl; } // END OF CODE ->->->->->->->-> signed main() { fast; int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <string> #include <vector> #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long int #define mod 1000000007 #define inf 1e18 + 42 #define endl "\n" #define pi 3.1415926535897932384626433832795028841971693993751058 #define maxn 100005 #define out1(a) cout << #a << " " << a << endl #define out2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl #define out3(a, b, c) \ cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \ << endl #define rep(i, a, b) for (int i = a; i < b; i++) #define repr(i, a, b) for (int i = a; i >= b; i--) #define fori(it, A) for (auto it = A.begin(); it != A.end(); it++) #define ft first #define sd second #define pb push_back #define mp make_pair #define pq priority_queue #define all(x) (x).begin(), (x).end() #define zero(x) memset(x, 0, sizeof(x)); #define ceil(a, b) (a + b - 1) / b using namespace std; int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } // START OF CODE ->->->->->->-> void solve() { int h, w, m; cin >> h >> w >> m; int mx_r = 0; int mx_c = 0; vector<pair<int, int>> p; map<pair<int, int>, int> chk; map<int, int> f, s; rep(i, 0, m) { int x, y; cin >> x >> y; s[x]++; f[y]++; chk[{x, y}]++; p.pb({x, y}); } vector<int> r, c; fori(it, s) { if (it->sd > mx_r) { mx_r = it->sd; } } fori(it, s) { if (it->sd == mx_r) { r.pb(it->ft); } } fori(it, f) { if (it->sd > mx_c) { mx_c = it->sd; } } fori(it, f) { if (it->sd == mx_c) { c.pb(it->ft); } } // rep(i,0,r.size()){ // out1(r[i]); // } // rep(i,0,c.size()){ // out1(c[i]); // } int ans = 0; rep(i, 0, r.size()) { rep(j, 0, c.size()) { if (chk[{r[i], c[j]}] > 0) { ans = max(ans, mx_r + mx_c - 1); } else { ans = max(ans, mx_r + mx_c); cout << ans << endl; return; } } } cout << ans << endl; } // END OF CODE ->->->->->->->-> signed main() { fast; int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
insert
101
101
101
103
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define mp make_pair #define int long long #define ll long long #define ll long long #define all(c) (c).begin(), (c).end() #define M 1000000007 #define INF LLONG_MAX #define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__) template <class T> void dbs(string str, T t) { cerr << str << " : " << t << "\n"; } template <class T, class... S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...); } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream &operator<<(ostream &os, const vector<T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class T> ostream &operator<<(ostream &os, const set<T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class S, class T> ostream &operator<<(ostream &os, const map<S, T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class T> void prc(T a, T b) { cerr << "["; for (T i = a; i != b; ++i) { if (i != a) cerr << ", "; cerr << *i; } cerr << "]\n"; } // Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n) // const int N = 3e5 + 5; map<pair<int, int>, int> dict; int h, w, m; int x[N], y[N]; int32_t main() { fastio; // freopen("file.in", "r", stdin); // freopen("file.out", "w", stdout); cin >> h >> w >> m; vector<pair<int, int>> v(m); for (int i = 0; i < m; i++) { cin >> v[i].first >> v[i].second; x[v[i].first]++; y[v[i].second]++; dict[{v[i].first, v[i].second}] = 1LL; } int mx_x = *max_element(x + 1, x + h + 1); int mx_y = *max_element(y + 1, y + w + 1); vector<int> X, Y; for (int i = 1; i <= h; i++) if (x[i] == mx_x) X.pb(i); for (int i = 1; i <= w; i++) if (y[i] == mx_y) Y.pb(i); int ans = 0; for (int i : X) { for (int j : Y) { int z = 0; if (dict.find({i, j}) != dict.end()) z = 1; ans = max(ans, x[i] + y[j] - z); } } // for(int i=1;i<=h;i++) // { // for(int j=1;j<=w;j++) // { // int z = 0; // if(dict.find({i, j}) != dict.end()) z = 1; // ans = max(ans, x[i] + y[j] - z); // } // } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define mp make_pair #define int long long #define ll long long #define ll long long #define all(c) (c).begin(), (c).end() #define M 1000000007 #define INF LLONG_MAX #define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__) template <class T> void dbs(string str, T t) { cerr << str << " : " << t << "\n"; } template <class T, class... S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...); } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream &operator<<(ostream &os, const vector<T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class T> ostream &operator<<(ostream &os, const set<T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class S, class T> ostream &operator<<(ostream &os, const map<S, T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class T> void prc(T a, T b) { cerr << "["; for (T i = a; i != b; ++i) { if (i != a) cerr << ", "; cerr << *i; } cerr << "]\n"; } // Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n) // const int N = 3e5 + 5; map<pair<int, int>, int> dict; int h, w, m; int x[N], y[N]; int32_t main() { fastio; // freopen("file.in", "r", stdin); // freopen("file.out", "w", stdout); cin >> h >> w >> m; vector<pair<int, int>> v(m); for (int i = 0; i < m; i++) { cin >> v[i].first >> v[i].second; x[v[i].first]++; y[v[i].second]++; dict[{v[i].first, v[i].second}] = 1LL; } int mx_x = *max_element(x + 1, x + h + 1); int mx_y = *max_element(y + 1, y + w + 1); vector<int> X, Y; for (int i = 1; i <= h; i++) if (x[i] == mx_x) X.pb(i); for (int i = 1; i <= w; i++) if (y[i] == mx_y) Y.pb(i); int ans = 0; for (int i : X) { for (int j : Y) { int z = 0; if (dict.find({i, j}) != dict.end()) z = 1; ans = max(ans, x[i] + y[j] - z); if (z == 0) { cout << ans << "\n"; return 0; } } } // for(int i=1;i<=h;i++) // { // for(int j=1;j<=w;j++) // { // int z = 0; // if(dict.find({i, j}) != dict.end()) z = 1; // ans = max(ans, x[i] + y[j] - z); // } // } cout << ans << "\n"; return 0; }
insert
93
93
93
97
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define fi(a, b) for (int i = a; i < b; i++) #define fj(a, b) for (int j = a; j < b; j++) #define ff first #define ss second #define ll long long #define ld long double #define ull unsigned long long #define bp(x) __builtin_popcount(x) #define pr(x) \ for (auto it : x) \ cout << it << " "; \ cout << endl; #define endl "\n" typedef vector<int> vi; typedef vector<pair<int, int>> vii; typedef vector<long long> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vll; void nikal_pehli_fursat_mai() { int n, m, w; cin >> n >> m >> w; vi x(n, 0), y(m, 0); map<pii, int> arr; int mx = 0, my = 0; vi v1, v2; fi(0, w) { int u, v; cin >> u >> v; u--; v--; arr[{u, v}]++; x[u]++; y[v]++; mx = max(mx, x[u]); my = max(my, y[v]); } fi(0, n) { if (mx == x[i]) v1.push_back(i); } fi(0, m) { if (my == y[i]) v2.push_back(i); } int ans = 0; fi(0, v1.size()) { fj(0, v2.size()) { ans = max(ans, mx + my - arr[{v1[i], v2[j]}]); } } cout << ans << endl; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); int tc = 1; // cin>>tc; while (tc--) { nikal_pehli_fursat_mai(); } }
#include <bits/stdc++.h> using namespace std; #define fi(a, b) for (int i = a; i < b; i++) #define fj(a, b) for (int j = a; j < b; j++) #define ff first #define ss second #define ll long long #define ld long double #define ull unsigned long long #define bp(x) __builtin_popcount(x) #define pr(x) \ for (auto it : x) \ cout << it << " "; \ cout << endl; #define endl "\n" typedef vector<int> vi; typedef vector<pair<int, int>> vii; typedef vector<long long> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vll; void nikal_pehli_fursat_mai() { int n, m, w; cin >> n >> m >> w; vi x(n, 0), y(m, 0); map<pii, int> arr; int mx = 0, my = 0; vi v1, v2; fi(0, w) { int u, v; cin >> u >> v; u--; v--; arr[{u, v}]++; x[u]++; y[v]++; mx = max(mx, x[u]); my = max(my, y[v]); } fi(0, n) { if (mx == x[i]) v1.push_back(i); } fi(0, m) { if (my == y[i]) v2.push_back(i); } int ans = 0; fi(0, v1.size()) { fj(0, v2.size()) { if (arr[{v1[i], v2[j]}]) { ans = mx + my - 1; } else { ans = mx + my; cout << ans << endl; return; } } } cout << ans << endl; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); int tc = 1; // cin>>tc; while (tc--) { nikal_pehli_fursat_mai(); } }
replace
51
52
51
60
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll hor[300005], ver[300005]; int main() { ll n, m, t, res = 0; cin >> n >> m >> t; set<pair<ll, ll>> s; set<ll> px, py; while (t--) { ll x, y; cin >> x >> y; hor[x]++; ver[y]++; s.insert({x, y}); } ll mx = *max_element(hor, hor + 300005); ll my = *max_element(ver, ver + 300005); for (ll i = 1; i <= 300005; i++) { if (hor[i] == mx) px.insert(i); if (ver[i] == my) py.insert(i); } for (auto i : px) { for (auto j : py) { ll tmp = hor[i] + ver[j]; if (s.find({i, j}) != s.end()) tmp -= 1; res = max(res, tmp); } } cout << res; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll hor[300005], ver[300005]; int main() { ll n, m, t, res = 0; cin >> n >> m >> t; set<pair<ll, ll>> s; set<ll> px, py; while (t--) { ll x, y; cin >> x >> y; hor[x]++; ver[y]++; s.insert({x, y}); } ll mx = *max_element(hor, hor + 300005); ll my = *max_element(ver, ver + 300005); for (ll i = 1; i <= 300005; i++) { if (hor[i] == mx) px.insert(i); if (ver[i] == my) py.insert(i); } for (auto i : px) { for (auto j : py) { ll tmp = hor[i] + ver[j]; if (s.find({i, j}) != s.end()) tmp -= 1; res = max(res, tmp); if (res == mx + my) { cout << res; return 0; } } } cout << res; }
insert
35
35
35
39
TLE
p02580
Python
Time Limit Exceeded
#!/usr/bin/env python3 def main(): H, W, M = map(int, input().split()) bomb = [list(map(int, input().split())) for i in range(M)] H_bomb = [0] * (H + 1) W_bomb = [0] * (W + 1) for b in bomb: H_bomb[b[0]] += 1 W_bomb[b[1]] += 1 ans = max(H_bomb) + max(W_bomb) H_bomb_index = [i for i, v in enumerate(H_bomb) if v == max(H_bomb)] W_bomb_index = [i for i, v in enumerate(W_bomb) if v == max(W_bomb)] x_point = [] for h in H_bomb_index: for w in W_bomb_index: x_point.append([h, w]) flag = True for x in x_point: if x not in bomb: flag = False if flag: ans -= 1 print(ans) if __name__ == "__main__": main()
#!/usr/bin/env python3 def main(): H, W, M = map(int, input().split()) bomb = [list(map(int, input().split())) for i in range(M)] H_bomb = [0] * (H + 1) W_bomb = [0] * (W + 1) for b in bomb: H_bomb[b[0]] += 1 W_bomb[b[1]] += 1 max_h, max_w = max(H_bomb), max(W_bomb) cnt = H_bomb.count(max_h) * W_bomb.count(max_w) for b in bomb: if H_bomb[b[0]] == max_h and W_bomb[b[1]] == max_w: cnt -= 1 print(max_h + max_w + bool(cnt) - 1) if __name__ == "__main__": main()
replace
11
25
11
17
TLE
p02580
Python
Runtime Error
H, W, M = map(int, input().split()) B = [list(map(int, input().split())) for _ in range(M)] bombs_row = [0] * H bombs_col = [0] * W for b in B: bombs_row[b[0] - 1] += 1 bombs_col[b[1] - 1] += 1 row_max = max(bombs_row) col_max = max(bombs_col) row_max_count = bombs_row.count(row_max) col_max_count = bombs_col.count(col_max) ans = row_max + col_max possible_point = row_max_count * col_max_count bombed_point = 0 for b in B: if bombs_row[b[0]] == row_max and bombs_col[b[1]] == col_max: bombed_point += 1 if bombed_point == possible_point: ans -= 1 print(ans)
H, W, M = map(int, input().split()) B = [list(map(int, input().split())) for _ in range(M)] bombs_row = [0] * H bombs_col = [0] * W for b in B: bombs_row[b[0] - 1] += 1 bombs_col[b[1] - 1] += 1 row_max = max(bombs_row) col_max = max(bombs_col) row_max_count = bombs_row.count(row_max) col_max_count = bombs_col.count(col_max) ans = row_max + col_max possible_point = row_max_count * col_max_count bombed_point = 0 for b in B: if bombs_row[b[0] - 1] == row_max and bombs_col[b[1] - 1] == col_max: bombed_point += 1 if bombed_point == possible_point: ans -= 1 print(ans)
replace
24
25
24
25
IndexError: list index out of range
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02580/Python/s510602402.py", line 25, in <module> if bombs_row[b[0]] == row_max and bombs_col[b[1]] == col_max: IndexError: list index out of range
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; #define INF 1000000000 #define pb push_back #define sz(a) int((a).size()) #define all(c) c.begin(), c.end() #define tr(c, i) for (typeof(c).begin() i = c.begin(); i != c.end(); i++) #define present(c, x) (c.find(x) != c.end()) #define cpresent(c, x) (find(all(c), x) != c.end()) ll bigmod(ll a, ll b, ll m) { if (b == 0) return 1; ll x = bigmod(a, b / 2, m); x = (x * x) % m; if (b % 2) x = (x * a) % m; return x; } ll bigsum(ll a, ll b, ll m) { ll s; if (b == 0) return b; if (b == 1) return a + 1; if (b % 2) { b = b / 2; s = bigsum(a, b, m) % m; s = (s * bigmod(a, b + 1, m)) % m; return s; } else { s = bigsum(a, b - 1, m) % m; s = (a * s + 1) % m; return s; } } int main() { int h, w, m, i, j, mr = 0, mc = 0, l1, l2, im, a, b, row[3005] = {0}, col[3005] = {0}; vi vr; vi vc; map<pair<int, int>, int> mp; cin >> h >> w >> m; for (i = 0; i < m; i++) { cin >> a >> b; mp[make_pair(a, b)] = 35; row[a]++; col[b]++; } for (i = 0; i <= h; i++) { mr = max(mr, row[i]); } for (i = 0; i <= w; i++) { mc = max(mc, col[i]); } for (i = 0; i <= h; i++) { if (row[i] == mr) vr.pb(i); } for (i = 0; i <= w; i++) { if (col[i] == mc) vc.pb(i); } im = 1; l1 = vr.size(); l2 = vc.size(); for (i = 0; i < l1; i++) { for (j = 0; j < l2; j++) { if (mp.find(make_pair(vr[i], vc[j])) != mp.end()) { continue; } else { im = 0; break; } } if (im == 0) break; } if (im == 0) cout << mr + mc << endl; else cout << mr + mc - 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; #define INF 1000000000 #define pb push_back #define sz(a) int((a).size()) #define all(c) c.begin(), c.end() #define tr(c, i) for (typeof(c).begin() i = c.begin(); i != c.end(); i++) #define present(c, x) (c.find(x) != c.end()) #define cpresent(c, x) (find(all(c), x) != c.end()) ll bigmod(ll a, ll b, ll m) { if (b == 0) return 1; ll x = bigmod(a, b / 2, m); x = (x * x) % m; if (b % 2) x = (x * a) % m; return x; } ll bigsum(ll a, ll b, ll m) { ll s; if (b == 0) return b; if (b == 1) return a + 1; if (b % 2) { b = b / 2; s = bigsum(a, b, m) % m; s = (s * bigmod(a, b + 1, m)) % m; return s; } else { s = bigsum(a, b - 1, m) % m; s = (a * s + 1) % m; return s; } } int main() { int h, w, m, i, j, mr = 0, mc = 0, l1, l2, im, a, b, row[300005] = {0}, col[300005] = {0}; vi vr; vi vc; map<pair<int, int>, int> mp; cin >> h >> w >> m; for (i = 0; i < m; i++) { cin >> a >> b; mp[make_pair(a, b)] = 35; row[a]++; col[b]++; } for (i = 0; i <= h; i++) { mr = max(mr, row[i]); } for (i = 0; i <= w; i++) { mc = max(mc, col[i]); } for (i = 0; i <= h; i++) { if (row[i] == mr) vr.pb(i); } for (i = 0; i <= w; i++) { if (col[i] == mc) vc.pb(i); } im = 1; l1 = vr.size(); l2 = vc.size(); for (i = 0; i < l1; i++) { for (j = 0; j < l2; j++) { if (mp.find(make_pair(vr[i], vc[j])) != mp.end()) { continue; } else { im = 0; break; } } if (im == 0) break; } if (im == 0) cout << mr + mc << endl; else cout << mr + mc - 1 << endl; return 0; }
replace
48
50
48
50
0
p02580
C++
Time Limit Exceeded
// Fri Aug 21 19:35:37 IST 2020 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define forn(ii, a, b) for (int ii = (int)a; ii < (int)b; ii++) #define scan(any) \ for (auto &i : any) \ cin >> i; #define debug(x) cerr << #x << " " << x << " -- \n" #define I__O ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define int64 long long #define all(x) (x).begin(), (x).end() #define ff first #define ss second #define pppp pair<int, int> #define flushOff fflush(stdout) #define precise(x) cout << fixed << setprecision(12) << x << '\n'; using namespace std; // policy based using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; const int MOD1 = 1e9 + 7; const int MOD2 = 1e9 + 9; const double pi = 3.141592653589793238; const int N = 1e5 + 7; const int INF = 2e9; const int64 reallyBig = 1e16 + 7; struct compare { bool operator()(pair<int, int> A, pair<int, int> B) { if (A.first == B.first) return A.second > B.second; return A.first > B.first; } }; int tests() { int H, W; cin >> H >> W; int M; cin >> M; vector<int> row(H + 1), col(W + 1); set<pair<int, int>> s; forn(k, 0, M) { int a, b; cin >> a >> b; row[a]++; col[b]++; s.insert({a, b}); } int row_mex = *max_element(all(row)); int col_mex = *max_element(all(col)); int row_len = 0, col_len = 0; vector<int> v1, v2; forn(i, 1, H + 1) if (row_mex == row[i]) row_len++, v1.push_back(i); forn(i, 1, W + 1) if (col_mex == col[i]) col_len++, v2.push_back(i); int ans = 0; for (int &t : v1) for (int &p : v2) ans = max(ans, row_mex + col_mex - (int)(s.find({t, p}) != s.end())); cout << ans << '\n'; return 0; } int main() { I__O; int cases = 1; // cin >> cases ; while (cases--) tests(); return 0; }
// Fri Aug 21 19:35:37 IST 2020 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define forn(ii, a, b) for (int ii = (int)a; ii < (int)b; ii++) #define scan(any) \ for (auto &i : any) \ cin >> i; #define debug(x) cerr << #x << " " << x << " -- \n" #define I__O ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define int64 long long #define all(x) (x).begin(), (x).end() #define ff first #define ss second #define pppp pair<int, int> #define flushOff fflush(stdout) #define precise(x) cout << fixed << setprecision(12) << x << '\n'; using namespace std; // policy based using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; const int MOD1 = 1e9 + 7; const int MOD2 = 1e9 + 9; const double pi = 3.141592653589793238; const int N = 1e5 + 7; const int INF = 2e9; const int64 reallyBig = 1e16 + 7; struct compare { bool operator()(pair<int, int> A, pair<int, int> B) { if (A.first == B.first) return A.second > B.second; return A.first > B.first; } }; int tests() { int H, W; cin >> H >> W; int M; cin >> M; vector<int> row(H + 1), col(W + 1); set<pair<int, int>> s; forn(k, 0, M) { int a, b; cin >> a >> b; row[a]++; col[b]++; s.insert({a, b}); } int row_mex = *max_element(all(row)); int col_mex = *max_element(all(col)); int row_len = 0, col_len = 0; vector<int> v1, v2; forn(i, 1, H + 1) if (row_mex == row[i]) row_len++, v1.push_back(i); forn(i, 1, W + 1) if (col_mex == col[i]) col_len++, v2.push_back(i); int64 check = (int64)row_len * col_len; if (check > M) return cout << row_mex + col_mex << '\n', 0; int ans = 0; for (int &t : v1) for (int &p : v2) ans = max(ans, row_mex + col_mex - (int)(s.find({t, p}) != s.end())); cout << ans << '\n'; return 0; } int main() { I__O; int cases = 1; // cin >> cases ; while (cases--) tests(); return 0; }
insert
59
59
59
62
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using ll = long long; #define FOR(i, k, n) for (ll i = (k); i < (n); i++) #define FORe(i, k, n) for (ll i = (k); i <= (n); i++) #define FORr(i, k, n) for (ll i = (k)-1; i > (n); i--) #define FORre(i, k, n) for (ll i = (k)-1; i >= (n); i--) #define REP(i, n) FOR(i, 0, n) #define REPr(i, n) FORre(i, n, 0) #define ALL(x) (x).begin(), (x).end() #define ALLr(x) (x).rbegin(), (x).rend() #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) using namespace std; const int INF = 1001001001; using P = pair<ll, ll>; int main(void) { ll H, W, M; cin >> H >> W >> M; vector<ll> h(M), w(M); map<P, ll> mp; REP(i, M) { cin >> h[i] >> w[i]; h[i]--; w[i]--; mp[P(h[i], w[i])]++; } vector<ll> a(H, 0), b(W, 0); REP(i, M) a[h[i]]++, b[w[i]]++; ll c = *max_element(ALL(a)); ll d = *max_element(ALL(b)); vector<ll> p, q; REP(i, H) { if (a[i] == c) p.emplace_back(i); if (b[i] == d) q.emplace_back(i); } ll n = p.size(), m = q.size(); ll ans = c + d - 1; REP(i, n) REP(j, m) { mp[P(p[i], q[j])]; if (!mp[P(p[i], q[j])]) { ans = c + d; break; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using ll = long long; #define FOR(i, k, n) for (ll i = (k); i < (n); i++) #define FORe(i, k, n) for (ll i = (k); i <= (n); i++) #define FORr(i, k, n) for (ll i = (k)-1; i > (n); i--) #define FORre(i, k, n) for (ll i = (k)-1; i >= (n); i--) #define REP(i, n) FOR(i, 0, n) #define REPr(i, n) FORre(i, n, 0) #define ALL(x) (x).begin(), (x).end() #define ALLr(x) (x).rbegin(), (x).rend() #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) using namespace std; const int INF = 1001001001; using P = pair<ll, ll>; int main(void) { ll H, W, M; cin >> H >> W >> M; vector<ll> h(M), w(M); map<P, ll> mp; REP(i, M) { cin >> h[i] >> w[i]; h[i]--; w[i]--; mp[P(h[i], w[i])]++; } vector<ll> a(H, 0), b(W, 0); REP(i, M) a[h[i]]++, b[w[i]]++; ll c = *max_element(ALL(a)); ll d = *max_element(ALL(b)); vector<ll> p, q; REP(i, H) if (a[i] == c) p.emplace_back(i); REP(i, W) if (b[i] == d) q.emplace_back(i); ll n = p.size(), m = q.size(); ll ans = c + d - 1; REP(i, n) REP(j, m) { mp[P(p[i], q[j])]; if (!mp[P(p[i], q[j])]) { ans = c + d; break; } } cout << ans << endl; return 0; }
replace
35
41
35
38
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using P = pair<ll, ll>; const long double PI = acos(-1.0L); ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } int main() { int h, w, m; cin >> h >> w >> m; vector<int> hvec(h, 0); vector<int> wvec(w, 0); vector<vector<int>> checker(h, vector<int>()); vector<vector<int>> checker2(w, vector<int>()); for (int i = 0; i < m; ++i) { int ch, cw; cin >> ch >> cw; ch--; cw--; hvec[ch]++; wvec[cw]++; checker[ch].emplace_back(cw); checker2[cw].emplace_back(ch); } for (int i = 0; i < h; ++i) { sort(checker[i].begin(), checker[i].end()); } for (int i = 0; i < w; ++i) { sort(checker2[i].begin(), checker2[i].end()); } int hmax = 0; for (int i = 0; i < h; ++i) { if (hmax <= hvec[i]) { hmax = hvec[i]; } } // hの候補 vector<int> hc; for (int i = 0; i < h; ++i) { if (hmax == hvec[i]) hc.emplace_back(i); } int wmax = 0; for (int i = 0; i < w; ++i) { if (wmax <= wvec[i]) { wmax = wvec[i]; } } // wの候補 vector<int> wc; for (int i = 0; i < w; ++i) { if (wmax == wvec[i]) wc.emplace_back(i); } int ans = 0; int hlen = hc.size(); int wlen = wc.size(); for (int i = 0; i < hlen; ++i) { for (int j = 0; j < wlen; ++j) { int cch = hc[i], ccw = wc[j]; int ccc = hvec[cch] + wvec[ccw]; int cchhlen = checker[cch].size(); int ccwwlen = checker2[ccw].size(); int lc, uc; if (cchhlen < ccwwlen) { lc = lower_bound(checker[cch].begin(), checker[cch].end(), ccw) - checker[cch].begin(); uc = upper_bound(checker[cch].begin(), checker[cch].end(), ccw) - checker[cch].begin(); } else { lc = lower_bound(checker2[ccw].begin(), checker2[ccw].end(), cch) - checker2[ccw].begin(); uc = upper_bound(checker2[ccw].begin(), checker2[ccw].end(), cch) - checker2[ccw].begin(); } if (lc != uc) ccc--; chmax(ans, ccc); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using P = pair<ll, ll>; const long double PI = acos(-1.0L); ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } int main() { int h, w, m; cin >> h >> w >> m; vector<int> hvec(h, 0); vector<int> wvec(w, 0); vector<vector<int>> checker(h, vector<int>()); vector<vector<int>> checker2(w, vector<int>()); for (int i = 0; i < m; ++i) { int ch, cw; cin >> ch >> cw; ch--; cw--; hvec[ch]++; wvec[cw]++; checker[ch].emplace_back(cw); checker2[cw].emplace_back(ch); } for (int i = 0; i < h; ++i) { sort(checker[i].begin(), checker[i].end()); } for (int i = 0; i < w; ++i) { sort(checker2[i].begin(), checker2[i].end()); } int hmax = 0; for (int i = 0; i < h; ++i) { if (hmax <= hvec[i]) { hmax = hvec[i]; } } // hの候補 vector<int> hc; for (int i = 0; i < h; ++i) { if (hmax == hvec[i]) hc.emplace_back(i); } int wmax = 0; for (int i = 0; i < w; ++i) { if (wmax <= wvec[i]) { wmax = wvec[i]; } } // wの候補 vector<int> wc; for (int i = 0; i < w; ++i) { if (wmax == wvec[i]) wc.emplace_back(i); } int ans = 0; int hlen = hc.size(); int wlen = wc.size(); if (hlen == h && wlen == w) { if (h == 1 && w == 1) cout << 1 << endl; else cout << 2 << endl; return 0; } for (int i = 0; i < hlen; ++i) { for (int j = 0; j < wlen; ++j) { int cch = hc[i], ccw = wc[j]; int ccc = hvec[cch] + wvec[ccw]; int cchhlen = checker[cch].size(); int ccwwlen = checker2[ccw].size(); int lc, uc; if (cchhlen < ccwwlen) { lc = lower_bound(checker[cch].begin(), checker[cch].end(), ccw) - checker[cch].begin(); uc = upper_bound(checker[cch].begin(), checker[cch].end(), ccw) - checker[cch].begin(); } else { lc = lower_bound(checker2[ccw].begin(), checker2[ccw].end(), cch) - checker2[ccw].begin(); uc = upper_bound(checker2[ccw].begin(), checker2[ccw].end(), cch) - checker2[ccw].begin(); } if (lc != uc) ccc--; chmax(ans, ccc); } } cout << ans << endl; }
insert
76
76
76
83
TLE
p02580
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; int main(void) { int H, W, M; cin >> H >> W >> M; // map<int,int> X, Y; // map< pair<int,int> ,int> mp; vector<vector<int>> X(H); vector<int> Y(W); for (int i = 0; i < M; i++) { int x, y; cin >> x >> y; --x; --y; X[x].emplace_back(y); Y[y]++; // X[x]++; // Y[y]++; // mp[make_pair(x, y)]++; } multiset<int> mst; for (auto e : Y) { mst.insert(e); } int ans = 0; for (int i = 0; i < H; i++) { for (auto y : X[i]) { ans = max(ans, (int)X[i].size() + Y[y] - 1); } for (auto y : X[i]) { mst.erase(mst.find(Y[y])); } ans = max(ans, (int)X[i].size() + *mst.rbegin()); for (auto y : X[i]) { mst.insert(Y[y]); } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; int main(void) { int H, W, M; cin >> H >> W >> M; // map<int,int> X, Y; // map< pair<int,int> ,int> mp; vector<vector<int>> X(H); vector<int> Y(W); for (int i = 0; i < M; i++) { int x, y; cin >> x >> y; --x; --y; X[x].emplace_back(y); Y[y]++; // X[x]++; // Y[y]++; // mp[make_pair(x, y)]++; } multiset<int> mst; for (auto e : Y) { mst.insert(e); } int ans = 0; for (int i = 0; i < H; i++) { for (auto y : X[i]) { ans = max(ans, (int)X[i].size() + Y[y] - 1); } for (auto y : X[i]) { mst.erase(mst.find(Y[y])); } if (mst.size()) ans = max(ans, (int)X[i].size() + *mst.rbegin()); for (auto y : X[i]) { mst.insert(Y[y]); } } cout << ans << endl; return 0; }
replace
45
46
45
47
0
p02580
C++
Time Limit Exceeded
/* author : seryu title : ABC176E_"Bomber" */ #include <bits/stdc++.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 rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rreps(i, n) for (int i = n; i >= 1; i--) #define mrep(i, j, n) for (int i = j; i < n; i++) #define mreps(i, j, n) for (int i = j; i <= n; i++) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define ERASE(x, val) x.erase(remove(all(x), val), x.end()) #define MOD 1000000007 typedef long long ll; typedef pair<int, int> P; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } // vector<pair<int,int>>の比較関数 bool compare_by_second(pair<int, int> a, pair<int, int> b) { if (a.first != b.first) return a.first < b.first; else return a.second < b.second; } void solve() { int h, w, m; cin >> h >> w >> m; vector<P> r_sum, c_sum; rep(i, h) r_sum.push_back({0, i}); rep(i, w) c_sum.push_back({0, i}); vector<P> obj; rep(i, m) { int a, b; cin >> a >> b; a--; b--; obj.push_back({a, b}); r_sum[a].first++; c_sum[b].first++; } sort(all(obj)); sort(all(r_sum)); reverse(all(r_sum)); sort(all(c_sum)); reverse(all(c_sum)); int ans = 0; int i_r = 0, i_c = 0; int last_r = r_sum[i_r].first, last_c = c_sum[i_c].first; while (true) { int tmp = last_r + last_c; int r = r_sum[i_r].second; int c = c_sum[i_c].second; bool cross = false; rep(i, m) if (obj[i].first == r && obj[i].second == c) cross = true; if (cross) tmp--; chmax(ans, tmp); if (i_r + 1 < h && r_sum[i_r + 1].first == last_r) { i_r++; } else if (i_c + 1 < w && c_sum[i_c + 1].first == last_c) { i_c++; } else { break; } } cout << ans << endl; return; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); return 0; }
/* author : seryu title : ABC176E_"Bomber" */ #include <bits/stdc++.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 rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rreps(i, n) for (int i = n; i >= 1; i--) #define mrep(i, j, n) for (int i = j; i < n; i++) #define mreps(i, j, n) for (int i = j; i <= n; i++) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define ERASE(x, val) x.erase(remove(all(x), val), x.end()) #define MOD 1000000007 typedef long long ll; typedef pair<int, int> P; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } // vector<pair<int,int>>の比較関数 bool compare_by_second(pair<int, int> a, pair<int, int> b) { if (a.first != b.first) return a.first < b.first; else return a.second < b.second; } void solve() { int h, w, m; cin >> h >> w >> m; vector<P> r_sum, c_sum; rep(i, h) r_sum.push_back({0, i}); rep(i, w) c_sum.push_back({0, i}); vector<P> obj; rep(i, m) { int a, b; cin >> a >> b; a--; b--; obj.push_back({a, b}); r_sum[a].first++; c_sum[b].first++; } sort(all(obj)); sort(all(r_sum)); reverse(all(r_sum)); sort(all(c_sum)); reverse(all(c_sum)); int ans = 0; int i_r = 0, i_c = 0; int last_r = r_sum[i_r].first, last_c = c_sum[i_c].first; while (true) { int tmp = last_r + last_c; int r = r_sum[i_r].second; int c = c_sum[i_c].second; bool cross = [&] { int left = 0, right = m; while (left <= right) { int mid = (left + right) / 2; if (obj[mid].first == r && obj[mid].second == c) return true; else if (obj[mid].first < r) left = mid + 1; else if (obj[mid].first > r) right = mid - 1; else if (obj[mid].second < c) left = mid + 1; else right = mid - 1; } return false; }(); if (cross) tmp--; chmax(ans, tmp); if (i_r + 1 < h && r_sum[i_r + 1].first == last_r) { i_r++; } else if (i_c + 1 < w && c_sum[i_c + 1].first == last_c) { i_c++; } else { break; } } cout << ans << endl; return; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); return 0; }
replace
70
72
70
88
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define MOD 1000000007 using namespace std; using ll = long long; int mp[1005][1005] = {}; int main() { int h, w, m; cin >> h >> w >> m; vector<int> height(h), width(w); set<pair<int, int>> block; rep(i, m) { int hei, wid; cin >> hei >> wid; hei--; wid--; block.emplace(hei, wid); height[hei]++; width[wid]++; } int mh = 0, mw = 0; rep(i, h) mh = max(mh, height[i]); rep(i, w) mw = max(mw, width[i]); int ans = mh + mw; rep(i, h) { if (height[i] != mh) continue; rep(j, w) { if (width[j] != mw) continue; if (block.count(pair<int, int>(i, j))) continue; cout << ans << endl; return 0; } } cout << ans - 1 << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define MOD 1000000007 using namespace std; using ll = long long; int mp[1005][1005] = {}; int main() { int h, w, m; cin >> h >> w >> m; vector<int> height(h), width(w); set<pair<int, int>> block; rep(i, m) { int hei, wid; cin >> hei >> wid; hei--; wid--; block.emplace(hei, wid); height[hei]++; width[wid]++; } int mh = 0, mw = 0; rep(i, h) mh = max(mh, height[i]); rep(i, w) mw = max(mw, width[i]); int ans = mh + mw; vector<int> tate, yoko; rep(i, h) if (mh == height[i]) tate.push_back(i); rep(i, w) if (mw == width[i]) yoko.push_back(i); for (int i : tate) { for (int j : yoko) { if (block.count(pair<int, int>(i, j))) continue; cout << ans << endl; return 0; } } cout << ans - 1 << endl; return 0; }
replace
27
33
27
32
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define pb push_back using namespace std; typedef long long ll; int main() { int H, W, m; cin >> H >> W >> m; vector<int> a(H), b(W); set<pair<int, int>> bomb; rep(i, m) { int h, w; cin >> h >> w; h--; w--; bomb.insert({h, w}); a[h]++; b[w]++; } int res1 = 0, res2 = 0; int ans = 0; rep(i, H) res1 = max(res1, a[i]); rep(i, W) res2 = max(res2, b[i]); vector<int> p, q; rep(i, H) if (a[i] == res1) p.pb(i); rep(i, W) if (b[i] == res2) q.pb(i); rep(i, p.size()) { rep(j, q.size()) { if (bomb.count({p[i], q[j]})) ans = max(ans, res1 + res2 - 1); else ans = max(ans, res1 + res2); } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define pb push_back using namespace std; typedef long long ll; int main() { int H, W, m; cin >> H >> W >> m; vector<int> a(H), b(W); set<pair<int, int>> bomb; rep(i, m) { int h, w; cin >> h >> w; h--; w--; bomb.insert({h, w}); a[h]++; b[w]++; } int res1 = 0, res2 = 0; int ans = 0; rep(i, H) res1 = max(res1, a[i]); rep(i, W) res2 = max(res2, b[i]); vector<int> p, q; rep(i, H) if (a[i] == res1) p.pb(i); rep(i, W) if (b[i] == res2) q.pb(i); if (p.size() * q.size() > m) { cout << res1 + res2 << endl; return 0; } rep(i, p.size()) { rep(j, q.size()) { if (bomb.count({p[i], q[j]})) ans = max(ans, res1 + res2 - 1); else ans = max(ans, res1 + res2); } } cout << ans << endl; }
insert
29
29
29
33
TLE
p02580
C++
Time Limit Exceeded
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define endl "\n" #define JAM(x) cout << #x << " = " << x << "\n" #define II() \ ({ \ int a; \ read(a); \ a; \ }) #define LL() \ ({ \ ll a; \ read(a); \ a; \ }) #define DD() \ ({ \ double a; \ scanf("%lf", &a); \ a; \ }) // Fast Reader template <class T> inline bool read(T &x) { int c = getchar(); int sgn = 1; while (~c && c < '0' || c > '9') { if (c == '-') sgn = -1; c = getchar(); } for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sgn; return ~c; } typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef pair<int, int> PII; typedef vector<PII> VPI; const int INF = 2e9; const int MX = 100005; const int MOD = 1000000007; const double PI = acos(-1.0); vector<int> sieve(100001); long long int power(long long int a, long long int b) { a %= MOD; long long int res = 1; while (b > 0) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } bool isprime(int n) { if (n == 1) return 0; int i; for (i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } void SIEVE() { int i, j; for (i = 0; i <= 100000; i++) sieve[i] = i; for (i = 2; i * i <= 100000; i++) { if (sieve[i] != i) continue; for (j = i * i; j <= 100000; j = j + i) { if (sieve[j] == j) sieve[j] = i; } } } /*_______________________________________________*/ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; int tot; cin >> tot; int ans = 0; vector<int> row(n); int mx = 0, mxr = 0; vector<int> col(m), mxcol(m), mxrow(n); int i, j; map<pair<int, int>, int> bomb; for (i = 0; i < tot; i++) { int x, y; cin >> x >> y; bomb[{x - 1, y - 1}] = -1; row[x - 1]++; col[y - 1]++; mx = max(mx, col[y - 1]); mxr = max(mxr, row[x - 1]); } int k = 0, d = 0; for (i = 0; i < m; i++) { if (col[i] == mx) mxcol[d++] = (i); } for (i = 0; i < n; i++) { if (row[i] == mxr) mxrow[k++] = (i); } if (mxr == m) { cout << m + mx - 1; return 0; } for (i = 0; i < k; i++) { for (j = 0; j < d; j++) { ans = max(ans, row[mxrow[i]] + col[mxcol[j]] + bomb[{mxrow[i], mxcol[j]}]); } if (ans == n + m - 1) break; } cout << ans; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define endl "\n" #define JAM(x) cout << #x << " = " << x << "\n" #define II() \ ({ \ int a; \ read(a); \ a; \ }) #define LL() \ ({ \ ll a; \ read(a); \ a; \ }) #define DD() \ ({ \ double a; \ scanf("%lf", &a); \ a; \ }) // Fast Reader template <class T> inline bool read(T &x) { int c = getchar(); int sgn = 1; while (~c && c < '0' || c > '9') { if (c == '-') sgn = -1; c = getchar(); } for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sgn; return ~c; } typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef pair<int, int> PII; typedef vector<PII> VPI; const int INF = 2e9; const int MX = 100005; const int MOD = 1000000007; const double PI = acos(-1.0); vector<int> sieve(100001); long long int power(long long int a, long long int b) { a %= MOD; long long int res = 1; while (b > 0) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } bool isprime(int n) { if (n == 1) return 0; int i; for (i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } void SIEVE() { int i, j; for (i = 0; i <= 100000; i++) sieve[i] = i; for (i = 2; i * i <= 100000; i++) { if (sieve[i] != i) continue; for (j = i * i; j <= 100000; j = j + i) { if (sieve[j] == j) sieve[j] = i; } } } /*_______________________________________________*/ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; int tot; cin >> tot; int ans = 0; vector<int> row(n); int mx = 0, mxr = 0; vector<int> col(m), mxcol(m), mxrow(n); int i, j; map<pair<int, int>, int> bomb; for (i = 0; i < tot; i++) { int x, y; cin >> x >> y; bomb[{x - 1, y - 1}] = -1; row[x - 1]++; col[y - 1]++; mx = max(mx, col[y - 1]); mxr = max(mxr, row[x - 1]); } int k = 0, d = 0; for (i = 0; i < m; i++) { if (col[i] == mx) mxcol[d++] = (i); } for (i = 0; i < n; i++) { if (row[i] == mxr) mxrow[k++] = (i); } if (mxr == m) { cout << m + mx - 1; return 0; } for (i = 0; i < k; i++) { for (j = 0; j < d; j++) { ans = max(ans, row[mxrow[i]] + col[mxcol[j]] + bomb[{mxrow[i], mxcol[j]}]); } if (ans == mxr + mx) break; } cout << ans; }
replace
134
135
134
135
TLE
p02580
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define maxn 30001 #define LL long long #define inf 10000000000 #define mod 1000000007 #define pi 3.14159265359 using namespace std; int dx[24] = {1, 0, -1, 0, 2, 0, -2, 0, -1, -1, -2, -2, 1, 1, 2, 2, -1, -1, -2, -2, 1, 1, 2, 2}; int dy[24] = {0, 1, 0, -1, 0, 2, 0, -2, -1, -2, -1, -2, -1, -2, -1, -2, 1, 2, 1, 2, 1, 2, 1, 2}; LL n, m, k; int arr[maxn]; int arr2[maxn]; // int visit[maxn][maxn]; // int cache[maxn]; // int c[maxn]; // int g[maxn]; // int dfsnum = 0; // vector<vector<int>>rvi; // vector<vector<int>>scc; // vector<pair<int, int>>ett; // stack<int>st; // bool flg = 1; // LL s, d; // // int findp(int a) { // if (a == c[a])return a; // return c[a] = findp(c[a]); // } // void unionp(int a, int b) { // a = findp(a); // b = findp(b); // // if (g[a] < g[b])swap(a, b); // c[b] = a; // g[a] += g[b]; // g[b] = 1; // // } // LL power(LL x, LL y) { // LL ret = 1; // while (y > 0) { // if (y % 2) { // ret *= x; // ret %= mod; // } // x *= x; // x %= mod; // y /= 2; // } // return ret; // } // void dfs2(int v) { // cache[v] = 1; // scc.back().push_back(v); // for (int nv : rvi[v]) { // if (cache[nv])continue; // dfs2(nv); // } // // } // LL fac(LL n) { // if (n == 1) return 1; // return (n * fac(n - 1) - power(2,n-1) )%mod; // } // int fac2(LL n) { // LL res, i; // if (n == 1)return n; // res = n; // for (int i = n - 1; i > 0; --i) { // res *= i; // res %= mod; // } // return res; // } LL gcd(LL a, LL b) { while (b != 0) { LL r = a % b; a = b; b = r; } return a; } vector<LL> vi; vector<LL> vi2; vector<vector<int>> graph; int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); // int t; cin >> t; cin.ignore(); int t = 1; for (int test_case = 0; test_case < t; ++test_case) { int flg = 1; LL ans1 = 0, ans2 = 0; string ans[2] = {"No", "Yes"}; cin >> n >> m >> k; set<int> s[maxn]; for (int i = 0; i < k; ++i) { LL y, x; cin >> y >> x; arr[y]++; arr2[x]++; s[y].insert(x); } int mx1 = arr[1]; int mx2 = arr2[1]; for (int i = 2; i <= n; ++i) mx1 = mx1 < arr[i] ? arr[i] : mx1; for (int i = 2; i <= m; ++i) mx2 = mx2 < arr2[i] ? arr2[i] : mx2; for (int i = 1; i <= n; ++i) if (arr[i] == mx1) vi.push_back(i); for (int i = 1; i <= m; ++i) if (arr2[i] == mx2) vi2.push_back(i); for (int i = 0; i < vi.size(); ++i) { for (int j = 0; j < vi2.size(); ++j) { if (s[vi[i]].find(vi2[j]) == s[vi[i]].end()) { cout << mx1 + mx2; flg = 0; break; } } if (!flg) break; } if (flg) cout << mx1 + mx2 - 1; cout << '\n'; } return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define maxn 300010 #define LL long long #define inf 10000000000 #define mod 1000000007 #define pi 3.14159265359 using namespace std; int dx[24] = {1, 0, -1, 0, 2, 0, -2, 0, -1, -1, -2, -2, 1, 1, 2, 2, -1, -1, -2, -2, 1, 1, 2, 2}; int dy[24] = {0, 1, 0, -1, 0, 2, 0, -2, -1, -2, -1, -2, -1, -2, -1, -2, 1, 2, 1, 2, 1, 2, 1, 2}; LL n, m, k; int arr[maxn]; int arr2[maxn]; // int visit[maxn][maxn]; // int cache[maxn]; // int c[maxn]; // int g[maxn]; // int dfsnum = 0; // vector<vector<int>>rvi; // vector<vector<int>>scc; // vector<pair<int, int>>ett; // stack<int>st; // bool flg = 1; // LL s, d; // // int findp(int a) { // if (a == c[a])return a; // return c[a] = findp(c[a]); // } // void unionp(int a, int b) { // a = findp(a); // b = findp(b); // // if (g[a] < g[b])swap(a, b); // c[b] = a; // g[a] += g[b]; // g[b] = 1; // // } // LL power(LL x, LL y) { // LL ret = 1; // while (y > 0) { // if (y % 2) { // ret *= x; // ret %= mod; // } // x *= x; // x %= mod; // y /= 2; // } // return ret; // } // void dfs2(int v) { // cache[v] = 1; // scc.back().push_back(v); // for (int nv : rvi[v]) { // if (cache[nv])continue; // dfs2(nv); // } // // } // LL fac(LL n) { // if (n == 1) return 1; // return (n * fac(n - 1) - power(2,n-1) )%mod; // } // int fac2(LL n) { // LL res, i; // if (n == 1)return n; // res = n; // for (int i = n - 1; i > 0; --i) { // res *= i; // res %= mod; // } // return res; // } LL gcd(LL a, LL b) { while (b != 0) { LL r = a % b; a = b; b = r; } return a; } vector<LL> vi; vector<LL> vi2; vector<vector<int>> graph; int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); // int t; cin >> t; cin.ignore(); int t = 1; for (int test_case = 0; test_case < t; ++test_case) { int flg = 1; LL ans1 = 0, ans2 = 0; string ans[2] = {"No", "Yes"}; cin >> n >> m >> k; set<int> s[maxn]; for (int i = 0; i < k; ++i) { LL y, x; cin >> y >> x; arr[y]++; arr2[x]++; s[y].insert(x); } int mx1 = arr[1]; int mx2 = arr2[1]; for (int i = 2; i <= n; ++i) mx1 = mx1 < arr[i] ? arr[i] : mx1; for (int i = 2; i <= m; ++i) mx2 = mx2 < arr2[i] ? arr2[i] : mx2; for (int i = 1; i <= n; ++i) if (arr[i] == mx1) vi.push_back(i); for (int i = 1; i <= m; ++i) if (arr2[i] == mx2) vi2.push_back(i); for (int i = 0; i < vi.size(); ++i) { for (int j = 0; j < vi2.size(); ++j) { if (s[vi[i]].find(vi2[j]) == s[vi[i]].end()) { cout << mx1 + mx2; flg = 0; break; } } if (!flg) break; } if (flg) cout << mx1 + mx2 - 1; cout << '\n'; } return 0; }
replace
11
12
11
12
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define inf 1e15 #define N 100005 int row[N]; int col[N]; vector<int> rowv, colv; set<pair<int, int>> bomb; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin>>t; while (t--) { int n, m, k; cin >> n >> m >> k; int rowh = 0, colh = 0; for (int i = 0; i < k; i++) { int x, y; cin >> x >> y; x--; y--; bomb.insert({x, y}); row[x]++; col[y]++; rowh = max(rowh, row[x]); colh = max(colh, col[y]); } for (int i = 0; i < n; i++) { if (row[i] == rowh) { rowv.push_back(i); } } for (int i = 0; i < m; i++) { if (col[i] == colh) { colv.push_back(i); } } ll ans = rowh + colh - 1; for (auto i : rowv) { for (auto j : colv) { if (bomb.find({i, j}) == bomb.end()) { ans++; goto end; } } } end: cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define inf 1e15 #define N 300005 int row[N]; int col[N]; vector<int> rowv, colv; set<pair<int, int>> bomb; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin>>t; while (t--) { int n, m, k; cin >> n >> m >> k; int rowh = 0, colh = 0; for (int i = 0; i < k; i++) { int x, y; cin >> x >> y; x--; y--; bomb.insert({x, y}); row[x]++; col[y]++; rowh = max(rowh, row[x]); colh = max(colh, col[y]); } for (int i = 0; i < n; i++) { if (row[i] == rowh) { rowv.push_back(i); } } for (int i = 0; i < m; i++) { if (col[i] == colh) { colv.push_back(i); } } ll ans = rowh + colh - 1; for (auto i : rowv) { for (auto j : colv) { if (bomb.find({i, j}) == bomb.end()) { ans++; goto end; } } } end: cout << ans << "\n"; } return 0; }
replace
8
9
8
9
0
p02580
C++
Time Limit Exceeded
#pragma region header #include <bits/stdc++.h> #define int long long #define all(a) begin(a), end(a) #define rall(a) rbegin(a), rend(a) #define mp make_pair #define rep1(i, n) for (decltype(+n) i = 0; i < (n); i++) #define rrep1(i, n) for (auto i = n - 1; i > static_cast<decltype(i)>(-1); i--) #define rep2(i, a, b) for (auto i = (a); i < (b); i++) #define rrep2(i, a, b) for (auto i = b - 1; i >= a; i--) #define GET_MACRO(_1, _2, _3, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__) #define rrep(...) GET_MACRO(__VA_ARGS__, rrep2, rrep1)(__VA_ARGS__) #define each(i, a) for (auto &&i : (a)) using namespace std; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; using vvs = vector<vs>; using vd = vector<ld>; using vvd = vector<vd>; using vb = vector<bool>; using vvb = vector<vb>; using pii = pair<int, int>; using vp = vector<pii>; using vvp = vector<vp>; using mii = map<int, int>; using vm = vector<mii>; using vvm = vector<vm>; template <class T, class U> using umap = unordered_map<T, U>; using umii = umap<int, int>; using seti = set<int>; template <class T> using uset = unordered_set<T>; using useti = uset<int>; template <class T> using less_queue = priority_queue<T>; template <class T> using greater_queue = priority_queue<T, vector<T>, greater<T>>; using int128 = __int128_t; ostream &operator<<(ostream &dest, int128 value) { ostream::sentry s(dest); if (s) { int128 tmp = value < 0 ? -value : value; char buffer[128]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(ios_base::badbit); } } return dest; } const int INF = 1e18; const ld EPS = 1e-10; template <class T> void SORT(T &a) { stable_sort(all(a)); } template <class T> void RSORT(T &a) { stable_sort(rall(a)); } template <class T> void rev(T &a) { reverse(rall(a)); } template <class T> void uniq(T &a) { a.erase(unique(all(a)), end(a)); } template <class T> auto min_of(T a) { return *min_element(all(a)); } template <class T> auto max_of(T a) { return *max_element(all(a)); } template <class T> int sum_of(T a) { return accumulate(all(a), 0ll); } template <class T, class U> auto sum_of(T a, U init) { return accumulate(all(a), init); } template <class T, class U> int count_of(T a, U i) { return count(all(a), i); } template <class T, class U> bool has(T a, U i) { return find(all(a), i) != end(a); } template <class T> int sz(T a) { return a.size(); }; template <class T> void COUT(T x) { cout << x << endl; } template <class T, class U> void COUT(T x, U y) { cout << x << ' ' << y << endl; } template <class T, class U, class V> void COUT(T x, U y, V z) { cout << x << ' ' << y << ' ' << z << endl; } template <class T> void CSP(T x) { cout << x << ' '; } template <class T> void CVEC(T v) { int c = v.size() - 1; for (int i = 0; i < c; i++) cout << v[i] << ' '; if (c > -1) cout << v[c]; cout << endl; } template <class T> bool amin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <class T> bool amax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } constexpr int lshift(int x) noexcept { return 1ll << x; } constexpr int popcount(unsigned int x) noexcept { return __builtin_popcountll(x); } constexpr int least1(unsigned int x) noexcept { return __builtin_ffsll(x); } constexpr int ceil_div(int x, int y) noexcept { return (x + y - 1) / y; } #pragma endregion header // no MOD void solve(int H, int W, int M, vi h, vi w) { mii hm, wm; each(x, h) hm[x]++; each(x, w) wm[x]++; seti hs, ws; int hmax = 0, wmax = 0; each(p, hm) amax(hmax, p.second); each(p, wm) amax(wmax, p.second); each(p, hm) if (p.second == hmax) hs.insert(p.first); each(p, wm) if (p.second == wmax) ws.insert(p.first); int ans = hmax + wmax; int cnt = 0; rep(i, M) if (has(hs, h[i]) && has(ws, w[i])) cnt++; if (cnt == sz(hs) * sz(ws)) ans--; COUT(ans); } #pragma region main signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(15); int H; cin >> H; int W; cin >> W; int M; cin >> M; vi h(M); vi w(M); for (int i = 0; i < M; i++) { cin >> h[i]; cin >> w[i]; } solve(H, W, M, move(h), move(w)); } #pragma endregion main
#pragma region header #include <bits/stdc++.h> #define int long long #define all(a) begin(a), end(a) #define rall(a) rbegin(a), rend(a) #define mp make_pair #define rep1(i, n) for (decltype(+n) i = 0; i < (n); i++) #define rrep1(i, n) for (auto i = n - 1; i > static_cast<decltype(i)>(-1); i--) #define rep2(i, a, b) for (auto i = (a); i < (b); i++) #define rrep2(i, a, b) for (auto i = b - 1; i >= a; i--) #define GET_MACRO(_1, _2, _3, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__) #define rrep(...) GET_MACRO(__VA_ARGS__, rrep2, rrep1)(__VA_ARGS__) #define each(i, a) for (auto &&i : (a)) using namespace std; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; using vvs = vector<vs>; using vd = vector<ld>; using vvd = vector<vd>; using vb = vector<bool>; using vvb = vector<vb>; using pii = pair<int, int>; using vp = vector<pii>; using vvp = vector<vp>; using mii = map<int, int>; using vm = vector<mii>; using vvm = vector<vm>; template <class T, class U> using umap = unordered_map<T, U>; using umii = umap<int, int>; using seti = set<int>; template <class T> using uset = unordered_set<T>; using useti = uset<int>; template <class T> using less_queue = priority_queue<T>; template <class T> using greater_queue = priority_queue<T, vector<T>, greater<T>>; using int128 = __int128_t; ostream &operator<<(ostream &dest, int128 value) { ostream::sentry s(dest); if (s) { int128 tmp = value < 0 ? -value : value; char buffer[128]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(ios_base::badbit); } } return dest; } const int INF = 1e18; const ld EPS = 1e-10; template <class T> void SORT(T &a) { stable_sort(all(a)); } template <class T> void RSORT(T &a) { stable_sort(rall(a)); } template <class T> void rev(T &a) { reverse(rall(a)); } template <class T> void uniq(T &a) { a.erase(unique(all(a)), end(a)); } template <class T> auto min_of(T a) { return *min_element(all(a)); } template <class T> auto max_of(T a) { return *max_element(all(a)); } template <class T> int sum_of(T a) { return accumulate(all(a), 0ll); } template <class T, class U> auto sum_of(T a, U init) { return accumulate(all(a), init); } template <class T, class U> int count_of(T a, U i) { return count(all(a), i); } template <class T, class U> bool has(T a, U i) { return find(all(a), i) != end(a); } template <class T> int sz(T a) { return a.size(); }; template <class T> void COUT(T x) { cout << x << endl; } template <class T, class U> void COUT(T x, U y) { cout << x << ' ' << y << endl; } template <class T, class U, class V> void COUT(T x, U y, V z) { cout << x << ' ' << y << ' ' << z << endl; } template <class T> void CSP(T x) { cout << x << ' '; } template <class T> void CVEC(T v) { int c = v.size() - 1; for (int i = 0; i < c; i++) cout << v[i] << ' '; if (c > -1) cout << v[c]; cout << endl; } template <class T> bool amin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <class T> bool amax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } constexpr int lshift(int x) noexcept { return 1ll << x; } constexpr int popcount(unsigned int x) noexcept { return __builtin_popcountll(x); } constexpr int least1(unsigned int x) noexcept { return __builtin_ffsll(x); } constexpr int ceil_div(int x, int y) noexcept { return (x + y - 1) / y; } #pragma endregion header // no MOD void solve(int H, int W, int M, vi h, vi w) { mii hm, wm; each(x, h) hm[x]++; each(x, w) wm[x]++; seti hs, ws; int hmax = 0, wmax = 0; each(p, hm) amax(hmax, p.second); each(p, wm) amax(wmax, p.second); each(p, hm) if (p.second == hmax) hs.insert(p.first); each(p, wm) if (p.second == wmax) ws.insert(p.first); int ans = hmax + wmax; int cnt = 0; rep(i, M) if (hs.find(h[i]) != hs.end() && ws.find(w[i]) != ws.end()) cnt++; if (cnt == sz(hs) * sz(ws)) ans--; COUT(ans); } #pragma region main signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(15); int H; cin >> H; int W; cin >> W; int M; cin >> M; vi h(M); vi w(M); for (int i = 0; i < M; i++) { cin >> h[i]; cin >> w[i]; } solve(H, W, M, move(h), move(w)); } #pragma endregion main
replace
138
139
138
139
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = int; using ull = uint; ull hashfunc(int64_t v) { return (ull)(v % 1000033LL); } int64_t makekey(ll h, ll w) { return 1000037LL * h + w; } const uint8_t HASH_EMPTY = 0; const uint8_t HASH_EXIST = 1; const uint8_t HASH_DELETED = 2; template <class K, class V> struct bunordered_map_elem { uint8_t exist; // 0:存在しない, 1:存在する, 2:削除後 K key; V value; }; template <class K, class V> class bunordered_map { public: bunordered_map_elem<K, V> *table; ull cap; ull length; bunordered_map() { cap = 97; table = new bunordered_map_elem<K, V>[cap]; for (ull i = 0; i < cap; i++) { table[i].exist = HASH_EMPTY; } length = 0; } bunordered_map(ull init_cap) { if (init_cap == 0) { throw exception(); } cap = init_cap; table = new bunordered_map_elem<K, V>[cap]; for (ull i = 0; i < cap; i++) { table[i].exist = HASH_EMPTY; } length = 0; } ~bunordered_map() { delete table; } void insert(K key, V value) { ull idx = hashfunc(key); while (true) { auto elem = table[idx]; if (elem.exist == HASH_EMPTY || elem.exist == HASH_DELETED) { // 新規登録 table[idx] = bunordered_map_elem<K, V>{ exist : HASH_EXIST, key : key, value : value }; length++; break; } else if (elem.exist == 1 && elem.key == key) { // 上書き table[idx] = bunordered_map_elem<K, V>{ exist : HASH_EXIST, key : key, value : value }; break; } else { idx++; if (idx >= cap) { idx = 0; } } } } ull get_index(K key) { ull idx = hashfunc(key); while (true) { auto elem = table[idx]; if (elem.exist == HASH_EMPTY) { return cap + 1; } else if (elem.exist == HASH_EXIST && elem.key == key) { return idx; } else { idx++; if (idx >= cap) { idx = 0; } } } } uint8_t count(K key) { if (get_index(key) == cap + 1) { return 0; } else { return 1; } } }; ll maxlist(vector<ll> &maxindices, vector<ll> &counts) { ll maxval = -1; for (ll i = 0; i < (ll)counts.size(); i++) { if (maxval == counts[i]) { maxindices.push_back(i); } else if (maxval < counts[i]) { maxval = counts[i]; maxindices.clear(); maxindices.push_back(i); } } return maxval; } int main() { ll H, W, M; cin >> H >> W >> M; vector<ll> hcount(H, 0); vector<ll> wcount(W, 0); bunordered_map<int64_t, bool> exist(5000011); for (ll i = 0; i < M; i++) { ll h, w; cin >> h >> w; h--; w--; hcount[h]++; wcount[w]++; exist.insert(makekey(h, w), true); } vector<ll> max_hi; ll max_h = maxlist(max_hi, hcount); vector<ll> max_wi; ll max_w = maxlist(max_wi, wcount); for (auto hi : max_hi) { for (auto wi : max_wi) { if (!exist.count(makekey(hi, wi))) { cout << max_h + max_w << endl; return 0; } } } cout << max_h + max_w - 1 << endl; }
#include <bits/stdc++.h> using namespace std; using ll = int; using ull = uint; ull hashfunc(int64_t v) { return (ull)(v % 1000033LL); } int64_t makekey(ll h, ll w) { return 1000037LL * h + 1000721LL * w + (h * w); } const uint8_t HASH_EMPTY = 0; const uint8_t HASH_EXIST = 1; const uint8_t HASH_DELETED = 2; template <class K, class V> struct bunordered_map_elem { uint8_t exist; // 0:存在しない, 1:存在する, 2:削除後 K key; V value; }; template <class K, class V> class bunordered_map { public: bunordered_map_elem<K, V> *table; ull cap; ull length; bunordered_map() { cap = 97; table = new bunordered_map_elem<K, V>[cap]; for (ull i = 0; i < cap; i++) { table[i].exist = HASH_EMPTY; } length = 0; } bunordered_map(ull init_cap) { if (init_cap == 0) { throw exception(); } cap = init_cap; table = new bunordered_map_elem<K, V>[cap]; for (ull i = 0; i < cap; i++) { table[i].exist = HASH_EMPTY; } length = 0; } ~bunordered_map() { delete table; } void insert(K key, V value) { ull idx = hashfunc(key); while (true) { auto elem = table[idx]; if (elem.exist == HASH_EMPTY || elem.exist == HASH_DELETED) { // 新規登録 table[idx] = bunordered_map_elem<K, V>{ exist : HASH_EXIST, key : key, value : value }; length++; break; } else if (elem.exist == 1 && elem.key == key) { // 上書き table[idx] = bunordered_map_elem<K, V>{ exist : HASH_EXIST, key : key, value : value }; break; } else { idx++; if (idx >= cap) { idx = 0; } } } } ull get_index(K key) { ull idx = hashfunc(key); while (true) { auto elem = table[idx]; if (elem.exist == HASH_EMPTY) { return cap + 1; } else if (elem.exist == HASH_EXIST && elem.key == key) { return idx; } else { idx++; if (idx >= cap) { idx = 0; } } } } uint8_t count(K key) { if (get_index(key) == cap + 1) { return 0; } else { return 1; } } }; ll maxlist(vector<ll> &maxindices, vector<ll> &counts) { ll maxval = -1; for (ll i = 0; i < (ll)counts.size(); i++) { if (maxval == counts[i]) { maxindices.push_back(i); } else if (maxval < counts[i]) { maxval = counts[i]; maxindices.clear(); maxindices.push_back(i); } } return maxval; } int main() { ll H, W, M; cin >> H >> W >> M; vector<ll> hcount(H, 0); vector<ll> wcount(W, 0); bunordered_map<int64_t, bool> exist(5000011); for (ll i = 0; i < M; i++) { ll h, w; cin >> h >> w; h--; w--; hcount[h]++; wcount[w]++; exist.insert(makekey(h, w), true); } vector<ll> max_hi; ll max_h = maxlist(max_hi, hcount); vector<ll> max_wi; ll max_w = maxlist(max_wi, wcount); for (auto hi : max_hi) { for (auto wi : max_wi) { if (!exist.count(makekey(hi, wi))) { cout << max_h + max_w << endl; return 0; } } } cout << max_h + max_w - 1 << endl; }
replace
7
8
7
8
TLE