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
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll MOD = 1000000007; const ld PI = acos(-1); const ld EPS = 0.0000000001; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repd(i, n) for (ll i = n - 1; 0 <= i; i--) #define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++) #define FORD(i, a, b) for (ll i = b - 1; (ll)(a) <= i; i--) #define ALL(x) x.begin(), x.end() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; string YES[2] = {"NO", "YES"}; string yes[2] = {"No", "Yes"}; int main() { ll h, w, m; cin >> h >> w >> m; vector<ll> hc(h, 0), wc(w, 0); map<pair<ll, ll>, ll> mp; rep(i, m) { ll x, y; cin >> x >> y; x--, y--; hc[x] += 1; wc[y] += 1; mp[{x, y}] = 1; } ll hm = MAX(hc), wm = MAX(wc); set<ll> ht, wt; rep(i, h) if (hm == hc[i]) ht.insert(i); rep(i, w) if (wm == wc[i]) wt.insert(i); ll res = hm + wm - 1; for (auto x : ht) { for (auto y : wt) { if (mp[{x, y}]) continue; res = hm + wm; } } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll MOD = 1000000007; const ld PI = acos(-1); const ld EPS = 0.0000000001; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repd(i, n) for (ll i = n - 1; 0 <= i; i--) #define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++) #define FORD(i, a, b) for (ll i = b - 1; (ll)(a) <= i; i--) #define ALL(x) x.begin(), x.end() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; string YES[2] = {"NO", "YES"}; string yes[2] = {"No", "Yes"}; int main() { ll h, w, m; cin >> h >> w >> m; vector<ll> hc(h, 0), wc(w, 0); map<pair<ll, ll>, ll> mp; rep(i, m) { ll x, y; cin >> x >> y; x--, y--; hc[x] += 1; wc[y] += 1; mp[{x, y}] = 1; } ll hm = MAX(hc), wm = MAX(wc); set<ll> ht, wt; rep(i, h) if (hm == hc[i]) ht.insert(i); rep(i, w) if (wm == wc[i]) wt.insert(i); ll res = hm + wm - 1; for (auto x : ht) { for (auto y : wt) { if (mp[{x, y}]) continue; cout << res + 1 << endl; return 0; } } cout << res << endl; }
replace
43
44
43
45
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { using coord = pair<int, int>; int H, W, M; cin >> H >> W >> M; set<coord> targets; int x, y; for (int i = 0; i < M; i++) { cin >> x >> y; x--; y--; // 1-indexed -> 0-indexed targets.insert(make_pair(x, y)); } vector<int> Nrow(H); vector<int> Ncol(W); for (auto [x, y] : targets) { Nrow.at(x)++; Ncol.at(y)++; } vector<int> argmax_row; int cummax_row = -1; for (int h = 0; h < H; h++) { if (cummax_row > Nrow.at(h)) { continue; } else if (cummax_row < Nrow.at(h)) { cummax_row = Nrow.at(h); argmax_row.clear(); argmax_row.emplace_back(h); } else { argmax_row.emplace_back(h); } } vector<int> argmax_col; int cummax_col = -1; for (int w = 0; w < W; w++) { if (cummax_col > Ncol.at(w)) { continue; } else if (cummax_col < Ncol.at(w)) { cummax_col = Ncol.at(w); argmax_col.clear(); argmax_col.emplace_back(w); } else { argmax_col.emplace_back(w); } } int Ncross = (int)argmax_row.size() * argmax_col.size(); if (Ncross > M) { int ans = cummax_row + cummax_col; cout << ans << endl; } else { vector<bool> filled(Ncross); for (size_t i = 0; i < argmax_row.size(); i++) { for (size_t j = 0; j < argmax_col.size(); j++) { size_t id = i * argmax_col.size() + j; filled.at(id) = targets.count(make_pair(argmax_row.at(i), argmax_col.at(j))); } } bool vacant_exist = false; for (auto b : filled) { vacant_exist |= !b; } int ans = vacant_exist ? cummax_row + cummax_col : cummax_row + cummax_col - 1; cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { using coord = pair<int, int>; int H, W, M; cin >> H >> W >> M; set<coord> targets; int x, y; for (int i = 0; i < M; i++) { cin >> x >> y; x--; y--; // 1-indexed -> 0-indexed targets.insert(make_pair(x, y)); } vector<int> Nrow(H); vector<int> Ncol(W); for (auto [x, y] : targets) { Nrow.at(x)++; Ncol.at(y)++; } vector<int> argmax_row; int cummax_row = -1; for (int h = 0; h < H; h++) { if (cummax_row > Nrow.at(h)) { continue; } else if (cummax_row < Nrow.at(h)) { cummax_row = Nrow.at(h); argmax_row.clear(); argmax_row.emplace_back(h); } else { argmax_row.emplace_back(h); } } vector<int> argmax_col; int cummax_col = -1; for (int w = 0; w < W; w++) { if (cummax_col > Ncol.at(w)) { continue; } else if (cummax_col < Ncol.at(w)) { cummax_col = Ncol.at(w); argmax_col.clear(); argmax_col.emplace_back(w); } else { argmax_col.emplace_back(w); } } int64_t Ncross = (int64_t)argmax_row.size() * argmax_col.size(); if (Ncross > M) { int ans = cummax_row + cummax_col; cout << ans << endl; } else { vector<bool> filled(Ncross); for (size_t i = 0; i < argmax_row.size(); i++) { for (size_t j = 0; j < argmax_col.size(); j++) { size_t id = i * argmax_col.size() + j; filled.at(id) = targets.count(make_pair(argmax_row.at(i), argmax_col.at(j))); } } bool vacant_exist = false; for (auto b : filled) { vacant_exist |= !b; } int ans = vacant_exist ? cummax_row + cummax_col : cummax_row + cummax_col - 1; cout << ans << endl; } }
replace
52
53
52
53
0
p02580
C++
Time Limit Exceeded
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <cmath> #include <complex> #include <cstdint> #include <cstdlib> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <type_traits> #include <unordered_map> #include <utility> #include <vector> /* template start */ using i64 = std::int_fast64_t; using u64 = std::uint_fast64_t; #define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++) #define all(i) i.begin(), i.end() #ifdef LOCAL #define debug(...) \ std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out() { std::cerr << std::endl; } template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) { std::cerr << " " << h; if (sizeof...(t) > 0) std::cout << " :"; debug_out(t...); } template <typename T1, typename T2> std::ostream &operator<<(std::ostream &os, std::pair<T1, T2> pa) { return os << pa.first << " " << pa.second; } template <typename T> std::ostream &operator<<(std::ostream &os, std::vector<T> vec) { for (std::size_t i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template <typename Num> constexpr Num mypow(Num a, u64 b, Num id = 1) { if (b == 0) return id; Num x = id; while (b > 0) { if (b & 1) x *= a; a *= a; b >>= 1; } return x; } /* template end */ int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); i64 h, w, m; std::cin >> h >> w >> m; using P = std::pair<i64, i64>; std::set<P> target; std::map<i64, i64> row, col; rep(i, 0, m) { i64 th, tw; std::cin >> th >> tw; row[th]++; col[tw]++; target.emplace(th, tw); } i64 ans = 0; std::vector<i64> row_vec; i64 row_max = 0; { for (const auto &e : row) { chmax(row_max, e.second); } for (const auto &e : row) { if (e.second == row_max) row_vec.emplace_back(e.first); } } std::vector<i64> col_vec; i64 col_max = 0; { for (const auto &e : col) { chmax(col_max, e.second); } for (const auto &e : col) { if (e.second == col_max) col_vec.emplace_back(e.first); } } for (const auto &r : row_vec) { for (const auto &c : col_vec) { i64 val = row_max + col_max; if (target.find(P(r, c)) != target.end()) val--; chmax(ans, val); } } std::cout << ans << "\n"; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <cmath> #include <complex> #include <cstdint> #include <cstdlib> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <type_traits> #include <unordered_map> #include <utility> #include <vector> /* template start */ using i64 = std::int_fast64_t; using u64 = std::uint_fast64_t; #define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++) #define all(i) i.begin(), i.end() #ifdef LOCAL #define debug(...) \ std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out() { std::cerr << std::endl; } template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) { std::cerr << " " << h; if (sizeof...(t) > 0) std::cout << " :"; debug_out(t...); } template <typename T1, typename T2> std::ostream &operator<<(std::ostream &os, std::pair<T1, T2> pa) { return os << pa.first << " " << pa.second; } template <typename T> std::ostream &operator<<(std::ostream &os, std::vector<T> vec) { for (std::size_t i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template <typename Num> constexpr Num mypow(Num a, u64 b, Num id = 1) { if (b == 0) return id; Num x = id; while (b > 0) { if (b & 1) x *= a; a *= a; b >>= 1; } return x; } /* template end */ int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); i64 h, w, m; std::cin >> h >> w >> m; using P = std::pair<i64, i64>; std::set<P> target; std::map<i64, i64> row, col; rep(i, 0, m) { i64 th, tw; std::cin >> th >> tw; row[th]++; col[tw]++; target.emplace(th, tw); } i64 ans = 0; std::vector<i64> row_vec; i64 row_max = 0; { for (const auto &e : row) { chmax(row_max, e.second); } for (const auto &e : row) { if (e.second == row_max) row_vec.emplace_back(e.first); } } std::vector<i64> col_vec; i64 col_max = 0; { for (const auto &e : col) { chmax(col_max, e.second); } for (const auto &e : col) { if (e.second == col_max) col_vec.emplace_back(e.first); } } if (row_vec.size() * col_vec.size() > m) { std::cout << row_max + col_max << "\n"; return 0; } for (const auto &r : row_vec) { for (const auto &c : col_vec) { i64 val = row_max + col_max; if (target.find(P(r, c)) != target.end()) val--; chmax(ans, val); } } std::cout << ans << "\n"; return 0; }
insert
140
140
140
145
TLE
p02580
C++
Time Limit Exceeded
// AtCoder template #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < n; ++i) int main() { cin.tie(0); ios::sync_with_stdio(false); map<pair<int, int>, int> mp; int h, w, m; cin >> h >> w >> m; vector<pair<int, int>> row(h), col(w); rep(i, h) row[i] = make_pair(0, i); rep(j, w) col[j] = make_pair(0, j); int ht, wt; rep(i, m) { cin >> ht >> wt; --ht; --wt; mp[make_pair(ht, wt)] = 1; row[ht].first++; col[wt].first++; } sort(row.begin(), row.end(), greater<pair<int, int>>()); sort(col.begin(), col.end(), greater<pair<int, int>>()); int rt = row[0].first, ct = col[0].first, cnt = 0; int ans = rt + ct - mp[make_pair(row[0].second, col[0].second)]; for (int i = 0; row[i].first == rt && cnt <= m + 1; ++i) { for (int j = 0; col[j].first == ct && cnt <= m + 1; ++j) { ht = row[i].second, wt = col[j].second; int tmp = row[i].first + col[j].first - mp[make_pair(ht, wt)]; if (ans < tmp) { ans = tmp; break; } if (mp[make_pair(ht, wt)] == 1) cnt++; } } cout << ans << endl; }
// AtCoder template #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < n; ++i) int main() { cin.tie(0); ios::sync_with_stdio(false); map<pair<int, int>, int> mp; int h, w, m; cin >> h >> w >> m; vector<pair<int, int>> row(h), col(w); rep(i, h) row[i] = make_pair(0, i); rep(j, w) col[j] = make_pair(0, j); int ht, wt; rep(i, m) { cin >> ht >> wt; --ht; --wt; mp[make_pair(ht, wt)] = 1; row[ht].first++; col[wt].first++; } sort(row.begin(), row.end(), greater<pair<int, int>>()); sort(col.begin(), col.end(), greater<pair<int, int>>()); int rt = row[0].first, ct = col[0].first, cnt = 0; int ans = rt + ct - mp[make_pair(row[0].second, col[0].second)]; for (int i = 0; row[i].first == rt && cnt <= m + 1; ++i) { for (int j = 0; col[j].first == ct && cnt <= m + 1; ++j) { ht = row[i].second, wt = col[j].second; int tmp = row[i].first + col[j].first - mp[make_pair(ht, wt)]; if (ans < tmp) { ans = tmp; break; } cnt++; } } cout << ans << endl; }
replace
41
43
41
42
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> using namespace std; using namespace __gnu_pbds; typedef long long ll; #define int long long typedef unsigned long long lu; typedef vector<ll> v; typedef vector<vector<ll>> vv; typedef vector<string> vs; typedef vector<pair<ll, ll>> vpr; typedef vector<bool> vb; typedef vector<double> vd; typedef long double ld; #define f(i, n) for (ll i = 0; i < n; i++) #define ff(i, n) for (ll i = 1; i <= n; i++) #define pb push_back #define mp make_pair #define endl "\n" #define fi first #define se second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define amax(x, y) \ if (y > x) \ x = y; #define amin(x, y) \ if (y < x) \ x = y; #define bg(x) x.begin() #define sz(x) (ll) x.size() #define in(x, n) \ for (ll i = 0; i < n; i++) \ cin >> x[i] #define out(x, n) \ for (ll i = 0; i < n; i++) \ cout << x[i] << " " #define mxt(a) *(max_element(a.begin(), a.end())) #define mnt(a) *(min_element(a.begin(),a.end()) #define tc \ ll t; \ cin >> t; \ while (t--) typedef pair<ll, ll> pi; #define yes cout << "YES\n"; #define no cout << "NO\n"; #define yesno(f) \ if (f) \ yes else no const v dx = {1, -1, 0, 0}; const v dy = {0, 0, 1, -1}; const ld PI = 2 * acos(0.0); ll cel(ll x1, ll y1) { if ((x1 % y1) == 0) return x1 / y1; else return x1 / y1 + 1; } ll power(ll a, ll b, ll m) { if (b == 0) return 1; ll d = power(a, b / 2, m); d = (d * d) % m; if (b & 1) d = (d * a) % m; return d; } const ll mod = 1e9 + 7; int MOD(int a) { if (a < 0) a += mod; if (a >= mod) a %= mod; return a; } // set_name.find_by_order(k) It returns to an iterator to the kth element // (counting from zero) in the set in O(logn) time set_name.order_of_key(k) It // returns to the number of items that are strictly smaller than our item k in // O(logn) time. /*string operations : str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1] str.substr (x) : returns a substring str[x],... end of string str.find(qtr) : returns the first occurenece of qtr in str */ int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int h, w, m; cin >> h >> w >> m; v row(h, 0), col(w, 0); vv coll(w); f(i, m) { int h1, w1; cin >> h1 >> w1; h1--; w1--; row[h1]++; col[w1]++; coll[w1].pb(h1); } set<pi> rows; for (int i = 0; i < h; i++) { rows.insert({row[i], i}); } int ans = 0; for (int i = 0; i < w; i++) { int ans1 = 0; for (auto it : coll[i]) { ans1 = max(ans1, col[i] + row[it] - 1); rows.erase({row[it], it}); } auto it = rows.end(); it--; ans1 = max(ans1, col[i] + it->first); for (auto it : coll[i]) rows.insert({row[it], it}); ans = max(ans, ans1); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> using namespace std; using namespace __gnu_pbds; typedef long long ll; #define int long long typedef unsigned long long lu; typedef vector<ll> v; typedef vector<vector<ll>> vv; typedef vector<string> vs; typedef vector<pair<ll, ll>> vpr; typedef vector<bool> vb; typedef vector<double> vd; typedef long double ld; #define f(i, n) for (ll i = 0; i < n; i++) #define ff(i, n) for (ll i = 1; i <= n; i++) #define pb push_back #define mp make_pair #define endl "\n" #define fi first #define se second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define amax(x, y) \ if (y > x) \ x = y; #define amin(x, y) \ if (y < x) \ x = y; #define bg(x) x.begin() #define sz(x) (ll) x.size() #define in(x, n) \ for (ll i = 0; i < n; i++) \ cin >> x[i] #define out(x, n) \ for (ll i = 0; i < n; i++) \ cout << x[i] << " " #define mxt(a) *(max_element(a.begin(), a.end())) #define mnt(a) *(min_element(a.begin(),a.end()) #define tc \ ll t; \ cin >> t; \ while (t--) typedef pair<ll, ll> pi; #define yes cout << "YES\n"; #define no cout << "NO\n"; #define yesno(f) \ if (f) \ yes else no const v dx = {1, -1, 0, 0}; const v dy = {0, 0, 1, -1}; const ld PI = 2 * acos(0.0); ll cel(ll x1, ll y1) { if ((x1 % y1) == 0) return x1 / y1; else return x1 / y1 + 1; } ll power(ll a, ll b, ll m) { if (b == 0) return 1; ll d = power(a, b / 2, m); d = (d * d) % m; if (b & 1) d = (d * a) % m; return d; } const ll mod = 1e9 + 7; int MOD(int a) { if (a < 0) a += mod; if (a >= mod) a %= mod; return a; } // set_name.find_by_order(k) It returns to an iterator to the kth element // (counting from zero) in the set in O(logn) time set_name.order_of_key(k) It // returns to the number of items that are strictly smaller than our item k in // O(logn) time. /*string operations : str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1] str.substr (x) : returns a substring str[x],... end of string str.find(qtr) : returns the first occurenece of qtr in str */ int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int h, w, m; cin >> h >> w >> m; v row(h, 0), col(w, 0); vv coll(w); f(i, m) { int h1, w1; cin >> h1 >> w1; h1--; w1--; row[h1]++; col[w1]++; coll[w1].pb(h1); } set<pi> rows; for (int i = 0; i < h; i++) { rows.insert({row[i], i}); } int ans = 0; for (int i = 0; i < w; i++) { int ans1 = 0; for (auto it : coll[i]) { ans1 = max(ans1, col[i] + row[it] - 1); rows.erase({row[it], it}); } if (!rows.empty()) { auto it = rows.end(); it--; ans1 = max(ans1, col[i] + it->first); } for (auto it : coll[i]) rows.insert({row[it], it}); ans = max(ans, ans1); } cout << ans << endl; return 0; }
replace
116
119
116
121
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; ll H, W, M; ll Y[1005]; ll X[1005]; int main() { cin >> H >> W >> M; vector<P> A(M); for (ll i = 0; i < M; i++) { ll y, x; cin >> y >> x; P p(y, x); A[i] = p; Y[y]++; X[x]++; } ll ymax = 0; ll xmax = 0; for (ll i = 1; i <= H; i++) if (ymax < Y[i]) ymax = Y[i]; for (ll i = 1; i <= W; i++) if (xmax < X[i]) xmax = X[i]; set<ll> Symax; set<ll> Sxmax; for (ll i = 1; i <= H; i++) if (Y[i] == ymax) Symax.insert(i); for (ll i = 1; i <= W; i++) if (X[i] == xmax) Sxmax.insert(i); ll ans = ymax + xmax; ll sum = 0; for (ll i = 0; i < M; i++) { ll y = A[i].first; ll x = A[i].second; if (Symax.count(y) && Sxmax.count(x)) sum++; } ll a = Symax.size(); ll b = Sxmax.size(); if (sum == a * b) ans--; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; ll H, W, M; ll Y[300005]; ll X[300005]; int main() { cin >> H >> W >> M; vector<P> A(M); for (ll i = 0; i < M; i++) { ll y, x; cin >> y >> x; P p(y, x); A[i] = p; Y[y]++; X[x]++; } ll ymax = 0; ll xmax = 0; for (ll i = 1; i <= H; i++) if (ymax < Y[i]) ymax = Y[i]; for (ll i = 1; i <= W; i++) if (xmax < X[i]) xmax = X[i]; set<ll> Symax; set<ll> Sxmax; for (ll i = 1; i <= H; i++) if (Y[i] == ymax) Symax.insert(i); for (ll i = 1; i <= W; i++) if (X[i] == xmax) Sxmax.insert(i); ll ans = ymax + xmax; ll sum = 0; for (ll i = 0; i < M; i++) { ll y = A[i].first; ll x = A[i].second; if (Symax.count(y) && Sxmax.count(x)) sum++; } ll a = Symax.size(); ll b = Sxmax.size(); if (sum == a * b) ans--; cout << ans << endl; return 0; }
replace
5
7
5
7
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; const long long LINF = 1e18; #define dump(x) cout << 'x' << ' = ' << (x) << ` `; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) typedef long long ll; using namespace std; typedef pair<ll, ll> P; template <typename T> void print(const vector<T> &x) { int n = x.size(); rep(i, n) { cout << x[i]; if (i != n - 1) cout << " "; else cout << endl; } } template <typename T> void print(const vector<vector<T>> &x) { int n = x.size(); rep(i, n) { rep(j, x[i].size()) { cout << x[i][j] << " "; } cout << endl; } } template <typename T> void print(const vector<T> &x, int n) { rep(i, n) { cout << x[i]; if (i != n - 1) cout << " "; else cout << endl; } } template <typename T> void print(const vector<vector<T>> &x, int n, int m) { rep(i, n) { rep(j, m) { cout << x[i][j] << " "; } cout << 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; } void input_init() { cin.tie(0); ios::sync_with_stdio(false); } int main(int argc, char const *argv[]) { int h, w, m; cin >> h >> w >> m; vector<ll> a(m), b(m); map<ll, ll> my, mx; set<P> st; rep(i, m) { cin >> a[i] >> b[i]; st.emplace(a[i], b[i]); my[a[i]]++; mx[b[i]]++; } ll Y = 0; ll X = 0; for (auto &&e : my) chmax(Y, e.second); for (auto &&e : mx) chmax(X, e.second); vector<ll> cx, cy; for (auto &&e : my) if (e.second == Y) cy.push_back(e.first); for (auto &&e : mx) if (e.second == X) cx.push_back(e.first); ll ans = 0; rep(i, cy.size()) { rep(j, cx.size()) { if (st.count(make_pair(cy[i], cx[j]))) { chmax(ans, X + Y - 1); } else { chmax(ans, X + Y); } } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; const long long LINF = 1e18; #define dump(x) cout << 'x' << ' = ' << (x) << ` `; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) typedef long long ll; using namespace std; typedef pair<ll, ll> P; template <typename T> void print(const vector<T> &x) { int n = x.size(); rep(i, n) { cout << x[i]; if (i != n - 1) cout << " "; else cout << endl; } } template <typename T> void print(const vector<vector<T>> &x) { int n = x.size(); rep(i, n) { rep(j, x[i].size()) { cout << x[i][j] << " "; } cout << endl; } } template <typename T> void print(const vector<T> &x, int n) { rep(i, n) { cout << x[i]; if (i != n - 1) cout << " "; else cout << endl; } } template <typename T> void print(const vector<vector<T>> &x, int n, int m) { rep(i, n) { rep(j, m) { cout << x[i][j] << " "; } cout << 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; } void input_init() { cin.tie(0); ios::sync_with_stdio(false); } int main(int argc, char const *argv[]) { int h, w, m; cin >> h >> w >> m; vector<ll> a(m), b(m); map<ll, ll> my, mx; set<P> st; rep(i, m) { cin >> a[i] >> b[i]; st.emplace(a[i], b[i]); my[a[i]]++; mx[b[i]]++; } ll Y = 0; ll X = 0; for (auto &&e : my) chmax(Y, e.second); for (auto &&e : mx) chmax(X, e.second); vector<ll> cx, cy; for (auto &&e : my) if (e.second == Y) cy.push_back(e.first); for (auto &&e : mx) if (e.second == X) cx.push_back(e.first); ll ans = 0; rep(i, cy.size()) { rep(j, cx.size()) { if (st.count(make_pair(cy[i], cx[j]))) { chmax(ans, X + Y - 1); } else { chmax(ans, X + Y); cout << ans << '\n'; return 0; } } } cout << ans << '\n'; return 0; }
insert
104
104
104
106
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define MAXX 200010 #define PI 3.14159265358979323846264338327950 #define PB push_back #define F first #define S second #define fixx(n) fixed << setprecision(n) #define ll long long #define mod 1000000007 ll h, w, t; ll x, y; ll a[MAXX]; ll b[MAXX]; int main() { FAST; cin >> h >> w >> t; map<ll, bool> m; while (t--) { cin >> x >> y; a[x]++; b[y]++; ll k = (x - 1) * w + y; m[k] = true; } vector<pair<ll, ll>> v; for (ll i = 1; i <= h; i++) { v.push_back({a[i], i}); } vector<pair<ll, ll>> p; for (ll i = 1; i <= w; i++) { p.push_back({b[i], i}); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); sort(p.begin(), p.end()); reverse(p.begin(), p.end()); x = v[0].first; y = p[0].first; ll k = x + y; ll ans = k - 1; for (ll i = 0; i < v.size(); i++) { bool f = false; for (ll j = 0; j < p.size(); j++) { ll c = v[i].first; ll d = p[j].first; if (d < y) { break; } if (c < x) { f = true; break; } c = v[i].second; d = p[j].second; ll sum = (c - 1) * w + d; if (m[sum] == false) { ans++; f = true; break; } } if (f == true) { break; } } int h2 = 0; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define MAXX 500005 #define PI 3.14159265358979323846264338327950 #define PB push_back #define F first #define S second #define fixx(n) fixed << setprecision(n) #define ll long long #define mod 1000000007 ll h, w, t; ll x, y; ll a[MAXX]; ll b[MAXX]; int main() { FAST; cin >> h >> w >> t; map<ll, bool> m; while (t--) { cin >> x >> y; a[x]++; b[y]++; ll k = (x - 1) * w + y; m[k] = true; } vector<pair<ll, ll>> v; for (ll i = 1; i <= h; i++) { v.push_back({a[i], i}); } vector<pair<ll, ll>> p; for (ll i = 1; i <= w; i++) { p.push_back({b[i], i}); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); sort(p.begin(), p.end()); reverse(p.begin(), p.end()); x = v[0].first; y = p[0].first; ll k = x + y; ll ans = k - 1; for (ll i = 0; i < v.size(); i++) { bool f = false; for (ll j = 0; j < p.size(); j++) { ll c = v[i].first; ll d = p[j].first; if (d < y) { break; } if (c < x) { f = true; break; } c = v[i].second; d = p[j].second; ll sum = (c - 1) * w + d; if (m[sum] == false) { ans++; f = true; break; } } if (f == true) { break; } } int h2 = 0; cout << ans << endl; return 0; }
replace
8
9
8
9
0
p02580
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w, m; cin >> h >> w >> m; vector<int> col(w, 0); vector<int> row(h, 0); set<pair<int, int>> s; rep(i, m) { int h, w; cin >> h >> w; col[--w]++; row[--h]++; s.insert(make_pair(h, w)); } int max_val = 0; rep(i, h) { max_val = max(max_val, row[i]); } vector<int> max_idy; rep(i, h) { if (row[i] == max_val) { max_idy.push_back(i); } } int max_val2 = 0; rep(i, h) { max_val2 = max(max_val2, col[i]); } vector<int> max_idx; rep(i, w) { if (col[i] == max_val2) { max_idx.push_back(i); } } int res = 0; for (auto e1 : max_idy) for (auto e2 : max_idx) { auto it = s.find(make_pair(e1, e2)); int flag = 0; if (it != s.end()) { res = max(res, max_val + max_val2 - 1); } else { res = max(res, max_val + max_val2); flag = 1; break; } if (flag) break; } wcout << res << endl; }
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w, m; cin >> h >> w >> m; vector<int> col(w, 0); vector<int> row(h, 0); set<pair<int, int>> s; rep(i, m) { int h, w; cin >> h >> w; col[--w]++; row[--h]++; s.insert(make_pair(h, w)); } int max_val = 0; rep(i, h) { max_val = max(max_val, row[i]); } vector<int> max_idy; rep(i, h) { if (row[i] == max_val) { max_idy.push_back(i); } } int max_val2 = 0; rep(i, w) { max_val2 = max(max_val2, col[i]); } vector<int> max_idx; rep(i, w) { if (col[i] == max_val2) { max_idx.push_back(i); } } int res = 0; for (auto e1 : max_idy) for (auto e2 : max_idx) { auto it = s.find(make_pair(e1, e2)); int flag = 0; if (it != s.end()) { res = max(res, max_val + max_val2 - 1); } else { res = max(res, max_val + max_val2); flag = 1; break; } if (flag) break; } wcout << res << endl; }
replace
54
55
54
55
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1000000007 using namespace std; int main() { long H, W, m; cin >> H >> W >> m; vector<pair<long, long>> hw; vector<long> hi(H), wi(W); rep(i, int(hi.size())) { hi[i] = 0; wi[i] = 0; } long h1, w1; rep(i, m) { cin >> h1 >> w1; h1--; w1--; hw.push_back({h1, w1}); hi[h1]++; wi[w1]++; } long maxh = 0, maxw = 0; rep(i, int(hi.size())) if (maxh < hi[i]) maxh = hi[i]; rep(i, int(wi.size())) if (maxw < wi[i]) maxw = wi[i]; long ans = maxh + maxw; vector<int> hcan, wcan; rep(i, int(hi.size())) if (maxh == hi[i]) { hcan.push_back(i); hi[i] = -INF; } rep(i, int(wi.size())) if (maxw == wi[i]) { wcan.push_back(i); wi[i] = -INF; } long tmp = 0; rep(i, m) { if (hi[hw[i].first] == -INF && wi[hw[i].second] == -INF) { tmp++; } } if (tmp == int(hcan.size()) * int(wcan.size())) ans--; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1000000007 using namespace std; int main() { long H, W, m; cin >> H >> W >> m; vector<pair<long, long>> hw; vector<long> hi(H), wi(W); rep(i, int(hi.size())) hi[i] = 0; rep(i, int(wi.size())) wi[i] = 0; long h1, w1; rep(i, m) { cin >> h1 >> w1; h1--; w1--; hw.push_back({h1, w1}); hi[h1]++; wi[w1]++; } long maxh = 0, maxw = 0; rep(i, int(hi.size())) if (maxh < hi[i]) maxh = hi[i]; rep(i, int(wi.size())) if (maxw < wi[i]) maxw = wi[i]; long ans = maxh + maxw; vector<int> hcan, wcan; rep(i, int(hi.size())) if (maxh == hi[i]) { hcan.push_back(i); hi[i] = -INF; } rep(i, int(wi.size())) if (maxw == wi[i]) { wcan.push_back(i); wi[i] = -INF; } long tmp = 0; rep(i, m) { if (hi[hw[i].first] == -INF && wi[hw[i].second] == -INF) { tmp++; } } if (tmp == int(hcan.size()) * int(wcan.size())) ans--; cout << ans << endl; return 0; }
replace
10
14
10
12
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define INF 1e12 #define PB push_back #define PF push_front #define fi first #define se second #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vpi vector<pii> #define vll vector<ll> #define vpl vector<pll> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define MX(x) *max_element(all(x)) #define MN(x) *min_element(all(x)) #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define pr_d(x) cout << fixed << setprecision(15) << x << endl #define ud(c, x) distance(c.begin(), upper_bound(all(c), x)) #define ld(c, x) distance(c.begin(), lower_bound(all(c), x)) #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define rep3(i, n) for (int i = (n - 1); i >= 0; --i) #define rep4(i, a, b) for (int i = (a); i > (b); --i) #define pb push_back #define out(x) cout << x << "\n" bool odd(int i) { return i % 2; } #define all(v) v.begin(), v.end() #define size(x) int(x.size()) int gcd(int a, int b) { return __gcd(a, b); } int lcm(int a, int b) { return a * (b / gcd(a, b)); } void Yes_No(bool f) { if (f) printf("Yes\n"); else printf("No\n"); } void YES_NO(bool f) { if (f) printf("YES\n"); else printf("NO\n"); } template <typename T> void deb1(T x) { cout << x << "\n"; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } //-------------------ここから回答する----------------------- void solve(void) { int h, w, m; cin >> h >> w >> m; vi x(m), y(m); set<pii> s; rep(v, m) { int i, j; cin >> i >> j; y[--i]++; x[--j]++; s.emplace(i, j); } int mx = 0, my = 0; rep(i, h) chmax(my, y[i]); rep(i, w) chmax(mx, x[i]); vi cx, cy; rep(i, h) if (y[i] == my) cy.pb(i); rep(i, w) if (x[i] == mx) cx.pb(i); int ans = mx + my; for (int i : cy) { for (int j : cx) { if (s.count({i, j})) continue; cout << ans << endl; return; } } --ans; cout << ans << endl; return; } int main(void) { solve(); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define INF 1e12 #define PB push_back #define PF push_front #define fi first #define se second #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vpi vector<pii> #define vll vector<ll> #define vpl vector<pll> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define MX(x) *max_element(all(x)) #define MN(x) *min_element(all(x)) #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define pr_d(x) cout << fixed << setprecision(15) << x << endl #define ud(c, x) distance(c.begin(), upper_bound(all(c), x)) #define ld(c, x) distance(c.begin(), lower_bound(all(c), x)) #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define rep3(i, n) for (int i = (n - 1); i >= 0; --i) #define rep4(i, a, b) for (int i = (a); i > (b); --i) #define pb push_back #define out(x) cout << x << "\n" bool odd(int i) { return i % 2; } #define all(v) v.begin(), v.end() #define size(x) int(x.size()) int gcd(int a, int b) { return __gcd(a, b); } int lcm(int a, int b) { return a * (b / gcd(a, b)); } void Yes_No(bool f) { if (f) printf("Yes\n"); else printf("No\n"); } void YES_NO(bool f) { if (f) printf("YES\n"); else printf("NO\n"); } template <typename T> void deb1(T x) { cout << x << "\n"; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } //-------------------ここから回答する----------------------- void solve(void) { int h, w, m; cin >> h >> w >> m; vi x(w), y(h); set<pii> s; rep(v, m) { int i, j; cin >> i >> j; y[--i]++; x[--j]++; s.emplace(i, j); } int mx = 0, my = 0; rep(i, h) chmax(my, y[i]); rep(i, w) chmax(mx, x[i]); vi cx, cy; rep(i, h) if (y[i] == my) cy.pb(i); rep(i, w) if (x[i] == mx) cx.pb(i); int ans = mx + my; for (int i : cy) { for (int j : cx) { if (s.count({i, j})) continue; cout << ans << endl; return; } } --ans; cout << ans << endl; return; } int main(void) { solve(); }
replace
71
72
71
72
0
p02580
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define MOD (1000000000 + 7) using namespace std; typedef long long ll; const int MAX = 3000000; long long fac[MAX], finv[MAX], inv[MAX]; 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; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } 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; } // テーブルを作る前処理 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; } map<ll, ll> prime; // 素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap // O(√n) // 整列済み(mapはkeyで自動で整列される) void prime_factorize(ll n) { if (n <= 1) return; ll l = sqrt(n); for (ll i = 2; i <= (ll)(l); i++) { // if (n % i == 0) { prime_factorize(i); prime_factorize(ll(n / i)); return; } } // mapでは存在しないkeyの場合も自動で構築される prime[n]++; return; } // 約数列挙? vector<ll> divisor; void list_divisor(ll n) { divisor.clear(); for (int i = 1; i * i <= n; i++) { if (n % i == 0) { divisor.push_back(i); if (i * i != n) divisor.push_back(n / i); } } sort(divisor.begin(), divisor.end()); } vector<bool> Eratosthenes(ll N) { vector<bool> primes(N, true); vector<ll> ret; primes[0] = false; primes[1] = false; for (ll i = 2; pow(i, 2) <= N; i++) { if (primes[i]) { for (int j = 2; i * j <= N; j++) primes[i * j] = false; ret.push_back(primes[i]); } } return primes; // ret; } template <typename T> bool next_combination(const T first, const T last, int k) { // ** Sample ** // vector<int> v{1, 2, 3, 4, 5, 6, 7}; // do { // for (int i = 0; i < k; i++) { // cout << v[i] << " "; // } // cout << "| "; // for (int i = k; i < v.size(); i++) { // cout << v[i] << " "; // } // cout << endl; // } while(next_combination(v.begin(), v.end(), k)); const T subset = first + k; // empty container | k = 0 | k == n if (first == last || first == subset || last == subset) { return false; } T src = subset; while (first != src) { src--; if (*src < *(last - 1)) { T dest = subset; while (*src >= *dest) { dest++; } iter_swap(src, dest); rotate(src + 1, dest + 1, last); rotate(subset, subset + (last - dest) - 1, last); return true; } } // restore rotate(first, subset, last); return false; } // union by size + path having class UnionFind { public: vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; // auto compare = [](pair<ll, ll> a, pair<ll, ll> b) { // ll a_mp = get<1>(a); // ll b_mp = get<1>(b); // return a_mp < b_mp; // // if (a_mp != b_mp) return a_mp > b_mp; // // else return get<0>(a) > get<0>(b); // }; ll H, W; bool push_queue(vector<vector<char>> &m, queue<tuple<ll, ll, ll>> &q, vector<vector<ll>> &seen, ll h, ll w, ll magic) { if (h >= H || w >= W || h < 0 || w < 0) return false; if (m[h][w] != '.') return false; if (seen[h][w] <= magic) return false; q.push(make_tuple(h, w, magic)); seen[h][w] = magic; return true; } bool check(vector<ll> &h, vector<ll> &w, ll M, ll h_, ll w_) { for (ll i = 0; i < M; i++) { if (h[i] == h_ && w[i] == w_) return true; } return false; } int main() { // E ll H, W, M; cin >> H >> W >> M; vector<ll> h(M, 0), w(M, 0); vector<ll> hcount(H, 0), wcount(W, 0); ll hmax = 0, wmax = 0; for (ll i = 0; i < M; i++) { ll hi, wi; cin >> hi >> wi; h[i] = hi - 1; w[i] = wi - 1; hcount[h[i]]++; wcount[w[i]]++; hmax = max(hmax, hcount[h[i]]); wmax = max(wmax, wcount[w[i]]); } map<ll, vector<ll>> wm; map<ll, vector<ll>> hm; for (ll i = 0; i < W; i++) { wm[wcount[i]].push_back(i); } for (ll i = 0; i < H; i++) { hm[hcount[i]].push_back(i); } for (ll i = 0; i < hm[hmax].size(); i++) { for (ll j = 0; j < wm[wmax].size(); j++) { // cout << hm[hmax][i] << "," << wm[wmax][j] << endl; if (check(h, w, M, hm[hmax][i], wm[wmax][j]) == false) { cout << hmax + wmax << endl; return 0; } } } cout << hmax + wmax - 1 << endl; // D // cin >> H >> W; // ll Ch, Cw; // cin >> Ch >> Cw; // Ch -= 1; // Cw -= 1; // ll Dh, Dw; // cin >> Dh >> Dw; // Dh -= 1; // Dw -= 1; // vector<vector<char>> map(H, vector<char>(W, '.')); // for(ll i = 0; i < H; i++) { // for(ll j = 0; j < W; j++) { // cin >> map[i][j]; // } // } // queue<tuple<ll, ll, ll>> q, q2; // q.push(make_tuple(Ch, Cw, 0)); // vector<vector<ll>> seen(H, vector<ll>(W, 9999999)); // while(q.size() > 0 || q2.size() > 0) { // tuple<ll, ll,ll> tup; // if(q.size() == 0) { // tup = q2.front(); q2.pop(); // } else { // tup = q.front(); q.pop(); // } // ll h = get<0>(tup); // ll w = get<1>(tup); // ll magic = get<2>(tup); // // cout << h << "," << w << ":" << magic << endl; // for(ll i = -2; i <= 2; i++) { // for(ll j = -2 ; j <= 2; j++) { // if( i== 0 && j == 0) continue; // if( (i == 0 && abs(j) == 1) || (j == 0 && abs(i) == 1)) // push_queue(map, q, seen, h + i, w + j, magic); // else // push_queue(map, q2, seen, h + i, w + j, magic+1); // } // } // } // if(seen[Dh][Dw] == 9999999) cout << -1 << endl; // else cout << seen[Dh][Dw] << endl; return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define MOD (1000000000 + 7) using namespace std; typedef long long ll; const int MAX = 3000000; long long fac[MAX], finv[MAX], inv[MAX]; 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; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } 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; } // テーブルを作る前処理 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; } map<ll, ll> prime; // 素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap // O(√n) // 整列済み(mapはkeyで自動で整列される) void prime_factorize(ll n) { if (n <= 1) return; ll l = sqrt(n); for (ll i = 2; i <= (ll)(l); i++) { // if (n % i == 0) { prime_factorize(i); prime_factorize(ll(n / i)); return; } } // mapでは存在しないkeyの場合も自動で構築される prime[n]++; return; } // 約数列挙? vector<ll> divisor; void list_divisor(ll n) { divisor.clear(); for (int i = 1; i * i <= n; i++) { if (n % i == 0) { divisor.push_back(i); if (i * i != n) divisor.push_back(n / i); } } sort(divisor.begin(), divisor.end()); } vector<bool> Eratosthenes(ll N) { vector<bool> primes(N, true); vector<ll> ret; primes[0] = false; primes[1] = false; for (ll i = 2; pow(i, 2) <= N; i++) { if (primes[i]) { for (int j = 2; i * j <= N; j++) primes[i * j] = false; ret.push_back(primes[i]); } } return primes; // ret; } template <typename T> bool next_combination(const T first, const T last, int k) { // ** Sample ** // vector<int> v{1, 2, 3, 4, 5, 6, 7}; // do { // for (int i = 0; i < k; i++) { // cout << v[i] << " "; // } // cout << "| "; // for (int i = k; i < v.size(); i++) { // cout << v[i] << " "; // } // cout << endl; // } while(next_combination(v.begin(), v.end(), k)); const T subset = first + k; // empty container | k = 0 | k == n if (first == last || first == subset || last == subset) { return false; } T src = subset; while (first != src) { src--; if (*src < *(last - 1)) { T dest = subset; while (*src >= *dest) { dest++; } iter_swap(src, dest); rotate(src + 1, dest + 1, last); rotate(subset, subset + (last - dest) - 1, last); return true; } } // restore rotate(first, subset, last); return false; } // union by size + path having class UnionFind { public: vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; // auto compare = [](pair<ll, ll> a, pair<ll, ll> b) { // ll a_mp = get<1>(a); // ll b_mp = get<1>(b); // return a_mp < b_mp; // // if (a_mp != b_mp) return a_mp > b_mp; // // else return get<0>(a) > get<0>(b); // }; ll H, W; bool push_queue(vector<vector<char>> &m, queue<tuple<ll, ll, ll>> &q, vector<vector<ll>> &seen, ll h, ll w, ll magic) { if (h >= H || w >= W || h < 0 || w < 0) return false; if (m[h][w] != '.') return false; if (seen[h][w] <= magic) return false; q.push(make_tuple(h, w, magic)); seen[h][w] = magic; return true; } bool check(vector<ll> &h, vector<ll> &w, ll M, ll h_, ll w_) { for (ll i = 0; i < M; i++) { if (h[i] == h_ && w[i] == w_) return true; } return false; } int main() { // E ll H, W, M; cin >> H >> W >> M; vector<ll> h(M, 0), w(M, 0); vector<ll> hcount(H, 0), wcount(W, 0); ll hmax = 0, wmax = 0; for (ll i = 0; i < M; i++) { ll hi, wi; cin >> hi >> wi; h[i] = hi - 1; w[i] = wi - 1; hcount[h[i]]++; wcount[w[i]]++; hmax = max(hmax, hcount[h[i]]); wmax = max(wmax, wcount[w[i]]); } map<ll, vector<ll>> wm; map<ll, vector<ll>> hm; for (ll i = 0; i < W; i++) { wm[wcount[i]].push_back(i); } for (ll i = 0; i < H; i++) { hm[hcount[i]].push_back(i); } ll count = 0; for (ll i = 0; i < M; i++) { if (hcount[h[i]] == hmax && wcount[w[i]] == wmax) count++; } if (hm[hmax].size() * wm[wmax].size() > count) cout << hmax + wmax << endl; else cout << hmax + wmax - 1 << endl; // D // cin >> H >> W; // ll Ch, Cw; // cin >> Ch >> Cw; // Ch -= 1; // Cw -= 1; // ll Dh, Dw; // cin >> Dh >> Dw; // Dh -= 1; // Dw -= 1; // vector<vector<char>> map(H, vector<char>(W, '.')); // for(ll i = 0; i < H; i++) { // for(ll j = 0; j < W; j++) { // cin >> map[i][j]; // } // } // queue<tuple<ll, ll, ll>> q, q2; // q.push(make_tuple(Ch, Cw, 0)); // vector<vector<ll>> seen(H, vector<ll>(W, 9999999)); // while(q.size() > 0 || q2.size() > 0) { // tuple<ll, ll,ll> tup; // if(q.size() == 0) { // tup = q2.front(); q2.pop(); // } else { // tup = q.front(); q.pop(); // } // ll h = get<0>(tup); // ll w = get<1>(tup); // ll magic = get<2>(tup); // // cout << h << "," << w << ":" << magic << endl; // for(ll i = -2; i <= 2; i++) { // for(ll j = -2 ; j <= 2; j++) { // if( i== 0 && j == 0) continue; // if( (i == 0 && abs(j) == 1) || (j == 0 && abs(i) == 1)) // push_queue(map, q, seen, h + i, w + j, magic); // else // push_queue(map, q2, seen, h + i, w + j, magic+1); // } // } // } // if(seen[Dh][Dw] == 9999999) cout << -1 << endl; // else cout << seen[Dh][Dw] << endl; return 0; }
replace
269
279
269
280
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> // ver2.7.1 #define int long long // #define endl "\n" // fflush(stdout); #define ALL(v) (v).begin(), (v).end() #define Vi vector<int> #define VVi vector<Vi> #define VVVi vector<VVi> #define Vm vector<mint> #define Vs vector<string> #define Vd vector<double> #define Vc vector<char> #define Pii pair<int, int> #define Pdd pair<double, double> #define VPii vector<Pii> #define Tiii tuple<int, int, int> #define VTiii vector<Tiii> #define PQi priority_queue<int> #define PQir priority_queue<int, vector<int>, greater<int>> #define pb push_back #define mp make_pair #define mt make_tuple #define itos to_string #define stoi stoll #define FI first #define SE second #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define cYes cout << "Yes" << endl #define cNo cout << "No" << endl #define cyes cout << "yes" << endl #define cno cout << "no" << endl #define sortr(v) sort(v, greater<>()) #define rep(i, a, b) for (int i = a; i < b; i++) #define repeq(i, a, b) for (int i = a; i <= b; i++) #define repreq(i, a, b) for (int i = a; i >= b; i--) #define dem(a, b) ((a + b - 1) / (b)) #define INF 3000000000000000000 // 3.0*10^18 #define MAX LLONG_MAX #define PI acos(-1.0L) // int MOD = 998244353; // case const int MOD = 1000000007; // 10^9 + 7 const double EPS = 1e-10; using namespace std; struct mint { int x; mint(int 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(int t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } 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; } /* debug */ template <typename T> // vector ostream &operator<<(ostream &os, const vector<T> &V) { int N = V.size(); if (N == 0) { os << '.'; return os; } rep(i, 0, N - 1) { os << V[i] << ' '; } os << V[N - 1]; return os; } template <typename T> // vector vector ostream &operator<<(ostream &os, const vector<vector<T>> &V) { int N = V.size(); rep(i, 0, N - 1) cout << V[i] << endl; cout << V[N - 1]; return os; } template <typename T, typename S> // pair ostream &operator<<(ostream &os, pair<T, S> const &P) { os << P.FI << ' ' << P.SE; return os; } template <typename T> // set ostream &operator<<(ostream &os, set<T> &S) { auto it = S.begin(); while (it != S.end()) { os << *it; if (next(it, 1) != S.end()) os << ' '; it++; }; return os; } template <typename T> // deque ostream &operator<<(ostream &os, deque<T> &q) { for (auto it = q.begin(); it < q.end(); it++) { os << *it; if (it + 1 != q.end()) os << " "; } return os; } /* useful */ template <typename T> void Vin(vector<T> &v) { int n = v.size(); rep(i, 0, n) cin >> v[i]; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } int mypow(int x, int n, int m) { if (n == 0) return 1; if (n % 2 == 0) return mypow(x * x % m, n / 2, m); else return x * mypow(x, n - 1, m) % m; } int scomb(int n, int r) { if (r < 0 || r > n) return 0; if ((n - r) < r) r = n - r; // nCr int a = 1; for (int i = n; i > n - r; --i) { a = a * i; } for (int i = 1; i < r + 1; ++i) { a = a / i; } return a; } Vi vis(Vi &v) { Vi S(v.size() + 1); rep(i, 1, S.size()) S[i] += v[i - 1] + S[i - 1]; return S; } int digitsum(int n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; } return ret; } int digit(int k, int i) { string s = itos(k); return s[s.size() - i] - '0'; } // i桁目の数字 template <typename T> void press(T &v) { v.erase(unique(ALL(v)), v.end()); } // 圧縮 Vi zip(Vi b) { int Z = b.size(); // 座標圧縮 Pii p[Z + 10]; int a = b.size(); Vi l(a); for (int i = 0; i < a; i++) p[i] = mp(b[i], i); sort(p, p + a); int w = 0; for (int i = 0; i < a; i++) { if (i && p[i].first != p[i - 1].first) w++; l[p[i].second] = w; } return l; } Vi nibe2V() { Vi a(60); int q = 1; rep(i, 0, 60) { a[i] = q; q *= 2; } return a; } // Vi nibe = nibe2V(); // 2^n int modiv(int a, int b) { return a * mypow(b, MOD - 2, MOD) % MOD; } // a÷b(%MOD) int SMALLER(Vi &a, int x) { return lower_bound(a.begin(), a.end(), x) - a.begin(); } int orSMALLER(Vi &a, int x) { return upper_bound(a.begin(), a.end(), x) - a.begin(); } int BIGGER(Vi &a, int x) { return a.size() - orSMALLER(a, x); } int orBIGGER(Vi &a, int x) { return a.size() - SMALLER(a, x); } int COUNT(Vi &a, int x) { return upper_bound(ALL(a), x) - lower_bound(ALL(a), x); } int maxind(Vi &a) { return max_element(ALL(a)) - a.begin(); } int minind(Vi &a) { return min_element(ALL(a)) - a.begin(); } Vi stpowV() { Vi a(1000005); a[0] = 1; repeq(i, 1, 1000004) a[i] = a[i - 1] * i % MOD; return a; } // Vi stpow = stpowV(); // 階乗配列(%MOD) /****************************** START ******************************/ signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); int h, w, K; cin >> h >> w; int m; cin >> m; Vi r(m), c(m); Vi yoko(w), tate(h); rep(i, 0, m) { cin >> r[i] >> c[i]; r[i]--, c[i]--; tate[r[i]]++; yoko[c[i]]++; } // cout << tate << endl; // cout << yoko << endl; K = *max_element(ALL(tate)) + *max_element(ALL(yoko)); Vi sum_h(100010), sum_w(100010); rep(i, 0, h) { sum_h[tate[i]]++; } rep(i, 0, w) { sum_w[yoko[i]]++; } // cout << sum_w << endl; int ans = 0; repeq(i, 0, K) { ans += sum_w[i] * sum_h[K - i]; } // cout << ans << endl; rep(i, 0, m) { int sum = tate[r[i]] + yoko[c[i]]; if (sum == K) ans--; else if (sum == K + 1) ans++; } // cout << ans << endl; if (ans >= 1) cout << K << endl; else cout << K - 1 << endl; return 0; }
#include <bits/stdc++.h> // ver2.7.1 #define int long long // #define endl "\n" // fflush(stdout); #define ALL(v) (v).begin(), (v).end() #define Vi vector<int> #define VVi vector<Vi> #define VVVi vector<VVi> #define Vm vector<mint> #define Vs vector<string> #define Vd vector<double> #define Vc vector<char> #define Pii pair<int, int> #define Pdd pair<double, double> #define VPii vector<Pii> #define Tiii tuple<int, int, int> #define VTiii vector<Tiii> #define PQi priority_queue<int> #define PQir priority_queue<int, vector<int>, greater<int>> #define pb push_back #define mp make_pair #define mt make_tuple #define itos to_string #define stoi stoll #define FI first #define SE second #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define cYes cout << "Yes" << endl #define cNo cout << "No" << endl #define cyes cout << "yes" << endl #define cno cout << "no" << endl #define sortr(v) sort(v, greater<>()) #define rep(i, a, b) for (int i = a; i < b; i++) #define repeq(i, a, b) for (int i = a; i <= b; i++) #define repreq(i, a, b) for (int i = a; i >= b; i--) #define dem(a, b) ((a + b - 1) / (b)) #define INF 3000000000000000000 // 3.0*10^18 #define MAX LLONG_MAX #define PI acos(-1.0L) // int MOD = 998244353; // case const int MOD = 1000000007; // 10^9 + 7 const double EPS = 1e-10; using namespace std; struct mint { int x; mint(int 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(int t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } 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; } /* debug */ template <typename T> // vector ostream &operator<<(ostream &os, const vector<T> &V) { int N = V.size(); if (N == 0) { os << '.'; return os; } rep(i, 0, N - 1) { os << V[i] << ' '; } os << V[N - 1]; return os; } template <typename T> // vector vector ostream &operator<<(ostream &os, const vector<vector<T>> &V) { int N = V.size(); rep(i, 0, N - 1) cout << V[i] << endl; cout << V[N - 1]; return os; } template <typename T, typename S> // pair ostream &operator<<(ostream &os, pair<T, S> const &P) { os << P.FI << ' ' << P.SE; return os; } template <typename T> // set ostream &operator<<(ostream &os, set<T> &S) { auto it = S.begin(); while (it != S.end()) { os << *it; if (next(it, 1) != S.end()) os << ' '; it++; }; return os; } template <typename T> // deque ostream &operator<<(ostream &os, deque<T> &q) { for (auto it = q.begin(); it < q.end(); it++) { os << *it; if (it + 1 != q.end()) os << " "; } return os; } /* useful */ template <typename T> void Vin(vector<T> &v) { int n = v.size(); rep(i, 0, n) cin >> v[i]; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } int mypow(int x, int n, int m) { if (n == 0) return 1; if (n % 2 == 0) return mypow(x * x % m, n / 2, m); else return x * mypow(x, n - 1, m) % m; } int scomb(int n, int r) { if (r < 0 || r > n) return 0; if ((n - r) < r) r = n - r; // nCr int a = 1; for (int i = n; i > n - r; --i) { a = a * i; } for (int i = 1; i < r + 1; ++i) { a = a / i; } return a; } Vi vis(Vi &v) { Vi S(v.size() + 1); rep(i, 1, S.size()) S[i] += v[i - 1] + S[i - 1]; return S; } int digitsum(int n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; } return ret; } int digit(int k, int i) { string s = itos(k); return s[s.size() - i] - '0'; } // i桁目の数字 template <typename T> void press(T &v) { v.erase(unique(ALL(v)), v.end()); } // 圧縮 Vi zip(Vi b) { int Z = b.size(); // 座標圧縮 Pii p[Z + 10]; int a = b.size(); Vi l(a); for (int i = 0; i < a; i++) p[i] = mp(b[i], i); sort(p, p + a); int w = 0; for (int i = 0; i < a; i++) { if (i && p[i].first != p[i - 1].first) w++; l[p[i].second] = w; } return l; } Vi nibe2V() { Vi a(60); int q = 1; rep(i, 0, 60) { a[i] = q; q *= 2; } return a; } // Vi nibe = nibe2V(); // 2^n int modiv(int a, int b) { return a * mypow(b, MOD - 2, MOD) % MOD; } // a÷b(%MOD) int SMALLER(Vi &a, int x) { return lower_bound(a.begin(), a.end(), x) - a.begin(); } int orSMALLER(Vi &a, int x) { return upper_bound(a.begin(), a.end(), x) - a.begin(); } int BIGGER(Vi &a, int x) { return a.size() - orSMALLER(a, x); } int orBIGGER(Vi &a, int x) { return a.size() - SMALLER(a, x); } int COUNT(Vi &a, int x) { return upper_bound(ALL(a), x) - lower_bound(ALL(a), x); } int maxind(Vi &a) { return max_element(ALL(a)) - a.begin(); } int minind(Vi &a) { return min_element(ALL(a)) - a.begin(); } Vi stpowV() { Vi a(1000005); a[0] = 1; repeq(i, 1, 1000004) a[i] = a[i - 1] * i % MOD; return a; } // Vi stpow = stpowV(); // 階乗配列(%MOD) /****************************** START ******************************/ signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); int h, w, K; cin >> h >> w; int m; cin >> m; Vi r(m), c(m); Vi yoko(w), tate(h); rep(i, 0, m) { cin >> r[i] >> c[i]; r[i]--, c[i]--; tate[r[i]]++; yoko[c[i]]++; } // cout << tate << endl; // cout << yoko << endl; K = *max_element(ALL(tate)) + *max_element(ALL(yoko)); Vi sum_h(300010), sum_w(300010); rep(i, 0, h) { sum_h[tate[i]]++; } rep(i, 0, w) { sum_w[yoko[i]]++; } // cout << sum_w << endl; int ans = 0; repeq(i, 0, K) { ans += sum_w[i] * sum_h[K - i]; } // cout << ans << endl; rep(i, 0, m) { int sum = tate[r[i]] + yoko[c[i]]; if (sum == K) ans--; else if (sum == K + 1) ans++; } // cout << ans << endl; if (ans >= 1) cout << K << endl; else cout << K - 1 << endl; return 0; }
replace
249
250
249
250
0
p02580
C++
Runtime Error
#include <cmath> #include <iostream> using namespace std; typedef long long ll; int main() { const int SIZE = 30010; int H, W, M, h[SIZE], w[SIZE], x[SIZE], y[SIZE]; cin >> H >> W >> M; for (int i = 1; i <= H; ++i) { x[i] = 0; } for (int i = 1; i <= W; ++i) { y[i] = 0; } for (int i = 0; i < M; ++i) { cin >> h[i] >> w[i]; x[h[i]]++; y[w[i]]++; } int x_max = 0; for (int i = 1; i <= H; ++i) { x_max = max(x_max, x[i]); } int x_sum = 0; for (int i = 1; i <= H; ++i) { if (x[i] == x_max) x_sum++; } int y_max = 0; for (int i = 1; i <= W; ++i) { y_max = max(y_max, y[i]); } int y_sum = 0; for (int i = 1; i <= W; ++i) { if (y[i] == y_max) y_sum++; } int m_sum = 0; for (int i = 0; i < M; ++i) { if (x[h[i]] == x_max && y[w[i]] == y_max) m_sum++; } if (m_sum == x_sum * y_sum) { cout << x_max + y_max - 1 << endl; } else { cout << x_max + y_max << endl; } return 0; }
#include <cmath> #include <iostream> using namespace std; typedef long long ll; int main() { const int SIZE = 300010; int H, W, M, h[SIZE], w[SIZE], x[SIZE], y[SIZE]; cin >> H >> W >> M; for (int i = 1; i <= H; ++i) { x[i] = 0; } for (int i = 1; i <= W; ++i) { y[i] = 0; } for (int i = 0; i < M; ++i) { cin >> h[i] >> w[i]; x[h[i]]++; y[w[i]]++; } int x_max = 0; for (int i = 1; i <= H; ++i) { x_max = max(x_max, x[i]); } int x_sum = 0; for (int i = 1; i <= H; ++i) { if (x[i] == x_max) x_sum++; } int y_max = 0; for (int i = 1; i <= W; ++i) { y_max = max(y_max, y[i]); } int y_sum = 0; for (int i = 1; i <= W; ++i) { if (y[i] == y_max) y_sum++; } int m_sum = 0; for (int i = 0; i < M; ++i) { if (x[h[i]] == x_max && y[w[i]] == y_max) m_sum++; } if (m_sum == x_sum * y_sum) { cout << x_max + y_max - 1 << endl; } else { cout << x_max + y_max << endl; } return 0; }
replace
6
7
6
7
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; using Graph = vector<vector<ll>>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++) #define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--) const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll MOD = 1000000007; const ll INF = 1000000000000000000L; #ifdef __DEBUG /** * For DEBUG * https://github.com/ta7uw/cpp-pyprint */ #include "cpp-pyprint/pyprint.h" #endif void solve() { ll H, W, M; cin >> H >> W >> M; map<ll, ll> row, col; vector<P> items(M); set<P> used; rep(i, M) cin >> items[i].first >> items[i].second; rep(i, M) { P p = items[i]; row[p.first]++; col[p.second]++; used.insert(p); } ll m = 0; rep2(i, 1, W + 1) { m = max(m, col[i]); } vector<ll> tar; rep2(i, 1, W + 1) { if (col[i] == m) { tar.push_back(i); } } ll ans = 0; rep2(i, 1, H + 1) { for (ll t : tar) { ll x = row[i]; x += m; if (used.count({i, t})) { x--; } ans = max(ans, x); } } cout << ans << '\n'; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; using Graph = vector<vector<ll>>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++) #define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--) const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll MOD = 1000000007; const ll INF = 1000000000000000000L; #ifdef __DEBUG /** * For DEBUG * https://github.com/ta7uw/cpp-pyprint */ #include "cpp-pyprint/pyprint.h" #endif void solve() { ll H, W, M; cin >> H >> W >> M; map<ll, ll> row, col; vector<P> items(M); set<P> used; rep(i, M) cin >> items[i].first >> items[i].second; rep(i, M) { P p = items[i]; row[p.first]++; col[p.second]++; used.insert(p); } ll m = 0; rep2(i, 1, W + 1) { m = max(m, col[i]); } vector<ll> tar; rep2(i, 1, W + 1) { if (col[i] == m) { tar.push_back(i); } } ll ans = 0; rep2(i, 1, H + 1) { if (row[i] + m - 1 < ans) continue; for (ll t : tar) { ll x = row[i]; x += m; if (used.count({i, t})) { x--; } ans = max(ans, x); } } cout << ans << '\n'; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); return 0; }
insert
49
49
49
51
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; using Graph = vector<vector<ll>>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++) #define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--) const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll MOD = 1000000007; const ll INF = 1000000000000000000L; #ifdef __DEBUG /** * For DEBUG * https://github.com/ta7uw/cpp-pyprint */ #include "cpp-pyprint/pyprint.h" #endif void solve() { ll H, W, M; cin >> H >> W >> M; map<ll, ll> row, col; vector<P> items(M); set<P> used; rep(i, M) cin >> items[i].first >> items[i].second; rep(i, M) { P p = items[i]; row[p.first]++; col[p.second]++; used.insert(p); } ll m = 0; rep2(i, 1, W + 1) { m = max(m, col[i]); } ll m2 = 0; rep2(i, 1, H + 1) { m2 = max(m2, row[i]); } vector<ll> tar1, tar2; rep2(i, 1, W + 1) { if (col[i] == m) tar1.push_back(i); } rep2(i, 1, H + 1) { if (row[i] == m2) tar2.push_back(i); } ll ans = 0; for (ll r : tar2) { for (ll c : tar1) { if (used.count({r, c})) { ans = max(ans, m + m2 - 1); } else { ans = max(ans, m + m2); } } } cout << ans << '\n'; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; using Graph = vector<vector<ll>>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++) #define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--) const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll MOD = 1000000007; const ll INF = 1000000000000000000L; #ifdef __DEBUG /** * For DEBUG * https://github.com/ta7uw/cpp-pyprint */ #include "cpp-pyprint/pyprint.h" #endif void solve() { ll H, W, M; cin >> H >> W >> M; map<ll, ll> row, col; vector<P> items(M); set<P> used; rep(i, M) cin >> items[i].first >> items[i].second; rep(i, M) { P p = items[i]; row[p.first]++; col[p.second]++; used.insert(p); } ll m = 0; rep2(i, 1, W + 1) { m = max(m, col[i]); } ll m2 = 0; rep2(i, 1, H + 1) { m2 = max(m2, row[i]); } vector<ll> tar1, tar2; rep2(i, 1, W + 1) { if (col[i] == m) tar1.push_back(i); } rep2(i, 1, H + 1) { if (row[i] == m2) tar2.push_back(i); } ll ans = 0; for (ll r : tar2) { for (ll c : tar1) { if (used.count({r, c})) { ans = max(ans, m + m2 - 1); } else { ans = max(ans, m + m2); } if (ans == m + m2) break; } } cout << ans << '\n'; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); return 0; }
insert
60
60
60
62
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int h, w, m, sz; vector<int> ob[300005]; int dat[400005]; void upd(int pos, int val) { pos += sz - 1; dat[pos] += val; while (pos > 1) { pos >>= 1; dat[pos] = max(dat[pos << 1], dat[pos << 1 | 1]); } } int qry(int bk, int l, int r, int ql, int qr) { if (qr < l || r < ql) return 0; if (ql <= l && r <= qr) return dat[bk]; return max(qry(bk << 1, l, (l + r) >> 1, ql, qr), qry(bk << 1 | 1, ((l + r) >> 1) + 1, r, ql, qr)); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> h >> w >> m; sz = 1; while (sz < w) sz <<= 1; while (m--) { int x, y; cin >> x >> y; ob[x].emplace_back(y); upd(y, 1); } int ans = 0; for (int i = 1; i <= h; i++) { for (int &j : ob[i]) upd(j, -1); ans = max(ans, (int)ob[i].size() + qry(1, 1, sz, 1, sz)); // cerr<<ob[i].size()<<' '<<qry(1,1,sz,1,sz)<<endl; for (int &j : ob[i]) upd(j, 1); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int h, w, m, sz; vector<int> ob[300005]; int dat[1200005]; void upd(int pos, int val) { pos += sz - 1; dat[pos] += val; while (pos > 1) { pos >>= 1; dat[pos] = max(dat[pos << 1], dat[pos << 1 | 1]); } } int qry(int bk, int l, int r, int ql, int qr) { if (qr < l || r < ql) return 0; if (ql <= l && r <= qr) return dat[bk]; return max(qry(bk << 1, l, (l + r) >> 1, ql, qr), qry(bk << 1 | 1, ((l + r) >> 1) + 1, r, ql, qr)); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> h >> w >> m; sz = 1; while (sz < w) sz <<= 1; while (m--) { int x, y; cin >> x >> y; ob[x].emplace_back(y); upd(y, 1); } int ans = 0; for (int i = 1; i <= h; i++) { for (int &j : ob[i]) upd(j, -1); ans = max(ans, (int)ob[i].size() + qry(1, 1, sz, 1, sz)); // cerr<<ob[i].size()<<' '<<qry(1,1,sz,1,sz)<<endl; for (int &j : ob[i]) upd(j, 1); } cout << ans << endl; return 0; }
replace
6
7
6
7
0
p02580
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { #define int long long int H, W, M; cin >> H >> W >> M; vector<vector<int>> G(H, vector<int>(W, 0)); vector<int> hh(H); vector<int> ww(W); vector<pair<int, int>> memo(M); for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; a--; b--; memo.at(i) = make_pair(a, b); hh.at(a)++; ww.at(b)++; } int mh = 0; int mw = 0; for (int i = 0; i < H; i++) { mh = max(mh, hh.at(i)); } for (int i = 0; i < W; i++) { mw = max(mw, ww.at(i)); } int counth = 0; int countw = 0; for (int i = 0; i < H; i++) { if (mh == hh.at(i)) { counth++; } } for (int i = 0; i < W; i++) { if (mw == ww.at(i)) { countw++; } } int count = 0; for (int i = 0; i < M; i++) { int h = memo.at(i).first; int w = memo.at(i).second; if (hh.at(h) == mh && ww.at(w) == mw) { count++; } } if (count == counth * countw) { cout << mh + mw - 1 << endl; } else { cout << mh + mw << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { #define int long long int H, W, M; cin >> H >> W >> M; vector<int> hh(H); vector<int> ww(W); vector<pair<int, int>> memo(M); for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; a--; b--; memo.at(i) = make_pair(a, b); hh.at(a)++; ww.at(b)++; } int mh = 0; int mw = 0; for (int i = 0; i < H; i++) { mh = max(mh, hh.at(i)); } for (int i = 0; i < W; i++) { mw = max(mw, ww.at(i)); } int counth = 0; int countw = 0; for (int i = 0; i < H; i++) { if (mh == hh.at(i)) { counth++; } } for (int i = 0; i < W; i++) { if (mw == ww.at(i)) { countw++; } } int count = 0; for (int i = 0; i < M; i++) { int h = memo.at(i).first; int w = memo.at(i).second; if (hh.at(h) == mh && ww.at(w) == mw) { count++; } } if (count == counth * countw) { cout << mh + mw - 1 << endl; } else { cout << mh + mw << endl; } }
delete
6
7
6
6
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; int main() { int h, w, m; cin >> h >> w >> m; // vector<vi> masu(h,vi(w,0)); map<pair<int, int>, int> mp; vi tate_count(h, 0); vi yoko_count(w, 0); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; yoko_count[b]++; tate_count[a]++; pair<int, int> kani = make_pair(a, b); mp[kani]++; } int maxi_t = 0; for (int i = 0; i < h; i++) { maxi_t = max(maxi_t, tate_count[i]); } int maxi_y = 0; for (int i = 0; i < w; i++) { maxi_y = max(maxi_y, yoko_count[i]); } int ans = maxi_y + maxi_t; vi yoko, tate; for (int i = 0; i < h; i++) { if (maxi_t == tate_count[i]) tate.push_back(i); } for (int i = 0; i < w; i++) { if (maxi_y == yoko_count[i]) yoko.push_back(i); } bool flag = false; for (auto x : yoko) { for (auto y : tate) { pair<int, int> ebi = make_pair(y, x); if (mp[ebi] == 0) flag = true; } } if (!flag) ans--; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; int main() { int h, w, m; cin >> h >> w >> m; // vector<vi> masu(h,vi(w,0)); map<pair<int, int>, int> mp; vi tate_count(h, 0); vi yoko_count(w, 0); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; yoko_count[b]++; tate_count[a]++; pair<int, int> kani = make_pair(a, b); mp[kani]++; } int maxi_t = 0; for (int i = 0; i < h; i++) { maxi_t = max(maxi_t, tate_count[i]); } int maxi_y = 0; for (int i = 0; i < w; i++) { maxi_y = max(maxi_y, yoko_count[i]); } int ans = maxi_y + maxi_t; vi yoko, tate; for (int i = 0; i < h; i++) { if (maxi_t == tate_count[i]) tate.push_back(i); } for (int i = 0; i < w; i++) { if (maxi_y == yoko_count[i]) yoko.push_back(i); } bool flag = false; if (tate.size() * yoko.size() > 1e9) { cout << ans << endl; return 0; } for (auto x : yoko) { for (auto y : tate) { pair<int, int> ebi = make_pair(y, x); if (mp[ebi] == 0) flag = true; } } if (!flag) ans--; cout << ans << endl; }
insert
41
41
41
45
TLE
p02580
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using P = pair<int, int>; using ll = long long; int main() { int h, w, n; cin >> h >> w >> n; vector<int> hs(h), ws(w); set<P> s; rep(i, n) { int r, c; cin >> r >> c; r--; c--; hs[r]++; ws[c]++; s.emplace(r, c); } int mh = 0, mw = 0; rep(i, h) mh = max(mh, hs[i]); rep(j, w) mw = max(mw, ws[j]); vector<int> is, js; rep(i, h) if (mh == hs[i]) is.push_back(i); rep(j, w) if (mw == hs[j]) js.push_back(j); int ans = mh + mw; for (int i : is) { for (int j : js) { if (s.count(P(i, j))) continue; cout << ans << endl; return 0; } } ans--; cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using P = pair<int, int>; using ll = long long; int main() { int h, w, n; cin >> h >> w >> n; vector<int> hs(h), ws(w); set<P> s; rep(i, n) { int r, c; cin >> r >> c; r--; c--; hs[r]++; ws[c]++; s.emplace(r, c); } int mh = 0, mw = 0; rep(i, h) mh = max(mh, hs[i]); rep(j, w) mw = max(mw, ws[j]); vector<int> is, js; rep(i, h) if (mh == hs[i]) is.push_back(i); rep(j, w) if (mw == ws[j]) js.push_back(j); int ans = mh + mw; for (int i : is) { for (int j : js) { if (s.count(P(i, j))) continue; cout << ans << endl; return 0; } } ans--; cout << ans << endl; }
replace
26
27
26
27
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define f first #define s second #define sz size() #define ll long long #define all(_v) _v.begin(), _v.end() #define pii pair<int, int> #define pll pair<ll, ll> #define pvllvll pair<vector<ll>, vector<ll>> #define ld long double #define veci vector<int> #define vecll vector<ll> const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const double PI = 3.1415926535897932384626433832795; const double eps = 1e-9; const int MOD1 = 1e9 + 7; const int MOD2 = 998244353; const int MAXN = 3e5 + 10; int cnt1[MAXN], cnt2[MAXN]; void solve() { int h, w, n; cin >> h >> w >> n; set<pii> a; for (int i = 1; i <= n; ++i) { int x, y; cin >> x >> y; cnt1[x]++; cnt2[y]++; a.insert(mp(x, y)); } int mx = *max_element(cnt1 + 1, cnt1 + h + 1); int mx2 = *max_element(cnt2 + 1, cnt2 + w + 1); veci x, y; for (int i = 1; i <= h; ++i) if (cnt1[i] == mx) x.pb(i); for (int i = 1; i <= w; ++i) if (cnt2[i] == mx2) y.pb(i); int ans = 0; for (auto v : x) for (auto u : y) ans = max(ans, cnt1[v] + cnt2[u] - (int)a.count(mp(v, u))); cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; /// cin >> T; while (T--) solve(), cout << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define f first #define s second #define sz size() #define ll long long #define all(_v) _v.begin(), _v.end() #define pii pair<int, int> #define pll pair<ll, ll> #define pvllvll pair<vector<ll>, vector<ll>> #define ld long double #define veci vector<int> #define vecll vector<ll> const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const double PI = 3.1415926535897932384626433832795; const double eps = 1e-9; const int MOD1 = 1e9 + 7; const int MOD2 = 998244353; const int MAXN = 3e5 + 10; int cnt1[MAXN], cnt2[MAXN]; void solve() { int h, w, n; cin >> h >> w >> n; set<pii> a; for (int i = 1; i <= n; ++i) { int x, y; cin >> x >> y; cnt1[x]++; cnt2[y]++; a.insert(mp(x, y)); } int mx = *max_element(cnt1 + 1, cnt1 + h + 1); int mx2 = *max_element(cnt2 + 1, cnt2 + w + 1); veci x, y; for (int i = 1; i <= h; ++i) if (cnt1[i] == mx) x.pb(i); for (int i = 1; i <= w; ++i) if (cnt2[i] == mx2) y.pb(i); int ans = 0; for (auto v : x) for (auto u : y) { int ch = a.count(mp(v, u)); ans = max(ans, cnt1[v] + cnt2[u] - ch); if (!ch) break; } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; /// cin >> T; while (T--) solve(), cout << '\n'; return 0; }
replace
47
49
47
53
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else { return false; } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else { return false; } } #define ll long long #define double long double #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = 1; i <= (n); i++) #define mod (ll)(1e9 + 7) #define inf (ll)(3e18 + 7) #define pi (double)acos(-1.0) #define P pair<int, int> #define PiP pair<ll, pair<ll, ll>> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; int main() { ll h, w, m; cin >> h >> w >> m; vector<int> a(h, 0), b(w, 0); map<P, int> mp; rep(i, m) { int x, y; cin >> x >> y; x--; y--; a[x]++; b[y]++; mp[{x, y}]++; } int max_a = *max_element(all(a)), max_b = *max_element(all(b)); int ans = max_a + max_b; rep(i, h) { rep(j, w) { if (mp[{i, j}] == 0 && max_b == b[j] && max_a == a[i]) { cout << ans << endl; return 0; } } } cout << ans - 1 << endl; }
#include <bits/stdc++.h> template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else { return false; } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else { return false; } } #define ll long long #define double long double #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = 1; i <= (n); i++) #define mod (ll)(1e9 + 7) #define inf (ll)(3e18 + 7) #define pi (double)acos(-1.0) #define P pair<int, int> #define PiP pair<ll, pair<ll, ll>> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; int main() { ll h, w, m; cin >> h >> w >> m; vector<int> a(h, 0), b(w, 0); map<P, int> mp; rep(i, m) { int x, y; cin >> x >> y; x--; y--; a[x]++; b[y]++; mp[{x, y}]++; } int max_a = *max_element(all(a)), max_b = *max_element(all(b)); int ans = max_a + max_b; vector<int> v1, v2; rep(i, h) if (max_a == a[i]) v1.push_back(i); rep(i, w) if (max_b == b[i]) v2.push_back(i); rep(i, v1.size()) { rep(j, v2.size()) { if (mp[{v1[i], v2[j]}] == 0) { cout << ans << endl; return 0; } } } cout << ans - 1 << endl; }
replace
46
49
46
52
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rep2(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--) #define rev2(i, a, b) for (int(i) = (a)-1; (i) >= (b); (i)--) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define pb push_back #define eb emplace_back #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } using namespace std; using ll = long long; using P = pair<int, int>; using Pll = pair<long long, long long>; template <class T> using V = vector<T>; template <class T> using VV = vector<vector<T>>; long long TEN(int i) { return !i ? 1 : TEN(i - 1) * 10LL; } template <class T, class U> bool chmin(T &a, const U &b) { if (a > b) { a = b; return 1; } return 0; } template <class T, class U> bool chmax(T &a, const U &b) { if (a < b) { a = b; return 1; } return 0; } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } iosetup; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// int H, W, M; int h[300005], w[300005]; int main() { cin >> H >> W >> M; rep(i, M) cin >> h[i] >> w[i]; map<P, bool> mp; rep(i, M) mp[{h[i], w[i]}] = true; V<int> cntH(300005, 0), cntW(300005, 0); rep(i, M) cntH[h[i]]++, cntW[w[i]]++; int h_id = max_element(rng(cntH)) - cntH.begin(); int w_id = max_element(rng(cntW)) - cntW.begin(); vector<int> max_h, max_w; rep(i, 300005) { if (cntH[i] == cntH[h_id]) max_h.pb(i); if (cntW[i] == cntW[w_id]) max_w.pb(i); } int x = 0; bool ok = false; rep(i, max_h.size()) rep(j, max_w.size()) { x++; if (x >= TEN(7)) { cout << cntH[h_id] + cntW[w_id] - !ok << endl; return 0; } if (!mp[{max_h[i], max_w[j]}]) { ok = true; } } cout << cntH[h_id] + cntW[w_id] - !ok << endl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rep2(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--) #define rev2(i, a, b) for (int(i) = (a)-1; (i) >= (b); (i)--) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define pb push_back #define eb emplace_back #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } using namespace std; using ll = long long; using P = pair<int, int>; using Pll = pair<long long, long long>; template <class T> using V = vector<T>; template <class T> using VV = vector<vector<T>>; long long TEN(int i) { return !i ? 1 : TEN(i - 1) * 10LL; } template <class T, class U> bool chmin(T &a, const U &b) { if (a > b) { a = b; return 1; } return 0; } template <class T, class U> bool chmax(T &a, const U &b) { if (a < b) { a = b; return 1; } return 0; } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } iosetup; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// int H, W, M; int h[300005], w[300005]; int main() { cin >> H >> W >> M; rep(i, M) cin >> h[i] >> w[i]; map<P, bool> mp; rep(i, M) mp[{h[i], w[i]}] = true; V<int> cntH(300005, 0), cntW(300005, 0); rep(i, M) cntH[h[i]]++, cntW[w[i]]++; int h_id = max_element(rng(cntH)) - cntH.begin(); int w_id = max_element(rng(cntW)) - cntW.begin(); vector<int> max_h, max_w; rep(i, 300005) { if (cntH[i] == cntH[h_id]) max_h.pb(i); if (cntW[i] == cntW[w_id]) max_w.pb(i); } int x = 0; bool ok = false; rep(i, max_h.size()) rep(j, max_w.size()) { x++; if (x >= 3 * TEN(5) + 2) { cout << cntH[h_id] + cntW[w_id] - !ok << endl; return 0; } if (!mp[{max_h[i], max_w[j]}]) { ok = true; } } cout << cntH[h_id] + cntW[w_id] - !ok << endl; return 0; }
replace
76
77
76
77
TLE
p02580
C++
Runtime Error
//*************************************JAI SAI //RAM*************************************// #include <bits/stdc++.h> using namespace std; typedef long long int ll; #define endl '\n' ll mat[3000001], vis[3000001], parent[1000001], ranks[1000001]; ll P = 998244353; vector<pair<ll, ll>> path = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; ll find(ll x) { if (parent[x] == x) return x; return parent[x] = find(parent[x]); } void unions(ll x, ll y) { ll xp = find(x); ll yp = find(y); if (xp != yp) { if (ranks[xp] > ranks[yp]) parent[yp] = xp; else { parent[xp] = yp; if (ranks[xp] == ranks[yp]) ranks[yp]++; } } } vector<ll> adj[1000001]; void solve() { ll i, j, k, l, m, n, o, r, p, q, ss, c; ll ans = 0; // cout<<ans<<endl; string s[1011]; cin >> n >> m >> p; map<ll, ll> row, col; map<pair<ll, ll>, ll> mp; ll mat[n + 1][m + 1]; memset(mat, 0, sizeof(mat)); set<ll> ro, co; for (i = 0; i < p; i++) { cin >> j >> k; row[j]++; col[k]++; mp[{j, k}]++; } ans = 0; r = 0; for (i = 1; i <= n; i++) { r = max(r, row[i]); } c = 0; for (i = 1; i <= m; i++) c = max(c, col[i]); for (i = 1; i <= n; i++) { if (row[i] == r) ro.insert(i); } for (i = 1; i <= m; i++) if (col[i] == c) co.insert(i); ans = (r + c - 1); ll flag = 0; for (auto x : ro) { for (auto y : co) { if (mp[{x, y}] == 0) { ans++; flag = 1; break; } } if (flag) break; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll t = 1; // cin>>t; ll o = 1; while (t--) { solve(); o++; } return 0; } // manpreet.singh orz // humane orz // arnavvats orz // leoamish300 orz // cipher76 orz // aug16arpit orz // aayushindwan orz // ig_monkey orz // DeadlyCritic orz // lucky_21 orz // sak23 orz // spookywooky orz // supahotfire orz //__FAILURE_orz // Errichto orz // tourist orz // Um_nik orz // 300iq orz // antontrygub_Oo orz // boboniu orz // MikeMirzayanov orz // MiFaFaOvO orz // Benq orz // Radewoosh orz // AshishGup orz // Ashishchup orz // aryanc403 orz // ma_da_fa_ka orz // Striver_79 orz // Love babbar orz // My Life of ultimate patience and hard work orz!!!!!!!
//*************************************JAI SAI //RAM*************************************// #include <bits/stdc++.h> using namespace std; typedef long long int ll; #define endl '\n' ll mat[3000001], vis[3000001], parent[1000001], ranks[1000001]; ll P = 998244353; vector<pair<ll, ll>> path = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; ll find(ll x) { if (parent[x] == x) return x; return parent[x] = find(parent[x]); } void unions(ll x, ll y) { ll xp = find(x); ll yp = find(y); if (xp != yp) { if (ranks[xp] > ranks[yp]) parent[yp] = xp; else { parent[xp] = yp; if (ranks[xp] == ranks[yp]) ranks[yp]++; } } } vector<ll> adj[1000001]; void solve() { ll i, j, k, l, m, n, o, r, p, q, ss, c; ll ans = 0; // cout<<ans<<endl; string s[1011]; cin >> n >> m >> p; map<ll, ll> row, col; map<pair<ll, ll>, ll> mp; memset(mat, 0, sizeof(mat)); set<ll> ro, co; for (i = 0; i < p; i++) { cin >> j >> k; row[j]++; col[k]++; mp[{j, k}]++; } ans = 0; r = 0; for (i = 1; i <= n; i++) { r = max(r, row[i]); } c = 0; for (i = 1; i <= m; i++) c = max(c, col[i]); for (i = 1; i <= n; i++) { if (row[i] == r) ro.insert(i); } for (i = 1; i <= m; i++) if (col[i] == c) co.insert(i); ans = (r + c - 1); ll flag = 0; for (auto x : ro) { for (auto y : co) { if (mp[{x, y}] == 0) { ans++; flag = 1; break; } } if (flag) break; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll t = 1; // cin>>t; ll o = 1; while (t--) { solve(); o++; } return 0; } // manpreet.singh orz // humane orz // arnavvats orz // leoamish300 orz // cipher76 orz // aug16arpit orz // aayushindwan orz // ig_monkey orz // DeadlyCritic orz // lucky_21 orz // sak23 orz // spookywooky orz // supahotfire orz //__FAILURE_orz // Errichto orz // tourist orz // Um_nik orz // 300iq orz // antontrygub_Oo orz // boboniu orz // MikeMirzayanov orz // MiFaFaOvO orz // Benq orz // Radewoosh orz // AshishGup orz // Ashishchup orz // aryanc403 orz // ma_da_fa_ka orz // Striver_79 orz // Love babbar orz // My Life of ultimate patience and hard work orz!!!!!!!
delete
36
37
36
36
0
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #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, lessl<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define ll long long #define int long long #define double long double #define all(a) (a).begin(), (a).end() #define sz(x) (int)x.size() #define ff first #define ss second #define mp make_pair #define pb push_back #define endl "\n" #define f(i, l, r) for (int i = l; i <= r; i++) #define rf(i, r, l) for (int i = r; i >= l; i--) #define bp __builtin_popcountll #define inf 1e18 const int N = 2e3 + 5; const int M = 1e9 + 7; void solve() { int n, m, k; cin >> n >> m >> k; map<int, int> r, w; map<pair<int, int>, int> mm; vector<pair<int, int>> v(k); int ans = 0; int rm = 0, wm = 0; for (int i = 0; i < k; i++) { int t1, t2; cin >> t1 >> t2; v[i].ff = t1; v[i].ss = t2; r[t1]++; w[t2]++; mm[mp(t1, t2)]++; rm = max(rm, r[t1]); wm = max(wm, w[t2]); } ans = rm + wm - 1; for (auto X : r) { int tar = X.ff; if (X.ss == rm) { for (auto jj : w) { int j = jj.ff; if (jj.ss == wm && mm.find(mp(tar, j)) == mm.end()) { ans++; cout << ans << endl; return; } } } } cout << ans << endl; } signed main() { FAST int t = 1; // cin>>t; for (int tc = 1; tc <= t; tc++) { // cout<<"Case #"<<tc<<": "; solve(); } }
#include <bits/stdc++.h> using namespace std; #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #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, lessl<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define ll long long #define int long long #define double long double #define all(a) (a).begin(), (a).end() #define sz(x) (int)x.size() #define ff first #define ss second #define mp make_pair #define pb push_back #define endl "\n" #define f(i, l, r) for (int i = l; i <= r; i++) #define rf(i, r, l) for (int i = r; i >= l; i--) #define bp __builtin_popcountll #define inf 1e18 const int N = 2e3 + 5; const int M = 1e9 + 7; void solve() { int n, m, k; cin >> n >> m >> k; map<int, int> r, w; map<pair<int, int>, int> mm; vector<pair<int, int>> v(k); int ans = 0; int rm = 0, wm = 0; for (int i = 0; i < k; i++) { int t1, t2; cin >> t1 >> t2; v[i].ff = t1; v[i].ss = t2; r[t1]++; w[t2]++; mm[mp(t1, t2)]++; rm = max(rm, r[t1]); wm = max(wm, w[t2]); } ans = rm + wm - 1; for (int i = 0; i <= n; i++) { if (r.find(i) != r.end()) { if (r[i] != rm) { r.erase(r.find(i)); } } } for (int i = 0; i <= m; i++) { if (w.find(i) != w.end()) { if (w[i] != wm) { w.erase(w.find(i)); } } } for (auto X : r) { int tar = X.ff; if (X.ss == rm) { for (auto jj : w) { int j = jj.ff; if (jj.ss == wm && mm.find(mp(tar, j)) == mm.end()) { ans++; cout << ans << endl; return; } } } } cout << ans << endl; } signed main() { FAST int t = 1; // cin>>t; for (int tc = 1; tc <= t; tc++) { // cout<<"Case #"<<tc<<": "; solve(); } }
insert
53
53
53
67
TLE
p02580
C++
Time Limit Exceeded
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; template <typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef tuple<ll, ll, ll> tlll; typedef tuple<int, int, int> tiii; const ll mod = 1e9 + 7; const int inf = 1 << 30; const ll lnf = 1ll << 60; int main() { int h, w, m; cin >> h >> w >> m; set<pii> bomb; vector<ll> tate(h); vector<ll> yoko(w); ll tatemx = 0; ll yokomx = 0; rep(i, m) { int a, b; cin >> a >> b; a--; b--; tate[a]++; yoko[b]++; chmax(tatemx, tate[a]); chmax(yokomx, yoko[b]); bomb.insert(pii(a, b)); } /* ll ans=0; rep(i,m){ chmax(ans,tate[bomb[i].first]+yoko[bomb[i].second]); } cout << ans-1 << endl; */ vector<int> tatekoho(0); vector<int> yokokoho(0); rep(i, h) { if (tate[i] == tatemx) tatekoho.push_back(i); } rep(i, w) { if (yoko[i] == yokomx) yokokoho.push_back(i); } bool f = 1; rep(i, tatekoho.size()) { rep(j, yokokoho.size()) { if (!(bomb.count(pii(tatekoho[i], yokokoho[j])))) f = 0; } } if (f) cout << tatemx + yokomx - 1 << endl; else cout << tatemx + yokomx << endl; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; template <typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef tuple<ll, ll, ll> tlll; typedef tuple<int, int, int> tiii; const ll mod = 1e9 + 7; const int inf = 1 << 30; const ll lnf = 1ll << 60; int main() { int h, w, m; cin >> h >> w >> m; set<pii> bomb; vector<ll> tate(h); vector<ll> yoko(w); ll tatemx = 0; ll yokomx = 0; rep(i, m) { int a, b; cin >> a >> b; a--; b--; tate[a]++; yoko[b]++; chmax(tatemx, tate[a]); chmax(yokomx, yoko[b]); bomb.insert(pii(a, b)); } /* ll ans=0; rep(i,m){ chmax(ans,tate[bomb[i].first]+yoko[bomb[i].second]); } cout << ans-1 << endl; */ vector<int> tatekoho(0); vector<int> yokokoho(0); rep(i, h) { if (tate[i] == tatemx) tatekoho.push_back(i); } rep(i, w) { if (yoko[i] == yokomx) yokokoho.push_back(i); } if (tatekoho.size() * yokokoho.size() > m) { cout << tatemx + yokomx << endl; return 0; } bool f = 1; rep(i, tatekoho.size()) { rep(j, yokokoho.size()) { if (!(bomb.count(pii(tatekoho[i], yokokoho[j])))) f = 0; } } if (f) cout << tatemx + yokomx - 1 << endl; else cout << tatemx + yokomx << endl; }
insert
67
67
67
71
TLE
p02580
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define f first #define se second #define pb push_back #define ms memset #define MOD 1000000007 #define MOD2 1000000009 #define sp fixed << setprecision #define sz(x) (int)(x).size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; ll fpow(ll x, ll y, ll p = MOD) { x = x % p; ll sum = 1; while (y) { if (y & 1) sum = sum * x; sum %= p; y = y >> 1; x = x * x; x %= p; } return sum; } ll inv(ll a, ll m = MOD) { ll c = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += c; return x; } ll add(ll a, ll b) { if (a < 0) a += MOD; if (b < 0) b += MOD; return (a % MOD + b % MOD + MOD) % MOD; } ll sub(ll a, ll b) { if (a < 0) a += MOD; if (b < 0) b += MOD; return (a % MOD - b % MOD + MOD) % MOD; } ll mul(ll a, ll b) { if (a < 0) a += MOD; if (b < 0) b += MOD; return ((a % MOD) * (b % MOD) + MOD) % MOD; } void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (sz(name)) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } int main() { setIO(); ll h, w, m; cin >> h >> w >> m; map<ll, ll> cx; map<ll, ll> cy; map<pair<ll, ll>, ll> cord; for (int i = 0; i < m; i++) { ll x, y; cin >> x >> y; cx[x]++; cy[y]++; cord[{x, y}]++; } ll res = 0; for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) { ll tmp = cx[i] + cy[j]; if (cord[{i, j}]) tmp--; res = max(res, tmp); } cout << res; }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define f first #define se second #define pb push_back #define ms memset #define MOD 1000000007 #define MOD2 1000000009 #define sp fixed << setprecision #define sz(x) (int)(x).size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; ll fpow(ll x, ll y, ll p = MOD) { x = x % p; ll sum = 1; while (y) { if (y & 1) sum = sum * x; sum %= p; y = y >> 1; x = x * x; x %= p; } return sum; } ll inv(ll a, ll m = MOD) { ll c = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += c; return x; } ll add(ll a, ll b) { if (a < 0) a += MOD; if (b < 0) b += MOD; return (a % MOD + b % MOD + MOD) % MOD; } ll sub(ll a, ll b) { if (a < 0) a += MOD; if (b < 0) b += MOD; return (a % MOD - b % MOD + MOD) % MOD; } ll mul(ll a, ll b) { if (a < 0) a += MOD; if (b < 0) b += MOD; return ((a % MOD) * (b % MOD) + MOD) % MOD; } void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (sz(name)) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } int main() { setIO(); ll h, w, m; cin >> h >> w >> m; map<ll, ll> cx; map<ll, ll> cy; map<pair<ll, ll>, ll> cord; for (int i = 0; i < m; i++) { ll x, y; cin >> x >> y; cx[x]++; cy[y]++; cord[{x, y}]++; } ll maxx = 0; ll maxy = 0; for (auto u : cx) { maxx = max(maxx, u.se); } for (auto u : cy) { maxy = max(maxy, u.se); } vector<ll> vx, vy; for (auto u : cx) { if (u.se == maxx) vx.pb(u.f); } for (auto u : cy) { if (u.se == maxy) vy.pb(u.f); } ll res = maxx + maxy - 1; ll cnt = 0; for (int i = 0; i < vx.size(); i++) for (int j = 0; j < vy.size(); j++) { if (cnt > m) { cout << res; return 0; } if (!cord[{vx[i], vy[j]}]) res = maxx + maxy; cnt++; } cout << res; }
replace
91
98
91
120
TLE
p02580
C++
Runtime Error
#include <algorithm> #include <iostream> #include <set> #include <string> #include <vector> #define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i) #define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return 0; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W, M; cin >> H >> W >> M; vector<int> h(M), w(M); rep(i, 0, M) { cin >> h[i] >> w[i]; } // yoko vector<int> yoko; rep(i, 0, M) { yoko.push_back(w[i]); } sort(all(yoko)); yoko.erase(unique(all(yoko)), yoko.end()); int yoko_size = (int)yoko.size(); vector<int> yoko_cnt(yoko_size, 0); rep(i, 0, M) { ++yoko_cnt[(int)(lower_bound(all(yoko), w[i]) - yoko.begin())]; } // tate vector<int> tate; rep(i, 0, M) { tate.push_back(h[i]); } sort(all(tate)); tate.erase(unique(all(tate)), tate.end()); int tate_size = (int)tate.size(); vector<int> tate_cnt(tate_size, 0); rep(i, 0, M) { ++tate_cnt[(int)(lower_bound(all(tate), h[i]) - tate.begin())]; } vector<vector<int>> yoko_pos(tate_size); rep(i, 0, M) { int h_idx = (int)(lower_bound(all(tate), h[i]) - tate.begin()); yoko_pos[h_idx].push_back( (int)(lower_bound(all(yoko), w[i]) - yoko.begin())); } int ans = 0; multiset<int> others, same; rep(i, 0, yoko_size) { others.insert(yoko_cnt[i]); } rep(i, 0, tate_size) { // 同じ行のものを分ける for (auto &w_idx : yoko_pos[i]) { others.erase(others.find(yoko_cnt[w_idx])); same.insert(yoko_cnt[w_idx] - 1); } chmax(ans, tate_cnt[i] + max(*others.rbegin(), *same.rbegin())); for (auto &w_idx : yoko_pos[i]) { same.erase(same.find(yoko_cnt[w_idx] - 1)); others.insert(yoko_cnt[w_idx]); } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <set> #include <string> #include <vector> #define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i) #define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return 0; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W, M; cin >> H >> W >> M; vector<int> h(M), w(M); rep(i, 0, M) { cin >> h[i] >> w[i]; } // yoko vector<int> yoko; rep(i, 0, M) { yoko.push_back(w[i]); } sort(all(yoko)); yoko.erase(unique(all(yoko)), yoko.end()); int yoko_size = (int)yoko.size(); vector<int> yoko_cnt(yoko_size, 0); rep(i, 0, M) { ++yoko_cnt[(int)(lower_bound(all(yoko), w[i]) - yoko.begin())]; } // tate vector<int> tate; rep(i, 0, M) { tate.push_back(h[i]); } sort(all(tate)); tate.erase(unique(all(tate)), tate.end()); int tate_size = (int)tate.size(); vector<int> tate_cnt(tate_size, 0); rep(i, 0, M) { ++tate_cnt[(int)(lower_bound(all(tate), h[i]) - tate.begin())]; } vector<vector<int>> yoko_pos(tate_size); rep(i, 0, M) { int h_idx = (int)(lower_bound(all(tate), h[i]) - tate.begin()); yoko_pos[h_idx].push_back( (int)(lower_bound(all(yoko), w[i]) - yoko.begin())); } int ans = 0; multiset<int> others, same; rep(i, 0, yoko_size) { others.insert(yoko_cnt[i]); } rep(i, 0, tate_size) { // 同じ行のものを分ける for (auto &w_idx : yoko_pos[i]) { others.erase(others.find(yoko_cnt[w_idx])); same.insert(yoko_cnt[w_idx] - 1); } if (!others.empty()) { chmax(ans, tate_cnt[i] + *others.rbegin()); } if (!same.empty()) { chmax(ans, tate_cnt[i] + *same.rbegin()); } for (auto &w_idx : yoko_pos[i]) { same.erase(same.find(yoko_cnt[w_idx] - 1)); others.insert(yoko_cnt[w_idx]); } } cout << ans << endl; return 0; }
replace
67
68
67
73
0
p02581
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, x[6005], y[2005][2005], add, ans, mx[2005], mxx; int main() { scanf("%d", &n); for (int i = 0; i < n * 3; i++) scanf("%d", x + i); for (int i = 1; i <= n; i++) { mx[i] = INT_MIN; for (int j = 1; j <= n; j++) y[i][j] = INT_MIN; } mx[x[0]] = mx[x[1]] = 0; y[x[0]][x[1]] = y[x[1]][x[0]] = 0; for (int i = 2; i + 3 <= n * 3; i += 3) { sort(x + i, x + i + 3); vector<tuple<int, int, int>> v; if (x[i] == x[i + 2]) { add++; continue; } if (x[i] == x[i + 1]) for (int j = 1; j <= n; j++) v.emplace_back(j, x[i + 2], y[x[i]][j] + 1); else if (x[i + 1] == x[i + 2]) for (int j = 1; j <= n; j++) v.emplace_back(j, x[i], y[x[i + 1]][j] + 1); for (int j = i; j < i + 3; j++) v.emplace_back(j == i ? x[i + 1] : x[i], j == i + 2 ? x[i + 1] : x[i + 2], y[x[j]][x[j]] + 1); v.emplace_back(x[i], x[i + 1], mxx); v.emplace_back(x[i], x[i + 2], mxx); v.emplace_back(x[i + 1], x[i + 2], mxx); for (int j = 1; j <= n; j++) for (int k = i + 1; k < i + 3; k++) v.emplace_back(j, x[i + k], mx[j]); for (auto &j : v) { int ta, tb, tc; tie(ta, tb, tc) = j; y[ta][tb] = max(y[ta][tb], tc); y[tb][ta] = max(y[tb][ta], tc); mx[ta] = max(mx[ta], tc); mx[tb] = max(mx[tb], tc); mxx = max(mxx, tc); } } y[x[n * 3 - 1]][x[n * 3 - 1]]++; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) ans = max(ans, y[i][j]); printf("%d\n", ans + add); }
#include <bits/stdc++.h> using namespace std; int n, x[6005], y[2005][2005], add, ans, mx[2005], mxx; int main() { scanf("%d", &n); for (int i = 0; i < n * 3; i++) scanf("%d", x + i); for (int i = 1; i <= n; i++) { mx[i] = INT_MIN; for (int j = 1; j <= n; j++) y[i][j] = INT_MIN; } mx[x[0]] = mx[x[1]] = 0; y[x[0]][x[1]] = y[x[1]][x[0]] = 0; for (int i = 2; i + 3 <= n * 3; i += 3) { sort(x + i, x + i + 3); vector<tuple<int, int, int>> v; if (x[i] == x[i + 2]) { add++; continue; } if (x[i] == x[i + 1]) for (int j = 1; j <= n; j++) v.emplace_back(j, x[i + 2], y[x[i]][j] + 1); else if (x[i + 1] == x[i + 2]) for (int j = 1; j <= n; j++) v.emplace_back(j, x[i], y[x[i + 1]][j] + 1); for (int j = i; j < i + 3; j++) v.emplace_back(j == i ? x[i + 1] : x[i], j == i + 2 ? x[i + 1] : x[i + 2], y[x[j]][x[j]] + 1); v.emplace_back(x[i], x[i + 1], mxx); v.emplace_back(x[i], x[i + 2], mxx); v.emplace_back(x[i + 1], x[i + 2], mxx); for (int j = 1; j <= n; j++) for (int k = i; k < i + 3; k++) v.emplace_back(j, x[k], mx[j]); for (auto &j : v) { int ta, tb, tc; tie(ta, tb, tc) = j; y[ta][tb] = max(y[ta][tb], tc); y[tb][ta] = max(y[tb][ta], tc); mx[ta] = max(mx[ta], tc); mx[tb] = max(mx[tb], tc); mxx = max(mxx, tc); } } y[x[n * 3 - 1]][x[n * 3 - 1]]++; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) ans = max(ans, y[i][j]); printf("%d\n", ans + add); }
replace
37
39
37
39
0
p02581
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using VI = vector<int>; using VVI = vector<VI>; inline int getBlockStart(int npos, int bakPos) { int nextBlock = (bakPos + 1 - 2) / 3 * 3 + 2; return npos < 0 ? nextBlock : max(nextBlock, (npos - 2) / 3 * 3 + 2); } inline int checkEqual(VI &A, int i, int j, int k) { return A[i] == A[k] && A[i] == A[j]; } inline void solve(VVI &dp, VI &A, int i, int j, int s) { if (s <= j && s + 3 > j) { s += 3; } if (s <= j || j <= i) { return; } int plus = s < A.size() ? checkEqual(A, i, j, s) : 0; dp[A.size()][A.size()] = max(dp[A.size()][A.size()], dp[i][j] + plus); if (s + 2 < A.size()) { dp[i][s + 0] = max(dp[i][s + 0], dp[i][j] + checkEqual(A, j, s + 1, s + 2)); dp[i][s + 1] = max(dp[i][s + 1], dp[i][j] + checkEqual(A, j, s + 0, s + 2)); dp[i][s + 2] = max(dp[i][s + 2], dp[i][j] + checkEqual(A, j, s + 0, s + 1)); dp[j][s + 0] = max(dp[j][s + 0], dp[i][j] + checkEqual(A, i, s + 1, s + 2)); dp[j][s + 1] = max(dp[j][s + 1], dp[i][j] + checkEqual(A, i, s + 0, s + 2)); dp[j][s + 2] = max(dp[j][s + 2], dp[i][j] + checkEqual(A, i, s + 0, s + 1)); dp[s + 0][s + 1] = max(dp[s + 0][s + 1], dp[i][j] + checkEqual(A, i, j, s + 2)); dp[s + 0][s + 2] = max(dp[s + 0][s + 2], dp[i][j] + checkEqual(A, i, j, s + 1)); dp[s + 1][s + 2] = max(dp[s + 1][s + 2], dp[i][j] + checkEqual(A, i, j, s + 0)); } } int main() { int N; cin >> N; VI A; int ans = 0; for (int i = 0; i <= N; ++i) { // pattern: 2, 3, 3 .... , 1 int upper = 2 + (i > 0) - 2 * (i == N); for (int j = 0; j < upper; ++j) { int v; cin >> v; A.push_back(v); } while (A.size() >= 3) { int aSize = A.size(); // cout << "GO " << aSize << endl; if (A[aSize - 1] == A[aSize - 2] && A[aSize - 1] == A[aSize - 3]) { A.pop_back(); A.pop_back(); A.pop_back(); ++ans; } else { break; } } } VVI dp(A.size() + 1, VI(A.size() + 1, -1)); VI curPos(N, -1); VI nextPos(A.size() + 1); for (int p = A.size() - 1; p >= 0; --p) { nextPos[p] = curPos[A[p]]; curPos[A[p]] = p; } dp[0][1] = 0; for (int i = 0; i < A.size(); ++i) { for (int j = i + 1; j < A.size(); ++j) { if (dp[i][j] == -1) { continue; } solve(dp, A, i, j, getBlockStart(j + 1, j)); // match i solve(dp, A, i, j, getBlockStart(nextPos[i], j)); // match j solve(dp, A, i, j, getBlockStart(nextPos[j], j)); } } if (!A.empty()) { cout << ans + dp[A.size()][A.size()] << endl; } else { cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using VI = vector<int>; using VVI = vector<VI>; inline int getBlockStart(int npos, int bakPos) { int nextBlock = (bakPos + 1 - 2) / 3 * 3 + 2; return npos < 0 ? nextBlock : max(nextBlock, (npos - 2) / 3 * 3 + 2); } inline int checkEqual(VI &A, int i, int j, int k) { return A[i] == A[k] && A[i] == A[j]; } inline void solve(VVI &dp, VI &A, int i, int j, int s) { if (s <= j && s + 3 > j) { s += 3; } if (s <= j || j <= i) { return; } int plus = s < A.size() ? checkEqual(A, i, j, s) : 0; dp[A.size()][A.size()] = max(dp[A.size()][A.size()], dp[i][j] + plus); if (s + 2 < A.size()) { dp[i][s + 0] = max(dp[i][s + 0], dp[i][j] + checkEqual(A, j, s + 1, s + 2)); dp[i][s + 1] = max(dp[i][s + 1], dp[i][j] + checkEqual(A, j, s + 0, s + 2)); dp[i][s + 2] = max(dp[i][s + 2], dp[i][j] + checkEqual(A, j, s + 0, s + 1)); dp[j][s + 0] = max(dp[j][s + 0], dp[i][j] + checkEqual(A, i, s + 1, s + 2)); dp[j][s + 1] = max(dp[j][s + 1], dp[i][j] + checkEqual(A, i, s + 0, s + 2)); dp[j][s + 2] = max(dp[j][s + 2], dp[i][j] + checkEqual(A, i, s + 0, s + 1)); dp[s + 0][s + 1] = max(dp[s + 0][s + 1], dp[i][j] + checkEqual(A, i, j, s + 2)); dp[s + 0][s + 2] = max(dp[s + 0][s + 2], dp[i][j] + checkEqual(A, i, j, s + 1)); dp[s + 1][s + 2] = max(dp[s + 1][s + 2], dp[i][j] + checkEqual(A, i, j, s + 0)); } } int main() { int N; cin >> N; VI A; int ans = 0; for (int i = 0; i <= N; ++i) { // pattern: 2, 3, 3 .... , 1 int upper = 2 + (i > 0) - 2 * (i == N); for (int j = 0; j < upper; ++j) { int v; cin >> v; A.push_back(v); } while (A.size() >= 3) { int aSize = A.size(); // cout << "GO " << aSize << endl; if (A[aSize - 1] == A[aSize - 2] && A[aSize - 1] == A[aSize - 3]) { A.pop_back(); A.pop_back(); A.pop_back(); ++ans; } else { break; } } } VVI dp(A.size() + 5, VI(A.size() + 5, -1)); VI curPos(N + 5, -1); VI nextPos(A.size() + 1); for (int p = A.size() - 1; p >= 0; --p) { nextPos[p] = curPos[A[p]]; curPos[A[p]] = p; } dp[0][1] = 0; for (int i = 0; i < A.size(); ++i) { for (int j = i + 1; j < A.size(); ++j) { if (dp[i][j] == -1) { continue; } solve(dp, A, i, j, getBlockStart(j + 1, j)); // match i solve(dp, A, i, j, getBlockStart(nextPos[i], j)); // match j solve(dp, A, i, j, getBlockStart(nextPos[j], j)); } } if (!A.empty()) { cout << ans + dp[A.size()][A.size()] << endl; } else { cout << ans << endl; } return 0; }
replace
85
87
85
87
0
p02581
C++
Time Limit Exceeded
#line 2 "header.hpp" //%snippet.set('header')% //%snippet.fold()% #ifndef HEADER_H #define HEADER_H // template version 2.0 using namespace std; #include <bits/stdc++.h> // varibable settings const long long INF = 1e18; template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1; #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, n) rrepi(i, 0, n) #define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i) #define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(i, a) for (auto &&i : a) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define mt(...) make_tuple(__VA_ARGS__) #define ub upper_bound #define lb lower_bound #define lpos(A, x) (lower_bound(all(A), x) - A.begin()) #define upos(A, x) (upper_bound(all(A), x) - A.begin()) template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); } template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); } template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); } #define cdiv(a, b) (((a) + (b)-1) / (b)) #define is_in(x, a, b) ((a) <= (x) && (x) < (b)) #define uni(x) \ sort(all(x)); \ x.erase(unique(all(x)), x.end()) #define slice(l, r) substr(l, r - l) typedef long long ll; typedef long double ld; using vl = vector<ll>; using vvl = vector<vl>; using pll = pair<ll, ll>; template <typename T> using PQ = priority_queue<T, vector<T>, greater<T>>; void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); } #if defined(PCM) || defined(LOCAL) #else #define dump(...) ; #define dump_1d(...) ; #define dump_2d(...) ; #define cerrendl ; #endif #endif /* HEADER_H */ //%snippet.end()% #line 2 "solve2.cpp" template <class T = ll> using vec = vector<T>; struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast; void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) { if (rest == 0) { f(indexes); } else { if (s < 0) return; recursive_comb(indexes, s - 1, rest, f); indexes[rest - 1] = s; recursive_comb(indexes, s - 1, rest - 1, f); } } // nCkの組み合わせに対して処理を実行する void foreach_comb(int n, int k, std::function<void(int *)> f) { int indexes[k]; recursive_comb(indexes, n - 1, k, f); } int solve() { ll n; cin >> n; vector<ll> a(3 * n); rep(i, 3 * n) { cin >> a[i]; a[i]--; } dump(a); a.pb(n); a.pb(n + 1); vec<vec<ll>> dp = make_table(n + 2, n + 2, -INF); dp[a[0]][a[1]] = 0; dp[a[1]][a[0]] = 0; ll now = 2; vec<ll> buf(3); ll add = 0; vec<tuple<ll, ll, ll>> updates; vec<ll> local(n + 2, -INF); local[a[0]] = 0; local[a[1]] = 0; while (true) { cerrendl; dump(now); buf[0] = a[now]; buf[1] = a[now + 1]; buf[2] = a[now + 2]; sort(all(buf)); ll mv = *max_element(all(local)); if (buf[0] == buf[2]) { add++; } else { if (buf[0] == buf[1]) { ll p = buf[0]; ll q = buf[2]; rep(x, n) updates.pb(mt(q, x, dp[p][x] + 1)); } else if (buf[1] == buf[2]) { ll p = buf[1]; ll q = buf[0]; rep(x, n) updates.pb(mt(q, x, dp[p][x] + 1)); } ll p = buf[0]; ll q = buf[1]; ll r = buf[2]; updates.pb(mt(q, r, dp[p][p] + 1)); updates.pb(mt(p, r, dp[q][q] + 1)); updates.pb(mt(p, q, dp[r][r] + 1)); // (2, 1) updates.pb(mt(p, q, mv)); updates.pb(mt(p, r, mv)); updates.pb(mt(r, q, mv)); // (1, 2) rep(x, n) { updates.pb(mt(x, p, local[x])); updates.pb(mt(x, q, local[x])); updates.pb(mt(x, r, local[x])); } } dump(updates); for (auto [x, y, v] : updates) { chmax(dp[x][y], v); chmax(dp[y][x], v); chmax(local[x], v); chmax(local[y], v); } if (now == 3 * n - 1) break; now += 3; } ll ans = 0; rep(i, n + 2) rep(j, n + 2) chmax(ans, dp[i][j]); cout << ans + add << endl; return 0; } int main() { /*{{{*/ solve(); check_input(); return 0; } /*}}}*/
#line 2 "header.hpp" //%snippet.set('header')% //%snippet.fold()% #ifndef HEADER_H #define HEADER_H // template version 2.0 using namespace std; #include <bits/stdc++.h> // varibable settings const long long INF = 1e18; template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1; #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, n) rrepi(i, 0, n) #define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i) #define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(i, a) for (auto &&i : a) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define mt(...) make_tuple(__VA_ARGS__) #define ub upper_bound #define lb lower_bound #define lpos(A, x) (lower_bound(all(A), x) - A.begin()) #define upos(A, x) (upper_bound(all(A), x) - A.begin()) template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); } template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); } template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); } #define cdiv(a, b) (((a) + (b)-1) / (b)) #define is_in(x, a, b) ((a) <= (x) && (x) < (b)) #define uni(x) \ sort(all(x)); \ x.erase(unique(all(x)), x.end()) #define slice(l, r) substr(l, r - l) typedef long long ll; typedef long double ld; using vl = vector<ll>; using vvl = vector<vl>; using pll = pair<ll, ll>; template <typename T> using PQ = priority_queue<T, vector<T>, greater<T>>; void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); } #if defined(PCM) || defined(LOCAL) #else #define dump(...) ; #define dump_1d(...) ; #define dump_2d(...) ; #define cerrendl ; #endif #endif /* HEADER_H */ //%snippet.end()% #line 2 "solve2.cpp" template <class T = ll> using vec = vector<T>; struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast; void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) { if (rest == 0) { f(indexes); } else { if (s < 0) return; recursive_comb(indexes, s - 1, rest, f); indexes[rest - 1] = s; recursive_comb(indexes, s - 1, rest - 1, f); } } // nCkの組み合わせに対して処理を実行する void foreach_comb(int n, int k, std::function<void(int *)> f) { int indexes[k]; recursive_comb(indexes, n - 1, k, f); } int solve() { ll n; cin >> n; vector<ll> a(3 * n); rep(i, 3 * n) { cin >> a[i]; a[i]--; } dump(a); a.pb(n); a.pb(n + 1); vec<vec<ll>> dp = make_table(n + 2, n + 2, -INF); dp[a[0]][a[1]] = 0; dp[a[1]][a[0]] = 0; ll now = 2; vec<ll> buf(3); ll add = 0; vec<tuple<ll, ll, ll>> updates; vec<ll> local(n + 2, -INF); local[a[0]] = 0; local[a[1]] = 0; while (true) { cerrendl; dump(now); buf[0] = a[now]; buf[1] = a[now + 1]; buf[2] = a[now + 2]; sort(all(buf)); updates.clear(); ll mv = *max_element(all(local)); if (buf[0] == buf[2]) { add++; } else { if (buf[0] == buf[1]) { ll p = buf[0]; ll q = buf[2]; rep(x, n) updates.pb(mt(q, x, dp[p][x] + 1)); } else if (buf[1] == buf[2]) { ll p = buf[1]; ll q = buf[0]; rep(x, n) updates.pb(mt(q, x, dp[p][x] + 1)); } ll p = buf[0]; ll q = buf[1]; ll r = buf[2]; updates.pb(mt(q, r, dp[p][p] + 1)); updates.pb(mt(p, r, dp[q][q] + 1)); updates.pb(mt(p, q, dp[r][r] + 1)); // (2, 1) updates.pb(mt(p, q, mv)); updates.pb(mt(p, r, mv)); updates.pb(mt(r, q, mv)); // (1, 2) rep(x, n) { updates.pb(mt(x, p, local[x])); updates.pb(mt(x, q, local[x])); updates.pb(mt(x, r, local[x])); } } dump(updates); for (auto [x, y, v] : updates) { chmax(dp[x][y], v); chmax(dp[y][x], v); chmax(local[x], v); chmax(local[y], v); } if (now == 3 * n - 1) break; now += 3; } ll ans = 0; rep(i, n + 2) rep(j, n + 2) chmax(ans, dp[i][j]); cout << ans + add << endl; return 0; } int main() { /*{{{*/ solve(); check_input(); return 0; } /*}}}*/
insert
138
138
138
139
TLE
p02581
C++
Runtime Error
#include <bits/stdc++.h> #define ln '\n' #define all(dat) dat.begin(), dat.end() #define loop(i, to) for (int i = 0; i < to; ++i) #define cont(i, to) for (int i = 1; i <= to; ++i) #define circ(i, fm, to) for (int i = fm; i <= to; ++i) #define foreach(i, dat) \ for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i) typedef long long num; using namespace std; const int nsz = 2e3; const int inf = 0x3f3f3f3f; int n, a[nsz + 5], f[nsz + 5][nsz + 5], mx[nsz + 5], maxi, ans; struct value { int a, b, val; value() {} value(int a, int b, int val) { this->a = a, this->b = b, this->val = val; } }; vector<value> dat; bool inline all_same(int a, int b, int c) { return a == b && b == c; } void inline upd(int a, int b, int val) { dat.push_back({a, b, val}); } void inline upd_all() { for (auto &[a, b, val] : dat) { f[a][b] = max(f[a][b], val); f[b][a] = max(f[b][a], val); mx[a] = max(mx[a], val); mx[b] = max(mx[b], val); maxi = max(maxi, val); } dat.clear(); } int main() { scanf("%d", &n); cont(i, n * 3) scanf("%d", &a[i]); memset(f, -inf, sizeof(f)); memset(mx, -inf, sizeof(mx)); maxi = -inf; upd(a[1], a[2], 0); upd_all(); loop(rnd, n) { int i = rnd * 3 + 3; sort(a + i, a + i + 3); if (a[i] == a[i + 2]) { ans += 1; continue; } upd(a[i + 0], a[i + 1], maxi); upd(a[i + 0], a[i + 2], maxi); upd(a[i + 1], a[i + 2], maxi); cont(k, n) { upd(a[i + 0], a[i + 1], f[k][k] + all_same(k, k, a[i + 2])); upd(a[i + 0], a[i + 2], f[k][k] + all_same(k, k, a[i + 1])); upd(a[i + 1], a[i + 2], f[k][k] + all_same(k, k, a[i + 0])); } cont(k, n) { upd(k, a[i + 0], mx[k]); if (a[i + 1] == a[i + 2]) upd(k, a[i + 0], f[k][a[i + 1]] + 1); upd(k, a[i + 1], mx[k]); if (a[i + 0] == a[i + 2]) upd(k, a[i + 1], f[k][a[i + 0]] + 1); upd(k, a[i + 2], mx[k]); if (a[i + 0] == a[i + 1]) upd(k, a[i + 2], f[k][a[i + 0]] + 1); } upd_all(); } ans += maxi; printf("%d\n", ans); }
#include <bits/stdc++.h> #define ln '\n' #define all(dat) dat.begin(), dat.end() #define loop(i, to) for (int i = 0; i < to; ++i) #define cont(i, to) for (int i = 1; i <= to; ++i) #define circ(i, fm, to) for (int i = fm; i <= to; ++i) #define foreach(i, dat) \ for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i) typedef long long num; using namespace std; const int nsz = 2e3; const int inf = 0x3f3f3f3f; int n, a[3 * nsz + 5], f[nsz + 5][nsz + 5], mx[nsz + 5], maxi, ans; struct value { int a, b, val; value() {} value(int a, int b, int val) { this->a = a, this->b = b, this->val = val; } }; vector<value> dat; bool inline all_same(int a, int b, int c) { return a == b && b == c; } void inline upd(int a, int b, int val) { dat.push_back({a, b, val}); } void inline upd_all() { for (auto &[a, b, val] : dat) { f[a][b] = max(f[a][b], val); f[b][a] = max(f[b][a], val); mx[a] = max(mx[a], val); mx[b] = max(mx[b], val); maxi = max(maxi, val); } dat.clear(); } int main() { scanf("%d", &n); cont(i, n * 3) scanf("%d", &a[i]); memset(f, -inf, sizeof(f)); memset(mx, -inf, sizeof(mx)); maxi = -inf; upd(a[1], a[2], 0); upd_all(); loop(rnd, n) { int i = rnd * 3 + 3; sort(a + i, a + i + 3); if (a[i] == a[i + 2]) { ans += 1; continue; } upd(a[i + 0], a[i + 1], maxi); upd(a[i + 0], a[i + 2], maxi); upd(a[i + 1], a[i + 2], maxi); cont(k, n) { upd(a[i + 0], a[i + 1], f[k][k] + all_same(k, k, a[i + 2])); upd(a[i + 0], a[i + 2], f[k][k] + all_same(k, k, a[i + 1])); upd(a[i + 1], a[i + 2], f[k][k] + all_same(k, k, a[i + 0])); } cont(k, n) { upd(k, a[i + 0], mx[k]); if (a[i + 1] == a[i + 2]) upd(k, a[i + 0], f[k][a[i + 1]] + 1); upd(k, a[i + 1], mx[k]); if (a[i + 0] == a[i + 2]) upd(k, a[i + 1], f[k][a[i + 0]] + 1); upd(k, a[i + 2], mx[k]); if (a[i + 0] == a[i + 1]) upd(k, a[i + 2], f[k][a[i + 0]] + 1); } upd_all(); } ans += maxi; printf("%d\n", ans); }
replace
17
18
17
18
0
p02582
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <iomanip> using namespace std; #define ll long long int #define mod 1000000007 #define vec vector<long long int> #define fi first #define se second #define pb push_back int main() { string a; cin >> a; int count = 0; int i = 0; while (i < 3) { if (a[i] == 'R') { count++; } } if (count == 2) { if (a[0] == 'R' && a[2] == 'R') { count = 1; } } cout << count; }
#include <bits/stdc++.h> #include <iomanip> using namespace std; #define ll long long int #define mod 1000000007 #define vec vector<long long int> #define fi first #define se second #define pb push_back int main() { string a; cin >> a; int count = 0; int i = 0; while (i < 3) { if (a[i] == 'R') { count++; } i++; } if (count == 2) { if (a[0] == 'R' && a[2] == 'R') { count = 1; } } cout << count; }
insert
19
19
19
20
TLE
p02582
C++
Runtime Error
#include <iostream> using namespace std; int main() { string a; cin >> a; int i, k = 0; for (i = 0; i < 3; i++) { if (a.at(i) == 'R') { k++; if (a.at(i + 1) != 'R') { break; } } } cout << k; return 0; }
#include <iostream> using namespace std; int main() { string a; cin >> a; int i, k = 0; for (i = 0; i < 3; i++) { if (a.at(i) == 'R') { k++; if (i != 2 && a.at(i + 1) != 'R') { break; } } } cout << k; return 0; }
replace
11
12
11
12
0
p02582
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define uu unsigned #define io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define MOD 1000000007 #define pi pair<int, int> #define pl pair<ll, ll> #define mkp make_pair #define ss second #define ff first #define all(x) x.begin(), x.end() #define vi vector<int> #define vl vector<ll> #define vb vector<bool> #define pb push_back #define pf push_front #define printcas cout << "Case " << cas << ": " #define _ continue; #define endl '\n' #define __ \ cout << endl; \ continue; #define vc4d(nam, type, a, b, c, d, fix) \ vector<vector<vector<vector<type>>>> nam( \ a, vector<vector<vector<type>>>( \ b, vector<vector<type>>(c, vector<type>(d, fix)))) const ll oo = (1ll << 60); int main() { io; int T = 1; // cin>>T; // for(int cas=1;cas<=T;cas++) while (T--) { string s; int cnt = 0, ans = 0, i; cin >> s; for (i = 0; i < 3; i++) { if (s[i] == 'R') { cnt = 0; while (i < 3 and s[i] == 'R') cnt++; ans = max(cnt, ans); } } cout << ans; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define uu unsigned #define io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define MOD 1000000007 #define pi pair<int, int> #define pl pair<ll, ll> #define mkp make_pair #define ss second #define ff first #define all(x) x.begin(), x.end() #define vi vector<int> #define vl vector<ll> #define vb vector<bool> #define pb push_back #define pf push_front #define printcas cout << "Case " << cas << ": " #define _ continue; #define endl '\n' #define __ \ cout << endl; \ continue; #define vc4d(nam, type, a, b, c, d, fix) \ vector<vector<vector<vector<type>>>> nam( \ a, vector<vector<vector<type>>>( \ b, vector<vector<type>>(c, vector<type>(d, fix)))) const ll oo = (1ll << 60); int main() { io; int T = 1; // cin>>T; // for(int cas=1;cas<=T;cas++) while (T--) { string s; int cnt = 0, ans = 0, i; cin >> s; for (i = 0; i < 3; i++) { if (s[i] == 'R') { cnt = 0; while (i < 3 and s[i] == 'R') cnt++, i++; ans = max(cnt, ans); } } cout << ans; } return 0; }
replace
45
46
45
46
TLE
p02582
C++
Time Limit Exceeded
// #include<bits/stdc++.h> #include <cstdio> #include <cstring> #include <iostream> #include <string> #define pb emplace_back #define LOCAL using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1e5 + 5; typedef long long ll; typedef pair<int, int> Pii; template <typename T> inline void read(T &t) { char c = getchar(); t = 0; int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) t = t * 10 + c - 48, c = getchar(); t = f * t; } template <typename T, typename... Args> inline void read(T &t, Args &...args) { read(t); read(args...); } string s; int main() { int t = 1; read(t); while (t--) { cin >> s; int tmp = 0, ans = -1; for (int i = 0; i < 3; i++) { if (s[i] == 'R') { tmp++; } else { ans = max(ans, tmp); tmp = 0; } } ans = max(ans, tmp); printf("%d\n", ans); } return 0; }
// #include<bits/stdc++.h> #include <cstdio> #include <cstring> #include <iostream> #include <string> #define pb emplace_back #define LOCAL using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1e5 + 5; typedef long long ll; typedef pair<int, int> Pii; template <typename T> inline void read(T &t) { char c = getchar(); t = 0; int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) t = t * 10 + c - 48, c = getchar(); t = f * t; } template <typename T, typename... Args> inline void read(T &t, Args &...args) { read(t); read(args...); } string s; int main() { int t = 1; // read(t); while (t--) { cin >> s; int tmp = 0, ans = -1; for (int i = 0; i < 3; i++) { if (s[i] == 'R') { tmp++; } else { ans = max(ans, tmp); tmp = 0; } } ans = max(ans, tmp); printf("%d\n", ans); } return 0; }
replace
38
39
38
39
TLE
p02582
C++
Runtime Error
#include <iostream> #include <string> int main() { std::string S; std::cin >> S; if ("RRS" == S || "SRR" == S) { std::cout << "2"; } if ("SSS" == S) { std::cout << "0"; } if ("RSR" == S || "RSS" == S || "SSR" == S || "SRS" == S) { std::cout << "1"; } return 1; }
#include <iostream> #include <string> int main() { std::string S; std::cin >> S; if ("RRS" == S || "SRR" == S) { std::cout << "2"; } if ("SSS" == S) { std::cout << "0"; } if ("RSR" == S || "RSS" == S || "SSR" == S || "SRS" == S) { std::cout << "1"; } if ("RRR" == S) { std::cout << "3"; } return 0; }
replace
16
17
16
20
1
p02582
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> #include <vector> using namespace std; int main() { string s; getline(cin, s); vector<int> count; int c = 0; ; for (int i = 0; i < 3; i++) { if (s[i] == 'R') { c++; } else { count.push_back(c); c = 0; } } sort(count.begin(), count.end(), greater<int>()); cout << count[0]; return 0; }
#include <bits/stdc++.h> #include <iostream> #include <vector> using namespace std; int main() { string s; getline(cin, s); vector<int> count; int c = 0; ; for (int i = 0; i < 3; i++) { if (s[i] == 'R') { c++; } else { count.push_back(c); c = 0; } count.push_back(c); } sort(count.begin(), count.end(), greater<int>()); cout << count[0]; return 0; }
insert
17
17
17
18
0
p02582
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <vector> using namespace std; int main(void) { char S[3]; cin >> S; int ans = 0; for (int i = 0; i < 3; ++i) { if (S[i] == 'R') ++ans; } if (ans == 2 && S[1] == 'S') ans = 1; cout << ans; return 0; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <vector> using namespace std; int main(void) { string S; cin >> S; int ans = 0; for (int i = 0; i < 3; ++i) { if (S[i] == 'R') ++ans; } if (ans == 2 && S[1] == 'S') ans = 1; cout << ans; return 0; }
replace
10
11
10
11
0
p02582
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define f first #define s second #define sz size() #define ll long long #define all(_v) _v.begin(), _v.end() #define pii pair<int, int> #define pll pair<ll, ll> #define pvllvll pair<vector<ll>, vector<ll>> #define ld long double #define veci vector<int> #define vecll vector<ll> const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const double PI = 3.1415926535897932384626433832795; const double eps = 1e-9; const int MOD1 = 1e9 + 7; const int MOD2 = 998244353; void solve() { string s; cin >> s; int cnt = 0, ans = 0; for (int i = 0; i < s.sz;) { if (s[i] == 'R') cnt++; else ans = max(ans, cnt), cnt = 0; } cout << max(ans, cnt); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; /// cin >> T; while (T--) solve(), cout << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define f first #define s second #define sz size() #define ll long long #define all(_v) _v.begin(), _v.end() #define pii pair<int, int> #define pll pair<ll, ll> #define pvllvll pair<vector<ll>, vector<ll>> #define ld long double #define veci vector<int> #define vecll vector<ll> const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const double PI = 3.1415926535897932384626433832795; const double eps = 1e-9; const int MOD1 = 1e9 + 7; const int MOD2 = 998244353; void solve() { string s; cin >> s; int cnt = 0, ans = 0; for (int i = 0; i < s.sz; ++i) { if (s[i] == 'R') cnt++; else ans = max(ans, cnt), cnt = 0; } cout << max(ans, cnt); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; /// cin >> T; while (T--) solve(), cout << '\n'; return 0; }
replace
27
28
27
28
TLE
p02582
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define SZ(x) (long long)x.size() #define endl '\n' #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define tc \ int tc; \ cin >> tc; \ while (tc--) #define REP(i, a, b) for (int i = a; i < b; i++) #define REPO(i, b, a) for (int i = b - 1; i >= a; i--) #define REPI(i, a, b) for (int i = a; i <= b; i++) #define MOD 1000000007 bool comp(pair<int, int> v, int val) { return v.ff < val; } inline int read() { int t = 0; char c; while ((c = getchar_unlocked()) != '\n' && c != ' ' && c != EOF) { t = t * 10 + c - 48; } return t; } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; int32_t main() { FAST; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("output.txt", "w", stderr); #endif string S; cin >> S; int i = 1; int ans = 0; while (i < SZ(S)) { if (S[i] == 'R' && S[i - 1] == 'R') ans++; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define SZ(x) (long long)x.size() #define endl '\n' #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define tc \ int tc; \ cin >> tc; \ while (tc--) #define REP(i, a, b) for (int i = a; i < b; i++) #define REPO(i, b, a) for (int i = b - 1; i >= a; i--) #define REPI(i, a, b) for (int i = a; i <= b; i++) #define MOD 1000000007 bool comp(pair<int, int> v, int val) { return v.ff < val; } inline int read() { int t = 0; char c; while ((c = getchar_unlocked()) != '\n' && c != ' ' && c != EOF) { t = t * 10 + c - 48; } return t; } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; int32_t main() { FAST; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("output.txt", "w", stderr); #endif string S; cin >> S; int i = 1; int ans = 0; if (S == "RSR" || S == "RSS" || S == "SSR" || S == "SRS") cout << 1; else if (S == "RRR") cout << 3; else if (S == "RRS" || S == "SRR") cout << 2; else cout << 0; return 0; }
replace
52
57
52
60
TLE
p02582
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("input.txt","r",stdin); string s; cin >> s; int c[3], cnt = 0, j = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == 'R') cnt++; else c[j] = cnt, j++, cnt = 0; } c[j] = cnt, j++; sort(c, c + j); cout << c[j - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("input.txt","r",stdin); string s; cin >> s; int c = 0; if (s == "SRR" || s == "RRS") c = 2; else if (s == "RRR") c = 3; else if (s == "SSR" || s == "SRS" || s == "RSS" || s == "RSR") c = 1; else c = 0; cout << c << endl; return 0; }
replace
12
22
12
22
0
p02582
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { string s; cin >> s; int sum = 0; bool pan = 0; for (int i = 0; i < 3; i++) { if (i = 1 && s[i] == 'R') pan = 1; if (s[i] == 'R' && pan == 1) { sum++; pan = 1; } if (s[i] != 'R') pan = 0; } cout << sum; return 0; }
#include <iostream> using namespace std; int main() { string s; cin >> s; if (s == "RRR") cout << 3; if (s == "RRS") cout << 2; if (s == "SRR") cout << 2; if (s == "RSS") cout << 1; if (s == "SSR") cout << 1; if (s == "SRS") cout << 1; if (s == "RSR") cout << 1; if (s == "SSS") cout << 0; return 0; }
replace
6
19
6
22
TLE
p02582
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int ans; string s; int main() { cin >> s; for (int i = 0, j = 0; i < 3; i = j + 1) { while (s[i] == 'R' && j + 1 < 3 && s[j + 1] == 'R') j++; if (s[i] == 'R') ans = max(ans, j - i + 1); } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int ans; string s; int main() { cin >> s; for (int i = 0, j = 0; i < 3; i = j + 1) { j = i; while (s[i] == 'R' && j + 1 < 3 && s[j + 1] == 'R') j++; if (s[i] == 'R') ans = max(ans, j - i + 1); } printf("%d\n", ans); return 0; }
insert
9
9
9
10
TLE
p02582
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i <= (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { string B; cin >> B; int A = 0; rep(i, 3) { if (B.at(i) == 'R') { A++; if (i == 2) { break; } else { if (B.at(i + 1) == 'R') { A++; if (i == 1) { break; } else { if (B.at(i + 2) == 'R') { A++; break; } else { break; } } } else { break; } } } } cout << A << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i <= (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { string B; cin >> B; int A = 0; rep(i, 3) { if (B.at(i) == 'R') { A++; if (i == 2) { break; } else { if (B.at(i + 1) == 'R') { A++; if (i == 1) { break; } else { if (B.at(i + 2) == 'R') { A++; break; } else { break; } } } else { break; } } } else if (i == 2) { break; } } cout << A << endl; }
insert
31
31
31
33
0
p02582
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { string s; cin >> s; int cnt = 0; vector<int> v; for (int i = 0; i < s.length(); i++) { if (s[i] == 'R') { cnt++; } else { v.push_back(cnt); cnt = 0; } } cout << *max_element(v.begin(), v.end()) << endl; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { string s; cin >> s; int cnt = 0; vector<int> v; for (int i = 0; i < s.length(); i++) { if (s[i] == 'R') { cnt++; if (i == s.length() - 1) { v.push_back(cnt); break; } } else { v.push_back(cnt); cnt = 0; } } cout << *max_element(v.begin(), v.end()) << endl; }
insert
12
12
12
16
0
p02582
C++
Runtime Error
#include <iostream> #include <string> #include <vector> using namespace std; int main(void) { string str; cin >> str; int c = 0; if (str == "SSS") c = 0; else if (str == "SSR") c = 1; else if (str == "SRS") c = 1; else if (str == "SRR") c = 2; else if (str == "RSS") c = 1; else if (str == "RSR") c = 1; else if (str == "RRS") c = 2; else if (str == "RRR") c = 3; cout << c << endl; return 1; }
#include <iostream> #include <string> #include <vector> using namespace std; int main(void) { string str; cin >> str; int c = 0; if (str == "SSS") c = 0; else if (str == "SSR") c = 1; else if (str == "SRS") c = 1; else if (str == "SRR") c = 2; else if (str == "RSS") c = 1; else if (str == "RSR") c = 1; else if (str == "RRS") c = 2; else if (str == "RRR") c = 3; cout << c << endl; }
delete
29
31
29
29
1
p02582
C++
Runtime Error
#include <iostream> int main() { char a[3]; std::cin >> a; bool _1 = a[0] == 'R'; bool _2 = a[1] == 'R'; bool _3 = a[2] == 'R'; if (_1 && _2 && _3) { std::cout << '3' << std::endl; } else if ((_1 && _2) || (_2 && _3)) { std::cout << '2' << std::endl; } else if (_1 || _2 || _3) { std::cout << '1' << std::endl; } else { std::cout << '0' << std::endl; } return 1; }
#include <iostream> int main() { char a[3]; std::cin >> a; bool _1 = a[0] == 'R'; bool _2 = a[1] == 'R'; bool _3 = a[2] == 'R'; if (_1 && _2 && _3) { std::cout << '3' << std::endl; } else if ((_1 && _2) || (_2 && _3)) { std::cout << '2' << std::endl; } else if (_1 || _2 || _3) { std::cout << '1' << std::endl; } else { std::cout << '0' << std::endl; } return 0; }
replace
19
20
19
20
1
p02582
C++
Runtime Error
#include <iostream> #include <string> #include <vector> using namespace std; int main() { string str; int i, c; i = c = 0; cin >> str; while (1) { if (str[i] == 'R') { c += 1; } if (c != 0 && str[i] == 'S') { break; } i += 1; } cout << c << endl; }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { string str; int i, c; i = c = 0; cin >> str; while (1) { if (i >= 3) { break; } if (str[i] == 'R') { c += 1; } if (c != 0 && str[i] == 'S') { break; } i += 1; } cout << c << endl; }
insert
12
12
12
15
0
p02582
Python
Runtime Error
s = input() cnt = 0 L = [] for i in s: if i == "R": cnt += 1 else: L.append(cnt) cnt = 0 print(max(L))
s = input() cnt = 0 L = [] for i in s: if i == "R": cnt += 1 else: L.append(cnt) cnt = 0 L.append(cnt) print(max(L))
replace
10
11
10
11
0
p02582
C++
Runtime Error
// list index out of rangeエラー表示用 #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep1(i, n) for (int i = 0; i < (int)(n); i++) int main() { string s; cin >> s; int n = 3; int tem = 0; vector<int> lan(0); for (int l = 0; l < n;) { int r = 0; for (; l + r < n && s[l] == s[l + r]; r++) { } if (s[l] == 'R') { lan.push_back(r); } l += r; r = 0; } cout << *max_element(lan.begin(), lan.end()); }
// list index out of rangeエラー表示用 #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep1(i, n) for (int i = 0; i < (int)(n); i++) int main() { string s; cin >> s; int n = 3; int tem = 0; vector<int> lan(0); for (int l = 0; l < n;) { int r = 0; for (; l + r < n && s[l] == s[l + r]; r++) { } if (s[l] == 'R') { lan.push_back(r); } l += r; r = 0; } lan.push_back(0); cout << *max_element(lan.begin(), lan.end()); }
insert
22
22
22
23
0
p02582
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define MoD 1e9 + 7 #define clear(a) memset(a, 0, sizeof(a)) #define fo(i, a, b) for (int i = a; i < b; i++) #define re(i, a, b) for (int i = b; i > a; i--) #define pb(a) push_back(a) 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; } int n; string s; void solve() { cin >> s; s += "."; int ans = 0; vector<int> v; fo(i, 0, 3) { if (s[i] == 'R') ans++; else { v.pb(ans); ans = 0; } } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); cout << v[0] << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; for (int i = 1; i <= t; ++i) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define MoD 1e9 + 7 #define clear(a) memset(a, 0, sizeof(a)) #define fo(i, a, b) for (int i = a; i < b; i++) #define re(i, a, b) for (int i = b; i > a; i--) #define pb(a) push_back(a) 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; } int n; string s; void solve() { cin >> s; s += "."; int ans = 0; vector<int> v; fo(i, 0, 4) { if (s[i] == 'R') ans++; else { v.pb(ans); ans = 0; } } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); cout << v[0] << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; for (int i = 1; i <= t; ++i) { solve(); } }
replace
29
30
29
30
0
p02582
Python
Runtime Error
S = int(input()) flag = False ans = 0 for i in range(len(S)): if S[i] == "R": ans += 1 flag = True elif S[i] == "S" and flag: break print(ans)
S = input() flag = False ans = 0 for i in range(len(S)): if S[i] == "R": ans += 1 flag = True elif S[i] == "S" and flag: break print(ans)
replace
0
1
0
1
ValueError: invalid literal for int() with base 10: 'RRS'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02582/Python/s302046269.py", line 1, in <module> S = int(input()) ValueError: invalid literal for int() with base 10: 'RRS'
p02582
Python
Runtime Error
S = input() rain_d = 0 for s in S: if s == "R": rain_d += 1 max_rain_d = rain_d elif s == "S": rain_d = 0 print(max_rain_d)
S = input() rain_d = 0 max_rain_d = 0 for s in S: if s == "R": rain_d += 1 max_rain_d = rain_d elif s == "S": rain_d = 0 print(max_rain_d)
insert
2
2
2
3
0
p02582
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int count = 0; int i; for (i = 0; i < s.length();) { if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') count = 3; else if (s[0] == 'R' && s[1] == 'R' && s[2] == 'S') count = 2; else if (s[0] == 'R' && s[1] == 'S' && s[2] == 'R') count = 1; else if (s[0] == 'S' && s[1] == 'R' && s[2] == 'R') count = 2; else if (s[0] == 'S' && s[1] == 'R' && s[2] == 'S') count = 1; else if (s[0] == 'S' && s[1] == 'S' && s[2] == 'S') count = 0; else if (s[0] == 'S' && s[1] == 'S' && s[2] == 'R') count = 1; else if (s[0] == 'R' && s[1] == 'S' && s[2] == 'S') count = 1; } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int count = 0; int i; if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') count = 3; else if (s[0] == 'R' && s[1] == 'R' && s[2] == 'S') count = 2; else if (s[0] == 'R' && s[1] == 'S' && s[2] == 'R') count = 1; else if (s[0] == 'S' && s[1] == 'R' && s[2] == 'R') count = 2; else if (s[0] == 'S' && s[1] == 'R' && s[2] == 'S') count = 1; else if (s[0] == 'S' && s[1] == 'S' && s[2] == 'S') count = 0; else if (s[0] == 'S' && s[1] == 'S' && s[2] == 'R') count = 1; else if (s[0] == 'R' && s[1] == 'S' && s[2] == 'S') count = 1; cout << count << endl; return 0; }
replace
8
26
8
24
TLE
p02582
Python
Runtime Error
# -*- coding: utf-8 -*- s = input() maxs = 0 ans = [] for a in s: if a == "R": maxs += 1 else: ans.append(maxs) maxs = 0 print(max(ans))
# -*- coding: utf-8 -*- s = input() maxs = 0 ans = [] for a in s: if a == "R": maxs += 1 else: ans.append(maxs) maxs = 0 ans.append(maxs) print(max(ans))
insert
13
13
13
14
0
p02582
Python
Runtime Error
s = input() if "RRR" in s: ans = 3 elif "RR" in s: ans = 2 elif "R" in s: ans = 1 print(ans)
s = input() if "RRR" in s: ans = 3 elif "RR" in s: ans = 2 elif "R" in s: ans = 1 else: ans = 0 print(ans)
insert
8
8
8
10
0
p02582
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> // #include <boost/math/common_factor.hpp> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pair<int, int>> vpii; typedef vector<pair<ll, ll>> vpll; #define all(x) x.begin(), x.end() #define reg(i, x) for (ll i = 0; i < x; i++) #define regi(i, a, x) for (ll i = a; i < x; i++) #define rev(i, n) for (ll i = n - 1; i > 0; i--) #define pb push_back #define lb lower_bound #define ub upper_bound // const ll INF = 1e18; const int INF = 1e9; const int MOD = 1e9 + 7; const int nax = 1000000 + 10; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int lcm(int a, int b) { return (a * b) / gcd(a, b); } ll MAXN = 10e9; int main() { string s; cin >> s; vi v; int cnt = 0; reg(i, s.size()) { if (s[i] == 'R') cnt++; else { if (cnt != 0) v.pb(cnt); cnt = 0; } } if (cnt != 0) v.pb(cnt); cout << *max_element(all(v)) << endl; }
#include <bits/stdc++.h> #include <iostream> // #include <boost/math/common_factor.hpp> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pair<int, int>> vpii; typedef vector<pair<ll, ll>> vpll; #define all(x) x.begin(), x.end() #define reg(i, x) for (ll i = 0; i < x; i++) #define regi(i, a, x) for (ll i = a; i < x; i++) #define rev(i, n) for (ll i = n - 1; i > 0; i--) #define pb push_back #define lb lower_bound #define ub upper_bound // const ll INF = 1e18; const int INF = 1e9; const int MOD = 1e9 + 7; const int nax = 1000000 + 10; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int lcm(int a, int b) { return (a * b) / gcd(a, b); } ll MAXN = 10e9; int main() { string s; cin >> s; vi v; int cnt = 0; v.pb(0); reg(i, s.size()) { if (s[i] == 'R') cnt++; else { if (cnt != 0) v.pb(cnt); cnt = 0; } } if (cnt != 0) v.pb(cnt); cout << *max_element(all(v)) << endl; }
insert
34
34
34
35
0
p02582
Python
Runtime Error
s = input() ans = s.index("S") print(ans)
s = input() if "RRR" in s: print(3) elif "RR" in s: print(2) elif "R" in s: print(1) else: print(0)
replace
2
5
2
10
0
p02582
Python
Runtime Error
S = input() R = [] r = 0 for s in S: if s == "R": r += 1 if s == "S": R.append(r) r = 0 print(max(R))
S = input() R = [] r = 0 for s in S: if s == "R": r += 1 if s == "S": R.append(r) r = 0 R.append(r) print(max(R))
insert
10
10
10
11
0
p02582
C++
Runtime Error
#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; #define ff first #define ss second #define ld long double #define ll long long int #define ull unsigned ll #define ins insert #define pb emplace_back #define vi vector<int> #define vll vector<ll> #define vvi vector<vi> #define vvll vector<vll> #define pii pair<int, int> #define pll pair<ll, ll> #define sz(a) (ll) a.size() #define all(a) a.begin(), a.end() #define fo(i, a, b) for (i = a; i < b; ++i) #define foe(i, a, b) for (i = a; i <= b; ++i) #define rep(i, n) for (i = 0; i < n; i++) #define rep1(i, n) for (i = 1; i <= n; i++) #define per(i, n) for (i = n - 1; i >= 0; i--) #define per1(i, n) for (i = n; i >= 1; i--) #define mod 1000000007 #define pi 3.141592653589793238460 #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(0) // #define pbds tree<int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; // use cerr if u want to display at the bottom } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif int main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t, i, j; t = 1; while (t--) { ll n, k; string s; cin >> s; s = s + "P"; vi v; for (i = 0; i < 3; i++) { ll cnt = 0; if (s[i] == 'R') { cnt++; while (s[i + 1] == 'R' && i < 3) { i++; cnt++; } v.pb(cnt); } } cout << *max_element(all(v)) << '\n'; } 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; #define ff first #define ss second #define ld long double #define ll long long int #define ull unsigned ll #define ins insert #define pb emplace_back #define vi vector<int> #define vll vector<ll> #define vvi vector<vi> #define vvll vector<vll> #define pii pair<int, int> #define pll pair<ll, ll> #define sz(a) (ll) a.size() #define all(a) a.begin(), a.end() #define fo(i, a, b) for (i = a; i < b; ++i) #define foe(i, a, b) for (i = a; i <= b; ++i) #define rep(i, n) for (i = 0; i < n; i++) #define rep1(i, n) for (i = 1; i <= n; i++) #define per(i, n) for (i = n - 1; i >= 0; i--) #define per1(i, n) for (i = n; i >= 1; i--) #define mod 1000000007 #define pi 3.141592653589793238460 #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(0) // #define pbds tree<int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; // use cerr if u want to display at the bottom } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif int main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t, i, j; t = 1; while (t--) { ll n, k; string s; cin >> s; s = s + "P"; vi v; for (i = 0; i < 3; i++) { ll cnt = 0; if (s[i] == 'R') { cnt++; while (s[i + 1] == 'R' && i < 3) { i++; cnt++; } v.pb(cnt); } } if (sz(v) == 0) cout << 0 << '\n'; else cout << *max_element(all(v)) << '\n'; } return 0; }
replace
77
78
77
81
-11
p02583
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <cstdint> #include <cstdio> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_set> #include <vector> #pragma GCC optimize("Ofast") using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef vector<vector<int>> vvi; typedef vector<vector<char>> vvc; typedef vector<vector<string>> vvs; typedef vector<vector<ll>> vvll; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define mes(a) cout << (a) << endl #define dmes(a, b) cout << (a) << " " << (b) << endl #define re0 return 0 #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define rSort(a) sort(a.rbegin(), a.rend()) #define MATHPI acos(-1) #define itn int int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; 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; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-19; signed main() { ll n; cin >> n; ll cnt = 0; vll l(n); rep(i, n) { cin >> l[i]; } // 各 p の値に対して Sort(l); rep(i, l.size() - 2) { for (ll j = i + 1; j < l.size() - 1; j++) { for (ll k = j + 1; k < l.size(); k++) { if (l[i] == l[j] || l[j] == l[k]) continue; if (l[i] + l[j] > l[k]) cnt++; } } } mes(cnt); }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <cstdint> #include <cstdio> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_set> #include <vector> #pragma GCC optimize("Ofast") using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef vector<vector<int>> vvi; typedef vector<vector<char>> vvc; typedef vector<vector<string>> vvs; typedef vector<vector<ll>> vvll; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define mes(a) cout << (a) << endl #define dmes(a, b) cout << (a) << " " << (b) << endl #define re0 return 0 #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define rSort(a) sort(a.rbegin(), a.rend()) #define MATHPI acos(-1) #define itn int int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; 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; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-19; signed main() { ll n; cin >> n; ll cnt = 0; vll l(n); rep(i, n) { cin >> l[i]; } // 各 p の値に対して Sort(l); rep(i, n - 2) { for (ll j = i + 1; j < n - 1; j++) { for (ll k = j + 1; k < n; k++) { if (l[i] == l[j] || l[j] == l[k]) continue; if (l[i] + l[j] > l[k]) cnt++; } } } mes(cnt); }
replace
89
92
89
92
TLE
p02583
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; // using ll = long long; int main() { ios::sync_with_stdio(false); int N; cin >> N; vector<int> L(N); rep(i, N) cin >> L[i]; sort(L.begin(), L.end()); int ans = 0; for (int i = 0; i < L.size() - 2; i++) { for (int j = i + 1; j < L.size() - 1; j++) { if (L[i] == L[j]) continue; auto itel = upper_bound(L.begin(), L.end(), L[j]); int l = itel - L.begin(); auto ite = lower_bound(L.begin(), L.end(), L[i] + L[j]); int r = ite - L.begin(); // cerr << l << " " << r << endl; ans += r - l; } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; // using ll = long long; int main() { ios::sync_with_stdio(false); int N; cin >> N; vector<int> L(N); if (N < 3) { cout << 0 << endl; return 0; } rep(i, N) cin >> L[i]; sort(L.begin(), L.end()); int ans = 0; for (int i = 0; i < L.size() - 2; i++) { for (int j = i + 1; j < L.size() - 1; j++) { if (L[i] == L[j]) continue; auto itel = upper_bound(L.begin(), L.end(), L[j]); int l = itel - L.begin(); auto ite = lower_bound(L.begin(), L.end(), L[i] + L[j]); int r = ite - L.begin(); // cerr << l << " " << r << endl; ans += r - l; } } cout << ans << endl; }
insert
11
11
11
15
TLE
p02583
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define pb push_back typedef long long ll; #define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n' const int inf = 1e9 + 7; const int N = 1e6 + 9; int main() { ios_base::sync_with_stdio(0); int a, b, n; cin >> n; // set<int> st; vector<int> v; for (int i = 0; i < n; ++i) { cin >> a; // st.insert(a); v.pb(a); } // for(int p: st) { // v.pb(p); // } sort(v.begin(), v.end()); int cnt = 0; for (int i = 0; i < v.size(); ++i) { // cout<<v[i]<<endl; for (int j = i + 1; j < v.size(); ++j) if (v[j] != v[i]) { for (int k = j + 1; k < v.size(); ++k) if (v[k] != v[i] && v[k] != v[j]) { if (v[i] + v[j] > v[k]) { cerr << v[i] << " " << v[j] << " " << v[k] << endl; cerr << " " << i + 1 << " " << j + 1 << " " << k + 1 << endl; ++cnt; } } } } cout << cnt << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define pb push_back typedef long long ll; #define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n' const int inf = 1e9 + 7; const int N = 1e6 + 9; int main() { ios_base::sync_with_stdio(0); int a, b, n; cin >> n; // set<int> st; vector<int> v; for (int i = 0; i < n; ++i) { cin >> a; // st.insert(a); v.pb(a); } // for(int p: st) { // v.pb(p); // } sort(v.begin(), v.end()); int cnt = 0; for (int i = 0; i < v.size(); ++i) { // cout<<v[i]<<endl; for (int j = i + 1; j < v.size(); ++j) if (v[j] != v[i]) { for (int k = j + 1; k < v.size(); ++k) if (v[k] != v[i] && v[k] != v[j]) { if (v[i] + v[j] > v[k]) { // cerr<<v[i]<<" "<<v[j]<<" "<<v[k]<<endl; // cerr<<" "<<i+1<<" "<<j+1<<" "<<k+1<<endl; ++cnt; } } } } cout << cnt << endl; return 0; }
replace
33
35
33
35
TLE
p02583
C++
Runtime Error
#pragma GCC optimize(2) #include <bits/stdc++.h> #define MIN -10000000 #define MAX 10000000 #define debug printf("%d", __LINE__) using namespace std; long long a[114511141]; int main() { int n; scanf("%d", &n); int cnt = 0; if (n < 3) return printf("0"); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) for (int k = j + 1; k <= n; k++) if (a[i] != a[j] && a[j] != a[k] && a[i] != a[k]) if (a[i] + a[j] > a[k]) if (a[i] + a[k] > a[j]) if (a[j] + a[k] > a[i]) cnt++; printf("%d", cnt); return 0; }
#pragma GCC optimize(2) #include <bits/stdc++.h> #define MIN -10000000 #define MAX 10000000 #define debug printf("%d", __LINE__) using namespace std; long long a[114511141]; int main() { int n; scanf("%d", &n); int cnt = 0; if (n < 3) return printf("0"), 0; for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) for (int k = j + 1; k <= n; k++) if (a[i] != a[j] && a[j] != a[k] && a[i] != a[k]) if (a[i] + a[j] > a[k]) if (a[i] + a[k] > a[j]) if (a[j] + a[k] > a[i]) cnt++; printf("%d", cnt); return 0; }
replace
12
13
12
13
-11
p02583
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; int main() { int N; cin >> N; vector<ull> L(N); for (int i = 0; i < N; i++) cin >> L.at(i); ull a = 0, b = 0, c = 0, cnt = 0; for (int i = 0; i < N - 2; i++) { for (int j = i + 1; j < N - 1; j++) { for (int k = j + 1; k < N; k++) { a = L.at(i); b = L.at(j); c = L.at(k); if ((a + b > c) && (b + c > a) && (c + a > b) && (L.at(i) != L.at(j)) && (L.at(j) != L.at(k)) && (L.at(k) != L.at(i))) { cerr << i + 1 << " " << j + 1 << " " << k + 1 << endl; cerr << L.at(i) << " " << L.at(j) << " " << L.at(k) << endl; cerr << a << " " << b << " " << c << endl; cnt++; } } } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; int main() { int N; cin >> N; vector<ull> L(N); for (int i = 0; i < N; i++) cin >> L.at(i); ull a = 0, b = 0, c = 0, cnt = 0; for (int i = 0; i < N - 2; i++) { for (int j = i + 1; j < N - 1; j++) { for (int k = j + 1; k < N; k++) { a = L.at(i); b = L.at(j); c = L.at(k); if ((a + b > c) && (b + c > a) && (c + a > b) && (L.at(i) != L.at(j)) && (L.at(j) != L.at(k)) && (L.at(k) != L.at(i))) { // cerr << i+1 << " " << j+1 << " " << k+1 << endl; // cerr << L.at(i) << " " << L.at(j) << " " << // L.at(k) << endl; cerr << a << " " << b << " " << // c << endl; cnt++; } } } } cout << cnt << endl; return 0; }
replace
24
27
24
28
TLE
p02583
C++
Time Limit Exceeded
// C #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> // #include <cstdalign> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif using namespace std; typedef long long int ll; typedef unsigned long long ull; typedef long double ld; #define REP(i, n) for (ll i = 0; i < (n); i++) #define REPR(i, n) for (ll i = n; i >= 0; i--) #define FOR(i, m, n) for (ll i = m; i < n; i++) #define ALL(n) begin(n), end(n) #define IN(a, x, b) (a <= x && x < b) #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); template <class T> inline T CHMAX(T &a, const T b) { return a = (a < b) ? b : a; } template <class T> inline T CHMIN(T &a, const T b) { return a = (a > b) ? b : a; } const long double EPS = 1e-10; const long long INF = 1e18; const long double PI = acos(-1.0L); const long long MOD = 1000000007; int main(void) { ll n; cin >> n; vector<ll> input; REP(i, n) { ll tmp; cin >> tmp; input.push_back(tmp); } ll ans = 0; for (ll i = 0; i < input.size() - 2; i++) { for (ll j = i + 1; j < input.size() - 1; j++) { for (ll k = j + 1; k < input.size(); k++) { if (input[i] == input[j] || input[j] == input[k] || input[k] == input[i]) { continue; } if (input[i] < input[k] + input[j]) { if (input[k] < input[i] + input[j]) { if (input[j] < input[k] + input[i]) { ans++; } } } } } } cout << ans << endl; return 0; }
// C #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> // #include <cstdalign> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif using namespace std; typedef long long int ll; typedef unsigned long long ull; typedef long double ld; #define REP(i, n) for (ll i = 0; i < (n); i++) #define REPR(i, n) for (ll i = n; i >= 0; i--) #define FOR(i, m, n) for (ll i = m; i < n; i++) #define ALL(n) begin(n), end(n) #define IN(a, x, b) (a <= x && x < b) #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); template <class T> inline T CHMAX(T &a, const T b) { return a = (a < b) ? b : a; } template <class T> inline T CHMIN(T &a, const T b) { return a = (a > b) ? b : a; } const long double EPS = 1e-10; const long long INF = 1e18; const long double PI = acos(-1.0L); const long long MOD = 1000000007; int main(void) { ll n; cin >> n; vector<ll> input; REP(i, n) { ll tmp; cin >> tmp; input.push_back(tmp); } ll ans = 0; if (n < 3) { cout << 0 << endl; return 0; } for (ll i = 0; i < input.size() - 2; i++) { for (ll j = i + 1; j < input.size() - 1; j++) { for (ll k = j + 1; k < input.size(); k++) { if (input[i] == input[j] || input[j] == input[k] || input[k] == input[i]) { continue; } if (input[i] < input[k] + input[j]) { if (input[k] < input[i] + input[j]) { if (input[j] < input[k] + input[i]) { ans++; } } } } } } cout << ans << endl; return 0; }
insert
122
122
122
126
TLE
p02583
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int ans = 0; for (int i = 0; i < n - 2; i++) { for (int j = i + 1; j < n - 1; j++) { for (int k = j + 1; j < n; k++) { if (a[i] + a[j] > a[k]) { ans++; } } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int ans = 0; for (int i = 0; i < n - 2; i++) { for (int j = i + 1; j < n - 1; j++) { for (int k = j + 1; k < n; k++) { if (a[i] + a[j] > a[k] && a[i] != a[j] && a[i] != a[k] && a[j] != a[k]) { ans++; } } } } cout << ans << endl; }
replace
14
16
14
17
TLE
p02583
C++
Time Limit Exceeded
#include <bits/stdc++.h> typedef long long ll; // forループ // 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか // Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる #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 int long long using namespace std; int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: return 0; } } ll a, b, c, s, t, x, y, z; ll A, B, C, S, T, X, Y, Z; ll cnt; long double pi = 3.14159265358979323846; string N, M; unsigned long long D; signed main() { cin >> a; vector<int> f(a); REP(i, a) cin >> f[i]; // cout << f.size() << endl; for (x = 0; x < f.size() - 2; x++) { for (y = x + 1; y < f.size() - 1; y++) { for (z = y + 1; z < f.size(); z++) { if (f[x] != f[y] && f[y] != f[z] && f[x] != f[z] && f[x] + f[y] > f[z] && f[z] + f[y] > f[x] && f[x] + f[z] > f[y]) { cnt++; } } } } cout << cnt << endl; ; return 0; }
#include <bits/stdc++.h> typedef long long ll; // forループ // 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか // Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる #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 int long long using namespace std; int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: return 0; } } ll a, b, c, s, t, x, y, z; ll A, B, C, S, T, X, Y, Z; ll cnt; long double pi = 3.14159265358979323846; string N, M; unsigned long long D; signed main() { cin >> a; vector<int> f(a); REP(i, a) cin >> f[i]; // cout << f.size() << endl; for (x = 0; x < a - 2; x++) { for (y = x + 1; y < a - 1; y++) { for (z = y + 1; z < a; z++) { if (f[x] != f[y] && f[y] != f[z] && f[x] != f[z] && f[x] + f[y] > f[z] && f[z] + f[y] > f[x] && f[x] + f[z] > f[y]) { cnt++; } } } } cout << cnt << endl; ; return 0; }
replace
64
67
64
67
TLE
p02583
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES #include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <set> #include <stdlib.h> #include <string> #include <vector> using namespace std; int main() { int N; vector<int> L; cin >> N; L.resize(N); for (int i = 0; i < N; i++) { cin >> L[i]; } sort(L.begin(), L.end()); int count = 0; for (int i = 0; i < L.size() - 2; i++) { for (int k = i + 1; k < L.size() - 1; k++) { if (L[i] == L[k]) continue; for (int n = k + 1; n < L.size(); n++) { if (L[k] == L[n]) continue; if (L[i] + L[k] > L[n]) { count++; } else { break; } } } } cout << count << endl; return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <set> #include <stdlib.h> #include <string> #include <vector> using namespace std; int main() { int N; vector<int> L; cin >> N; L.resize(N); for (int i = 0; i < N; i++) { cin >> L[i]; } sort(L.begin(), L.end()); int count = 0; for (int i = 0; i < L.size(); i++) { for (int k = i + 1; k < L.size(); k++) { if (L[i] == L[k]) continue; for (int n = k + 1; n < L.size(); n++) { if (L[k] == L[n]) continue; if (L[i] + L[k] > L[n]) { count++; } else { break; } } } } cout << count << endl; return 0; }
replace
33
35
33
35
TLE
p02583
C++
Time Limit Exceeded
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define int long long #define ld long double #define x first #define y second #define mp make_pair #define pb push_back #define rt return #define yy cout < "Yes\n" #define nn cout << "No\n" #define er erase #define cl clear #define bg begin #define bk break #define ct continue using namespace std; struct st {}; bool cmp() { return 1; } int go() { return 0; } void recur() {} void solve() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = j + 1; k < n; j++) { if (a[i] + a[j] > a[k]) ans++; } } } cout << ans; } signed main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin>>t; while (t--) solve(); }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define int long long #define ld long double #define x first #define y second #define mp make_pair #define pb push_back #define rt return #define yy cout < "Yes\n" #define nn cout << "No\n" #define er erase #define cl clear #define bg begin #define bk break #define ct continue using namespace std; struct st {}; bool cmp() { return 1; } int go() { return 0; } void recur() {} void solve() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int ans = 0; for (int i = 0; i < n - 2; i++) { for (int j = i + 1; j < n - 1; j++) { for (int k = j + 1; k < n; k++) { if (a[i] == a[j] || a[j] == a[k] || a[i] == a[k]) continue; if (a[i] + a[j] > a[k]) ans++; } } } cout << ans; } signed main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin>>t; while (t--) solve(); }
replace
31
34
31
36
TLE
p02583
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; long int cnt = 0; for (int i = 0; i < n; i++) for (int j = i + 1; i < n; j++) for (int k = j + 1; k < n; k++) { if (arr[i] != arr[j] && arr[i] != arr[k] && arr[j] != arr[k]) { if (arr[i] + arr[j] > arr[k] && arr[i] + arr[k] > arr[j] && arr[j] + arr[k] > arr[i]) cnt++; } } cout << cnt; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; long int cnt = 0; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) for (int k = j + 1; k < n; k++) { if (arr[i] != arr[j] && arr[i] != arr[k] && arr[j] != arr[k]) { if (arr[i] + arr[j] > arr[k] && arr[i] + arr[k] > arr[j] && arr[j] + arr[k] > arr[i]) cnt++; } } cout << cnt; }
replace
10
11
10
11
TLE
p02583
C++
Runtime Error
#include <algorithm> #include <array> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int64_t N; cin >> N; vector<int64_t> L(N); if (N < 3) { cout << 0; return 0; } for (int64_t i = 0; i < N; i++) { cin >> L.at(i); } sort(L.begin(), L.end()); int64_t cnt = 0; for (int64_t i = 0; i < N; i++) { for (int64_t j = i + 1; j < N; j++) { if (L.at(i) == L.at(j)) { continue; } for (int64_t k = j + 1; k < N; j++) { if (L.at(i) == L.at(k) or L.at(j) == L.at(k)) { continue; } if (L.at(i) + L.at(j) > L.at(k) and L.at(j) + L.at(k) > L.at(i) and L.at(k) + L.at(i) > L.at(j)) { cnt++; } } } } cout << cnt; return 0; }
#include <algorithm> #include <array> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int64_t N; cin >> N; vector<int64_t> L(N); if (N < 3) { cout << 0; return 0; } for (int64_t i = 0; i < N; i++) { cin >> L.at(i); } sort(L.begin(), L.end()); int64_t cnt = 0; for (int64_t i = 0; i < N; i++) { for (int64_t j = i + 1; j < N; j++) { if (L.at(i) == L.at(j)) { continue; } for (int64_t k = j + 1; k < N; k++) { if (L.at(i) == L.at(k) or L.at(j) == L.at(k)) { continue; } if (L.at(i) + L.at(j) > L.at(k) and L.at(j) + L.at(k) > L.at(i) and L.at(k) + L.at(i) > L.at(j)) { cnt++; } } } } cout << cnt; return 0; }
replace
31
32
31
32
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
p02583
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> L(N); for (int i = 0; i < N; i++) { cin >> L.at(i); } sort(L.begin(), L.end()); long long int ans = 0; for (int i = 0; i < L.size() - 2; i++) { for (int j = i + 1; j < L.size() - 1; j++) { for (int k = j + 1; k < L.size(); k++) { vector<long long int> l(3); l.at(0) = L.at(i); l.at(1) = L.at(j); l.at(2) = L.at(k); sort(l.begin(), l.end()); if (l.at(0) == l.at(1) || l.at(1) == l.at(2)) { continue; } else if (l.at(2) < l.at(0) + l.at(1)) { ans++; } else { break; } } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> L(N); for (int i = 0; i < N; i++) { cin >> L.at(i); } sort(L.begin(), L.end()); long long int ans = 0; for (int i = 0; i < N - 2; i++) { for (int j = i + 1; j < N - 1; j++) { for (int k = j + 1; k < N; k++) { vector<long long int> l(3); l.at(0) = L.at(i); l.at(1) = L.at(j); l.at(2) = L.at(k); sort(l.begin(), l.end()); if (l.at(0) == l.at(1) || l.at(1) == l.at(2)) { continue; } else if (l.at(2) < l.at(0) + l.at(1)) { ans++; } else { break; } } } } cout << ans << endl; }
replace
15
18
15
18
TLE
p02583
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0; int L[n]; cin >> n; for (int i = 0; i < n; i++) { cin >> L[i]; } if (n < 3) { cout << count << endl; } else { for (int i = 0; i < n - 2; i++) { for (int j = 1; j < n - 1; j++) { for (int k = 2; k < n; k++) { if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) { if (i < j && j < k && i < k) { if (L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j]) { count++; } } } } } } cout << count << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0; int L[n]; cin >> n; for (int i = 0; i < n; i++) { cin >> L[i]; } if (n < 3) { cout << count << endl; } else { for (int i = 0; i < n - 2; i++) { for (int j = 1; j < n - 1; j++) { for (int k = 2; k < n; k++) { if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) { if (i < j && j < k) { if (L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j]) { count++; } } } } } } cout << count << endl; } return 0; }
replace
17
18
17
18
-11
p02583
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> L; for (int i = 0; i < N; i++) { cin >> L[i]; } int cnt = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if (L[i] != L[j]) { for (int k = j + 1; k < N; k++) { if (L[i] != L[k] && L[j] != L[k]) { if (L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[j] + L[k] > L[i]) { cnt++; } } } } } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int L[100]; for (int i = 0; i < N; i++) { cin >> L[i]; } int cnt = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if (L[i] != L[j]) { for (int k = j + 1; k < N; k++) { if (L[i] != L[k] && L[j] != L[k]) { if (L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[j] + L[k] > L[i]) { cnt++; } } } } } } cout << cnt << endl; return 0; }
replace
5
6
5
6
-11
p02583
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < int(N); ++i) using ll = long long; const int INF = 2147483647; const ll MOD = 1e9 + 7; // const ll INF = 1000000000000000000LL; int main() { int n; cin >> n; vector<ll> l(n); rep(i, n) cin >> l[i]; sort(l.begin(), l.end()); ll cnt = 0; for (ll i = 0; i < l.size() - 2; i++) { for (ll j = i + 1; j < l.size() - 1; j++) { for (ll k = j + 1; k < l.size(); k++) { if (l[i] == l[j] || l[j] == l[k]) continue; if (l[i] + l[j] > l[k]) cnt++; if (l[i] + l[j] <= l[k]) break; } } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < int(N); ++i) using ll = long long; const int INF = 2147483647; const ll MOD = 1e9 + 7; // const ll INF = 1000000000000000000LL; int main() { int n; cin >> n; vector<ll> l(n); rep(i, n) cin >> l[i]; sort(l.begin(), l.end()); ll cnt = 0; for (ll i = 0; i < l.size(); i++) { for (ll j = i + 1; j < l.size(); j++) { for (ll k = j + 1; k < l.size(); k++) { if (l[i] == l[j] || l[j] == l[k]) continue; if (l[i] + l[j] > l[k]) cnt++; if (l[i] + l[j] <= l[k]) break; } } } cout << cnt << endl; return 0; }
replace
15
17
15
17
TLE
p02583
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < int(N); ++i) using ll = long long; const int INF = 2147483647; const ll MOD = 1e9 + 7; // const ll INF = 1000000000000000000LL; int main() { int n; cin >> n; vector<ll> l(n); rep(i, n) cin >> l[i]; sort(l.begin(), l.end()); ll cnt = 0; for (ll i = 0; i < l.size() - 2; i++) { for (ll j = i + 1; j < l.size(); j++) { for (ll k = j + 1; k < l.size(); k++) { if (l[i] == l[j] || l[j] == l[k]) continue; if (l[i] + l[j] > l[k]) cnt++; if (l[i] + l[j] <= l[k]) break; } } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < int(N); ++i) using ll = long long; const int INF = 2147483647; const ll MOD = 1e9 + 7; // const ll INF = 1000000000000000000LL; int main() { int n; cin >> n; vector<ll> l(n); rep(i, n) cin >> l[i]; sort(l.begin(), l.end()); ll cnt = 0; for (ll i = 0; i < l.size(); i++) { for (ll j = i + 1; j < l.size() - 1; j++) { for (ll k = j + 1; k < l.size(); k++) { if (l[i] == l[j] || l[j] == l[k]) continue; if (l[i] + l[j] > l[k]) cnt++; if (l[i] + l[j] <= l[k]) break; } } } cout << cnt << endl; return 0; }
replace
15
17
15
17
TLE
p02583
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; #define debug(a) cerr << #a << ": " << a << endl #define sz(a) int(a.size()) #define rep(i, n) for (int i = 0; i < n; i++) #define forr(i, st, en) for (int i = st; i <= en; i++) #define all(v) (v).begin(), (v).end() #define X first #define Y second #define pb push_back #define fast \ cin.tie(0); \ ios::sync_with_stdio(false) #define vi vector<int> #define vii vector<vector<int>> #define int long long int32_t main() { fast; int n; cin >> n; vi a(n); rep(i, n) { cin >> a[i]; } sort(all(a)); int answer = 0; rep(i, n) { rep(j, n) { rep(k, n) { if (i < j && j < k && a[i] != a[j] && a[j] != a[k] && a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i]) { debug(i); debug(j); debug(k); answer++; } } } } cout << answer << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define debug(a) cerr << #a << ": " << a << endl #define sz(a) int(a.size()) #define rep(i, n) for (int i = 0; i < n; i++) #define forr(i, st, en) for (int i = st; i <= en; i++) #define all(v) (v).begin(), (v).end() #define X first #define Y second #define pb push_back #define fast \ cin.tie(0); \ ios::sync_with_stdio(false) #define vi vector<int> #define vii vector<vector<int>> #define int long long int32_t main() { fast; int n; cin >> n; vi a(n); rep(i, n) { cin >> a[i]; } sort(all(a)); int answer = 0; for (int i = 0; i < n - 2; i++) { for (int j = i + 1; j < n - 1; j++) { for (int k = j + 1; k < n; k++) { if (a[i] != a[j] && a[j] != a[k] && a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i]) { answer++; } } } } cout << answer << endl; }
replace
25
33
25
30
TLE
p02583
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> A(N); int cnt = 0; for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); if (N < 3) { cout << 0; return -1; } else { for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { for (int k = j + 1; k < N; k++) { if ((A[i] != A[j]) && (A[j] != A[k]) && (A[k] != A[i])) { if (A[i] + A[j] > A[k]) { cnt++; } } } } } } cout << cnt << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> A(N); int cnt = 0; for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); for (int i = 0; i < N; i++) { for (int j = 0; j < i; j++) { for (int k = 0; k < j; k++) { if ((A[i] != A[j]) && (A[j] != A[k]) && (A[k] != A[i])) { if (A[k] + A[j] > A[i]) { cnt++; } } } } } cout << cnt << endl; return 0; }
replace
13
24
13
19
0
p02583
C++
Time Limit Exceeded
#include <algorithm> #include <assert.h> #include <climits> #include <cstring> #include <fstream> #include <iostream> #include <math.h> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { int N; vector<int> v; cin >> N; for (int i = 0; i < N; i++) { int temp; cin >> temp; v.push_back(temp); } sort(v.begin(), v.end()); int ans = 0; for (int i = 0; i < v.size() - 2; i++) { int j = i + 1; int k = i + 2; while (j < k && k < N) { j = k - 1; while (v[i] + v[j] > v[k] && j > i) { if (v[i] != v[j] && v[j] != v[k]) ans++; j--; } k++; } } cout << ans; }
#include <algorithm> #include <assert.h> #include <climits> #include <cstring> #include <fstream> #include <iostream> #include <math.h> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { int N; vector<int> v; cin >> N; for (int i = 0; i < N; i++) { int temp; cin >> temp; v.push_back(temp); } sort(v.begin(), v.end()); int ans = 0; for (int i = 0; i < N - 2; i++) { int j = i + 1; int k = i + 2; while (j < k && k < N) { j = k - 1; while (v[i] + v[j] > v[k] && j > i) { if (v[i] != v[j] && v[j] != v[k]) ans++; j--; } k++; } } cout << ans; }
replace
27
28
27
28
TLE
p02583
C++
Time Limit Exceeded
#include <bits/stdc++.h> typedef uint64_t u64; typedef int64_t i64; typedef uint32_t u32; typedef int32_t i32; typedef uint16_t u16; typedef int16_t i16; typedef uint8_t u8; typedef int8_t i8; using namespace std; #define rep(idx, N) for (u64 idx = 0; idx < N; idx++) int main() { u32 n; cin >> n; vector<u64> l(n); rep(i, n) { cin >> l[i]; } sort(l.begin(), l.end()); u64 ans = 0; for (u32 i = 0; i < n - 2; i++) { for (u32 j = i + 1; j < n - 1; j++) { for (u32 k = j + 1; k < n; k++) { if ((l[i] != l[j] && l[k] != l[j])) { if (l[k] < l[i] + l[j]) { // cout << l[i] << " " << l[j] << " " << l[k] << endl; ans++; } else { break; } } } } } cout << ans; return 0; }
#include <bits/stdc++.h> typedef uint64_t u64; typedef int64_t i64; typedef uint32_t u32; typedef int32_t i32; typedef uint16_t u16; typedef int16_t i16; typedef uint8_t u8; typedef int8_t i8; using namespace std; #define rep(idx, N) for (u64 idx = 0; idx < N; idx++) int main() { u32 n; cin >> n; vector<u64> l(n); rep(i, n) { cin >> l[i]; } sort(l.begin(), l.end()); u64 ans = 0; if (n < 3) { cout << 0; return 0; } for (u32 i = 0; i < n - 2; i++) { for (u32 j = i + 1; j < n - 1; j++) { for (u32 k = j + 1; k < n; k++) { if ((l[i] != l[j] && l[k] != l[j])) { if (l[k] < l[i] + l[j]) { // cout << l[i] << " " << l[j] << " " << l[k] << endl; ans++; } else { break; } } } } } cout << ans; return 0; }
insert
27
27
27
32
TLE
p02583
C++
Time Limit Exceeded
#include <bits/stdc++.h> typedef long long ll; // forループ // 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか // Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる #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 int long long using namespace std; int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: return 0; } } ll a, b, c, s, t, x, y, z; ll A, B, C, S, T, X, Y, Z; ll cnt; long double pi = 3.14159265358979323846; string N, M; unsigned long long D; signed main() { cin >> a; vector<int> f(a); REP(i, a) cin >> f[i]; for (x = 0; x < f.size() - 2; x++) { for (y = x + 1; y < f.size() - 1; y++) { for (z = y + 1; z < f.size(); z++) { if (f[x] > f[y] && f[x] > f[z] && f[x] - f[y] - f[z] < 0 && f[y] != f[z]) cnt++; else if (f[y] > f[x] && f[y] > f[z] && f[y] - f[x] - f[z] < 0 && f[x] != f[z]) cnt++; else if (f[z] > f[y] && f[z] > f[x] && f[z] - f[y] - f[x] < 0 && f[x] != f[y]) cnt++; } } } cout << cnt; return 0; }
#include <bits/stdc++.h> typedef long long ll; // forループ // 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか // Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる #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 int long long using namespace std; int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: return 0; } } ll a, b, c, s, t, x, y, z; ll A, B, C, S, T, X, Y, Z; ll cnt; long double pi = 3.14159265358979323846; string N, M; unsigned long long D; signed main() { cin >> a; vector<int> f(a); REP(i, a) cin >> f[i]; for (x = 0; x < a - 2; x++) { for (y = x + 1; y < a - 1; y++) { for (z = y + 1; z < a; z++) { if (f[x] > f[y] && f[x] > f[z] && f[x] - f[y] - f[z] < 0 && f[y] != f[z]) cnt++; else if (f[y] > f[x] && f[y] > f[z] && f[y] - f[x] - f[z] < 0 && f[x] != f[z]) cnt++; else if (f[z] > f[y] && f[z] > f[x] && f[z] - f[y] - f[x] < 0 && f[x] != f[y]) cnt++; } } } cout << cnt; return 0; }
replace
62
65
62
65
TLE
p02583
Python
Runtime Error
N = int(input()) L = map(int, input().split()) if N < 3: print(0) exit() ans = 0 for i in range(0, N - 2): for j in range(i + 1, N - 1): for k in range(j + 1, N): arr = [L[i], L[j], L[k]] arr.sort() if arr[0] != arr[1] & arr[1] != arr[2]: if arr[2] < arr[0] + arr[1]: ans = ans + 1 print(ans)
N = int(input()) L = list(map(int, input().split())) if N < 3: print(0) exit() ans = 0 for i in range(0, N - 2): for j in range(i + 1, N - 1): for k in range(j + 1, N): arr = [L[i], L[j], L[k]] arr.sort() if arr[0] != arr[1] & arr[1] != arr[2]: if arr[2] < arr[0] + arr[1]: ans = ans + 1 print(ans)
replace
1
2
1
2
TypeError: 'map' object is not subscriptable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02583/Python/s182919644.py", line 12, in <module> arr = [L[i], L[j], L[k]] TypeError: 'map' object is not subscriptable
p02583
C++
Time Limit Exceeded
#include <iostream> using namespace std; #include <vector> #define re(i, n) for (int i = 0; i < n; i++) int main() { int n; cin >> n; vector<int> l(n); re(i, n) cin >> l[i]; int cnt = 0; re(i, n - 2) { for (int j = i + 1; i < n - 1; j++) { for (int k = j + 1; i < n; k++) { if (abs(l[i] - l[j]) < l[k] && l[k] < l[i] + l[j]) cnt++; } } } cout << cnt << endl; return 0; }
#include <iostream> using namespace std; #include <vector> #define re(i, n) for (int i = 0; i < n; i++) int main() { int n; cin >> n; vector<int> l(n); re(i, n) cin >> l[i]; int cnt = 0; re(i, n - 2) { for (int j = i + 1; j < n - 1; j++) { for (int k = j + 1; k < n; k++) { if (abs(l[i] - l[j]) < l[k] && l[k] < l[i] + l[j] && l[i] != l[j] && l[i] != l[k] && l[j] != l[k]) cnt++; } } } cout << cnt << endl; return 0; }
replace
14
17
14
18
TLE
p02583
C++
Time Limit Exceeded
#include <cstdio> int main() { unsigned N, answer = 0; scanf("%u", &N); unsigned L[N]; for (int i = 0; i < N; ++i) { scanf("%u", L + i); } for (unsigned i = 0; i < N - 2; i++) { for (unsigned j = i + 1; j < N - 1; j++) { for (unsigned k = j + 1; k < N; k++) { if (L[i] != L[j] && L[k] != L[j] && L[i] != L[k] && L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[k] + L[j] > L[i]) answer++; } } } printf("%u\n", answer); return 0; }
#include <cstdio> int main() { unsigned N, answer = 0; scanf("%u", &N); unsigned L[N]; for (int i = 0; i < N; ++i) { scanf("%u", L + i); } for (unsigned i = 0; i + 2 < N; i++) { for (unsigned j = i + 1; j + 1 < N; j++) { for (unsigned k = j + 1; k < N; k++) { if (L[i] != L[j] && L[k] != L[j] && L[i] != L[k] && L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[k] + L[j] > L[i]) answer++; } } } printf("%u\n", answer); return 0; }
replace
9
11
9
11
TLE
p02583
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> l(n); for (int i = 0; i < n; i++) { cin >> l[i]; } int result = 0; // for(int i=0; i<l.size(); i++){ // cout << l[i] << endl; // } for (int i = 0; i < l.size() - 2; i++) { // cout << i << "-" << l[i] << " " << endl; for (int j = i + 1; j < l.size() - 1; j++) { // cout << " " << j << "-" << l[j] << endl; for (int k = j + 1; k < l.size(); k++) { // cout << " " << k << "-" << l[k]; if (l[i] != l[j] && l[i] != l[k] && l[j] != l[k] && (l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[j] + l[k] > l[i])) { result++; // cout << "[x]"; } // cout << endl; } } } cout << result << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> l(n); for (int i = 0; i < n; i++) { cin >> l[i]; } int result = 0; // for(int i=0; i<l.size(); i++){ // cout << l[i] << endl; // } if (n == 1) { cout << result << endl; return 0; } for (int i = 0; i < l.size() - 2; i++) { // cout << i << "-" << l[i] << " " << endl; for (int j = i + 1; j < l.size() - 1; j++) { // cout << " " << j << "-" << l[j] << endl; for (int k = j + 1; k < l.size(); k++) { // cout << " " << k << "-" << l[k]; if (l[i] != l[j] && l[i] != l[k] && l[j] != l[k] && (l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[j] + l[k] > l[i])) { result++; // cout << "[x]"; } // cout << endl; } } } cout << result << endl; return 0; }
insert
16
16
16
21
TLE
p02583
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; vector<int> v; int main() { cin >> n; for (int i = 1; i <= n; i++) { int nr; cin >> nr; v.push_back(nr); } sort(v.begin(), v.end()); v.push_back(0); int total = 0, lastj = 0, lasti = 0; for (int i = 0; i < v.size() - 3; i++) { if (i > 0) { if (v[i] == v[i - 1]) { total += lasti; continue; } else { lasti = 0; } } for (int j = i + 1; j < v.size() - 2; j++) if (v[i] != v[j]) { if (v[j] == v[j - 1]) { total += lastj; lasti += lastj; continue; } int st = j + 1, dr = v.size() - 2; while (v[st] == v[st - 1] && st <= dr) st++; if (st > dr) { lastj = 0; continue; } int ini_st = st; while (st < dr) { int mij = (st + dr) / 2; if (v[i] + v[j] > v[mij]) st = mij + 1; else dr = mij; } while (v[i] + v[j] <= v[st]) st--; total += max(0, st - ini_st + 1); lastj = max(0, st - ini_st + 1); lasti += lastj; } } cout << total; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; vector<int> v; int main() { cin >> n; for (int i = 1; i <= n; i++) { int nr; cin >> nr; v.push_back(nr); } if (n < 3) { cout << 0; return 0; } sort(v.begin(), v.end()); v.push_back(0); int total = 0, lastj = 0, lasti = 0; for (int i = 0; i < v.size() - 3; i++) { if (i > 0) { if (v[i] == v[i - 1]) { total += lasti; continue; } else { lasti = 0; } } for (int j = i + 1; j < v.size() - 2; j++) if (v[i] != v[j]) { if (v[j] == v[j - 1]) { total += lastj; lasti += lastj; continue; } int st = j + 1, dr = v.size() - 2; while (v[st] == v[st - 1] && st <= dr) st++; if (st > dr) { lastj = 0; continue; } int ini_st = st; while (st < dr) { int mij = (st + dr) / 2; if (v[i] + v[j] > v[mij]) st = mij + 1; else dr = mij; } while (v[i] + v[j] <= v[st]) st--; total += max(0, st - ini_st + 1); lastj = max(0, st - ini_st + 1); lasti += lastj; } } cout << total; return 0; }
insert
12
12
12
16
0
p02584
Python
Time Limit Exceeded
x, k, d = map(int, input().split()) x = abs(x) while k > 0: x = min(abs(x + d), abs(x - d)) k -= 1 print(x)
x, k, d = map(int, input().split()) x = abs(x) k_ = min(k, x // d) k = k - k_ x = x - k_ * d if k % 2 != 0: x = abs(x - d) print(x)
replace
2
5
2
9
TLE
p02584
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI) #define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i < (int)(n); i++) typedef long long ll; int main() { ll X, K, D; cin >> X >> K >> D; X = abs(X); while (abs(X) >= D && K > 0) { X -= D; K--; } if (K == 0) { cout << abs(X) << endl; } else if (K % 2 == 0) { cout << abs(X) << endl; } else { cout << min(abs(X - D), abs(X + D)) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI) #define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i < (int)(n); i++) typedef long long ll; int main() { ll X, K, D; cin >> X >> K >> D; X = abs(X); // while (abs(X) >= D && K > 0) { // X -= D; // K--; // } ll q = X / D; q = min(q, K); K -= q; X -= D * q; if (K == 0) { cout << abs(X) << endl; } else if (K % 2 == 0) { cout << abs(X) << endl; } else { cout << min(abs(X - D), abs(X + D)) << endl; } return 0; }
replace
19
23
19
27
TLE
p02584
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<long long, long long> P; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define agewari(a, b) ((ll)a + ((ll)b - 1)) / b const int MOD = 1000000007; const long long INF = 1LL << 60; int main() { ll x, k, d; cin >> x >> k >> d; x = abs(x); bool ok = true; ll tmp = 0; rep(i, k) { tmp += d; if (tmp >= x) { ok = false; break; } } if (ok) { ll ans = x; rep(i, k) ans -= d; cout << ans << endl; return 0; } if ((k - (x / d)) % 2 == 0) { cout << x - (x / d) * d << endl; } else { cout << abs(x - ((x / d) + 1) * d) << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<long long, long long> P; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define agewari(a, b) ((ll)a + ((ll)b - 1)) / b const int MOD = 1000000007; const long long INF = 1LL << 60; int main() { ll x, k, d; cin >> x >> k >> d; x = abs(x); bool ok = true; if (k * d > x) ok = false; if (log10(k) + log10(d) > 17) ok = false; if (ok) { ll ans = x; rep(i, k) ans -= d; cout << ans << endl; return 0; } if ((k - (x / d)) % 2 == 0) { cout << x - (x / d) * d << endl; } else { cout << abs(x - ((x / d) + 1) * d) << endl; } }
replace
16
24
16
21
TLE
p02584
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, x, n) for (int i = x; i < (n); i++) const long long INF = 1LL << 60; // 仮想的な無限大の値; using namespace std; using ll = long long; using P = pair<int, int>; 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 main() { ll X, K, D; cin >> X >> K >> D; ll p = X; ll m = 1e16; ll r = abs(m) % D; vector<ll> q(3); ll j = 0; rep(i, K) { if (p > 0) p -= D; else p += D; chmin(m, abs(p)); q[j % 3] = p; if (j > 3) { if (p == q[(j - 2) % 3]) { // cout << j << " "<< q[j%3] << " " << q[(j-1)%3] << " " << q[(j-2)%3] // << endl; if ((K - i) % 2 == 0) { m = abs(q[(j - 1) % 3]); } else { m = abs(p); } break; } } ++j; } cout << m << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, x, n) for (int i = x; i < (n); i++) const long long INF = 1LL << 60; // 仮想的な無限大の値; using namespace std; using ll = long long; using P = pair<int, int>; 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 main() { ll X, K, D; cin >> X >> K >> D; ll p = X; ll m = 1e16; ll r = abs(m) % D; vector<ll> q(3); ll j = 0; ll F = abs(p) / D; ll G = abs(p) % D; ll H = abs(G - D); if (K <= F) { cout << abs(X) - K * D << endl; return 0; } if ((K - F) % 2 == 0) { cout << G << endl; } else { cout << H << endl; } return 0; rep(i, K) { if (p > 0) p -= D; else p += D; chmin(m, abs(p)); q[j % 3] = p; if (j > 3) { if (p == q[(j - 2) % 3]) { // cout << j << " "<< q[j%3] << " " << q[(j-1)%3] << " " << q[(j-2)%3] // << endl; if ((K - i) % 2 == 0) { m = abs(q[(j - 1) % 3]); } else { m = abs(p); } break; } } ++j; } cout << m << endl; return 0; }
insert
31
31
31
46
TLE
p02584
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> using namespace std; typedef long long ll; int main() { ll x, k, d; scanf("%lld%lld%lld", &x, &k, &d); if (x == d || -x == d) { printf("%lld\n", (k & 1 ? 0 : d)); return 0; } if (k == 1) { printf("%lld\n", (x >= 0 ? abs(x - d) : abs(x + d))); return 0; } if (x >= 0) { while (x - d >= 0) { x -= d; k--; if (!k) { printf("%lld\n", abs(x)); return 0; } } } if (x < 0) { while (x + d < 0) { x += d; k--; if (!k) { printf("%lld\n", abs(x)); return 0; } } } if (k & 1) { printf("%lld\n", (abs(x - d) >= abs(x + d) ? abs(x + d) : abs(x - d))); return 0; } else { printf("%lld\n", abs(x)); return 0; } return 0; }
#include <cstdio> #include <iostream> using namespace std; typedef long long ll; int main() { ll x, k, d; cin >> x >> k >> d; ll a = abs(x) / d; ll ans; if (a == k) ans = abs(x) - d * a; else if (a < k) { k -= a; if (k & 1) ans = d * (a + 1) - abs(x); else ans = abs(x) - d * a; } else ans = abs(x) - d * k; cout << ans << endl; return 0; }
replace
6
42
6
20
TLE
p02584
C++
Time Limit Exceeded
// HEADER FILES AND NAMESPACES #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>; template <typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; // DEFINE STATEMENTS const long long infty = 1e18; #define num1 1000000007 #define num2 998244353 #define REP(i, a, n) for (ll i = a; i < n; i++) #define REPd(i, a, n) for (ll i = a; i >= n; i--) #define pb push_back #define pob pop_back #define f first #define s second #define fix(f, n) std::fixed << std::setprecision(n) << f #define all(x) x.begin(), x.end() #define M_PI 3.14159265358979323846 #define epsilon (double)(0.000000001) typedef long long ll; typedef vector<long long> vll; typedef pair<long long, long long> pll; typedef vector<pair<long long, long long>> vpll; typedef vector<int> vii; // DEBUG FUNCTIONS #ifndef ONLINE_JUDGE template <typename T> void __p(T a) { cout << a; } template <typename T, typename F> void __p(pair<T, F> a) { cout << "{"; __p(a.first); cout << ","; __p(a.second); cout << "}"; } template <typename T> void __p(std::vector<T> a) { cout << "{"; for (auto it = a.begin(); it < a.end(); it++) __p(*it), cout << ",}"[it + 1 == a.end()]; } template <typename T> void __p(std::set<T> a) { cout << "{"; for (auto it = a.begin(); it != a.end();) { __p(*it); cout << ",}"[++it == a.end()]; } } template <typename T> void __p(std::multiset<T> a) { cout << "{"; for (auto it = a.begin(); it != a.end();) { __p(*it); cout << ",}"[++it == a.end()]; } } template <typename T, typename F> void __p(std::map<T, F> a) { cout << "{\n"; for (auto it = a.begin(); it != a.end(); ++it) { __p(it->first); cout << ": "; __p(it->second); cout << "\n"; } cout << "}\n"; } template <typename T, typename... Arg> void __p(T a1, Arg... a) { __p(a1); __p(a...); } template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : "; __p(arg1); cout << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { int bracket = 0, i = 0; for (;; i++) if (names[i] == ',' && bracket == 0) break; else if (names[i] == '(') bracket++; else if (names[i] == ')') bracket--; const char *comma = names + i; cout.write(names, comma - names) << " : "; __p(arg1); cout << " | "; __f(comma + 1, args...); } #define trace(...) \ cout << "Line:" << __LINE__ << " ", __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) #define error(...) #endif // DEBUG FUNCTIONS END // CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; mt19937_64 rng(chrono::steady_clock::now() .time_since_epoch() .count()); // FOR RANDOM NUMBER GENERATION ll mod_exp(ll a, ll b, ll c) { ll res = 1; a = a % c; while (b > 0) { if (b % 2 == 1) res = (res * a) % c; b /= 2; a = (a * a) % c; } return res; } ll mymod(ll a, ll b) { return ((a % b) + b) % b; } ll gcdExtended(ll, ll, ll *, ll *); ll modInverse(ll a, ll m) { ll x, y; ll g = gcdExtended(a, m, &x, &y); g++; // this line was added just to remove compiler warning ll res = (x % m + m) % m; return res; } ll gcdExtended(ll a, ll b, ll *x, ll *y) { if (a == 0) { *x = 0, *y = 1; return b; } ll x1, y1; ll gcd = gcdExtended(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd; } bool my(pair<pll, ll> p1, pair<pll, ll> p2) { if (p1.f.f < p2.f.f) return true; else if (p1.f.f == p2.f.f && p1.s < p2.s) return true; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll x, k, d; cin >> x >> k >> d; while (x >= d && k > 0) { x -= d; k--; } while (x <= -d && k > 0) { x += d; k--; } if (!k) { cout << abs(x) << "\n"; exit(0); } if (k & 1) { if (x >= 0) { cout << abs(x - d) << "\n"; } else { cout << x + d << "\n"; } } else { cout << abs(x) << "\n"; } return 0; } /* 1. Check borderline constraints. Can a variable you are dividing by be 0? 2. Use ll while using bitshifts 3. Do not erase from set while iterating it 4. Initialise everything 5. Read the task carefully, is something unique, sorted, adjacent, guaranteed?? 6. DO NOT use if(!mp[x]) if you want to iterate the map later 7. Are you using i in all loops? Are the i's conflicting? */
// HEADER FILES AND NAMESPACES #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>; template <typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; // DEFINE STATEMENTS const long long infty = 1e18; #define num1 1000000007 #define num2 998244353 #define REP(i, a, n) for (ll i = a; i < n; i++) #define REPd(i, a, n) for (ll i = a; i >= n; i--) #define pb push_back #define pob pop_back #define f first #define s second #define fix(f, n) std::fixed << std::setprecision(n) << f #define all(x) x.begin(), x.end() #define M_PI 3.14159265358979323846 #define epsilon (double)(0.000000001) typedef long long ll; typedef vector<long long> vll; typedef pair<long long, long long> pll; typedef vector<pair<long long, long long>> vpll; typedef vector<int> vii; // DEBUG FUNCTIONS #ifndef ONLINE_JUDGE template <typename T> void __p(T a) { cout << a; } template <typename T, typename F> void __p(pair<T, F> a) { cout << "{"; __p(a.first); cout << ","; __p(a.second); cout << "}"; } template <typename T> void __p(std::vector<T> a) { cout << "{"; for (auto it = a.begin(); it < a.end(); it++) __p(*it), cout << ",}"[it + 1 == a.end()]; } template <typename T> void __p(std::set<T> a) { cout << "{"; for (auto it = a.begin(); it != a.end();) { __p(*it); cout << ",}"[++it == a.end()]; } } template <typename T> void __p(std::multiset<T> a) { cout << "{"; for (auto it = a.begin(); it != a.end();) { __p(*it); cout << ",}"[++it == a.end()]; } } template <typename T, typename F> void __p(std::map<T, F> a) { cout << "{\n"; for (auto it = a.begin(); it != a.end(); ++it) { __p(it->first); cout << ": "; __p(it->second); cout << "\n"; } cout << "}\n"; } template <typename T, typename... Arg> void __p(T a1, Arg... a) { __p(a1); __p(a...); } template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : "; __p(arg1); cout << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { int bracket = 0, i = 0; for (;; i++) if (names[i] == ',' && bracket == 0) break; else if (names[i] == '(') bracket++; else if (names[i] == ')') bracket--; const char *comma = names + i; cout.write(names, comma - names) << " : "; __p(arg1); cout << " | "; __f(comma + 1, args...); } #define trace(...) \ cout << "Line:" << __LINE__ << " ", __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) #define error(...) #endif // DEBUG FUNCTIONS END // CUSTOM HASH TO SPEED UP UNORDERED MAP AND TO AVOID FORCED CLASHES struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; mt19937_64 rng(chrono::steady_clock::now() .time_since_epoch() .count()); // FOR RANDOM NUMBER GENERATION ll mod_exp(ll a, ll b, ll c) { ll res = 1; a = a % c; while (b > 0) { if (b % 2 == 1) res = (res * a) % c; b /= 2; a = (a * a) % c; } return res; } ll mymod(ll a, ll b) { return ((a % b) + b) % b; } ll gcdExtended(ll, ll, ll *, ll *); ll modInverse(ll a, ll m) { ll x, y; ll g = gcdExtended(a, m, &x, &y); g++; // this line was added just to remove compiler warning ll res = (x % m + m) % m; return res; } ll gcdExtended(ll a, ll b, ll *x, ll *y) { if (a == 0) { *x = 0, *y = 1; return b; } ll x1, y1; ll gcd = gcdExtended(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd; } bool my(pair<pll, ll> p1, pair<pll, ll> p2) { if (p1.f.f < p2.f.f) return true; else if (p1.f.f == p2.f.f && p1.s < p2.s) return true; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll x, k, d; cin >> x >> k >> d; if (x >= d) { ll times = min(x / d, k); x -= times * d; k -= times; } if (x <= -d) { ll times = min(abs(x) / d, k); x += times * d; k -= times; } if (!k) { cout << abs(x) << "\n"; exit(0); } if (k & 1) { if (x >= 0) { cout << abs(x - d) << "\n"; } else { cout << x + d << "\n"; } } else { cout << abs(x) << "\n"; } return 0; } /* 1. Check borderline constraints. Can a variable you are dividing by be 0? 2. Use ll while using bitshifts 3. Do not erase from set while iterating it 4. Initialise everything 5. Read the task carefully, is something unique, sorted, adjacent, guaranteed?? 6. DO NOT use if(!mp[x]) if you want to iterate the map later 7. Are you using i in all loops? Are the i's conflicting? */
replace
175
182
175
184
TLE
p02584
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <limits> using namespace std; typedef unsigned long long int ull; typedef long long int ll; #define fi(i, n) for (int i = 0; i < n; i++) #define f(i, a, b) for (int i = a; i < b; i++) #define vi vector<int> #define pb push_back int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } ll fact(ll n) { ll ans = 1e14; for (ll i = 1; i <= sqrt(n); i++) { if (n % i == 0) { ll sol = (i - 1) + (n / i - 1); ans = min(ans, sol); } } return ans; } int visited[200000] = {0}; vector<vector<int>> v(200000); int dfs(int x) { int ans = 0; if (visited[x] == 0) { visited[x] = 1; ans++; int a = v[x].size(); for (int j = 0; j < a; j++) { int data = v[x][j]; ans = ans + dfs(data); } } return ans; } int main() { ll x, k, d; cin >> x >> k >> d; if (x == 0) { if (k % 2 == 0) { cout << x; } else { ll y = abs(x - d); ll z = abs(x + d); cout << min(y, z) << endl; } } x = abs(x); if ((x / k) > d) { x = x - k * d; cout << x << endl; } else if (x > 0) { while (x >= 0 && k > 0) { if (x - d >= 0) { x = x - d; k--; } else { break; } } if (k == 0) { cout << x << endl; } else { if (k % 2 == 0) cout << x << endl; else { ll y = abs(x - d); ll z = abs(x + d); cout << min(y, z) << endl; } } } }
#include <bits/stdc++.h> #include <limits> using namespace std; typedef unsigned long long int ull; typedef long long int ll; #define fi(i, n) for (int i = 0; i < n; i++) #define f(i, a, b) for (int i = a; i < b; i++) #define vi vector<int> #define pb push_back int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } ll fact(ll n) { ll ans = 1e14; for (ll i = 1; i <= sqrt(n); i++) { if (n % i == 0) { ll sol = (i - 1) + (n / i - 1); ans = min(ans, sol); } } return ans; } int visited[200000] = {0}; vector<vector<int>> v(200000); int dfs(int x) { int ans = 0; if (visited[x] == 0) { visited[x] = 1; ans++; int a = v[x].size(); for (int j = 0; j < a; j++) { int data = v[x][j]; ans = ans + dfs(data); } } return ans; } int main() { ll x, k, d; cin >> x >> k >> d; if (x == 0) { if (k % 2 == 0) { cout << x; } else { ll y = abs(x - d); ll z = abs(x + d); cout << min(y, z) << endl; } } x = abs(x); if ((x / k) >= d) { x = x - k * d; cout << x << endl; } else if (x > 0) { while (x >= 0 && k > 0) { if (x - d >= 0) { x = x - d; k--; } else { break; } } if (k == 0) { cout << x << endl; } else { if (k % 2 == 0) cout << x << endl; else { ll y = abs(x - d); ll z = abs(x + d); cout << min(y, z) << endl; } } } }
replace
52
53
52
53
TLE
p02584
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; int main() { long long x, k, d; cin >> x >> k >> d; while (k--) { if (x > 0) x -= d; // 현재위치(x)가 양수인 경우 else x += d; // 현재위치(x)가 음수거나, 0인 경우 } cout << abs(x); return 0; }
#include <cmath> #include <iostream> using namespace std; int main() { long long x, k, d; cin >> x >> k >> d; x = abs(x); long long n = (d ? x / d : 0), r = (d ? x % d : 0); if (n > k) cout << (x - k * d); else if ((k - n) % 2) cout << abs(d - r); else cout << r; return 0; }
replace
6
13
6
14
TLE
p02584
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <queue> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; using PP = pair<ll, pair<ll, ll>>; #define rep(i, n) for (ll i = 0; i < (n); ++i) ll x, k, d, ans; int main() { cin >> x >> k >> d; x = abs(x); if ((ll)x / d < k) { if ((k - (ll)x / d) % 2) { ans = d - (x % d); } else { ans = x % d; } } else { if ((ll)x / d == k) { rep(i, d) { if (x % d == i) { ans = i; } } } else { ans = x - (k * d); } } ans = abs(ans); cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <queue> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; using PP = pair<ll, pair<ll, ll>>; #define rep(i, n) for (ll i = 0; i < (n); ++i) ll x, k, d, ans; int main() { cin >> x >> k >> d; x = abs(x); if ((ll)x / d < k) { if ((k - (ll)x / d) % 2) { ans = d - (x % d); } else { ans = x % d; } } else { if ((ll)x / d == k) { ans = x % d; } else { ans = x - (k * d); } } ans = abs(ans); cout << ans << endl; return 0; }
replace
30
35
30
31
TLE
p02584
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long x, k, d; cin >> x >> k >> d; x = abs(x); for (long long i = 1; i < k + 1; i++) { if (x <= 0) { if ((k - i) % 2 == 1) { cout << abs(x); return 0; } else { cout << x + d; return 0; } } x -= d; } cout << abs(x); }
#include <bits/stdc++.h> using namespace std; int main() { long long x, k, d; cin >> x >> k >> d; x = abs(x); long long n = x / d + 1; long long m = min(k, n); x -= d * m; if ((k - m) % 2 == 0) cout << abs(x); else cout << x + d; }
replace
7
20
7
14
TLE
p02584
Python
Time Limit Exceeded
X, K, D = map(int, input().split()) x = abs(X) k = K while x > 0 and k > 0: x -= D k -= 1 if k % 2 == 1: x += D print(abs(x))
X, K, D = map(int, input().split()) x = abs(X) k = K xd = min(x // D + 1, K) x -= D * xd k -= xd if k % 2 == 1: x += D print(abs(x))
replace
4
7
4
8
TLE
p02584
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pii pair<int, int> #define _FastIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define MAXX 105 ll n; ll l[MAXX]; int main() { _FastIO; ll x, k, d; cin >> x >> k >> d; x = abs(x); while ((x - d) >= 0 && k) { k--; x -= d; } if (!k) { cout << x << endl; return 0; } if (k % 2) { cout << abs(x - d) << endl; return 0; } cout << x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pii pair<int, int> #define _FastIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define MAXX 105 ll n; ll l[MAXX]; int main() { _FastIO; ll x, k, d; cin >> x >> k >> d; x = abs(x); ll p = x / d; if (p >= k) { x -= (k * d); k = 0; } else { x %= d; k -= p; } if (!k) { cout << x << endl; return 0; } if (k % 2) { cout << abs(x - d) << endl; return 0; } cout << x << endl; return 0; }
replace
20
23
20
27
TLE