Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; int RI() { return 0; } template <typename... T> int RI(int &head, T &...tail) { return scanf("%d", &head) + RI(tail...); } void PRI(int x) { printf("%d\n", x); } template <typename... Args> void PRI(int head, Args... tail) { printf("%d ", head); PRI(tail...); } pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) { return make_pair(a.first + b.first, a.second + b.second); } pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) { return make_pair(a.first - b.first, a.second - b.second); } pair<int, int> &operator+=(pair<int, int> &a, const pair<int, int> &b) { a.first += b.first; a.second += b.second; return a; } pair<int, int> &operator-=(pair<int, int> &a, const pair<int, int> &b) { a.first -= b.first; a.second -= b.second; return a; } template <class T, class U> bool cmp_second(const pair<T, U> &a, const pair<T, U> &b) { return a.second < b.second; } inline int sg(int x) { return x ? (x > 0 ? 1 : -1) : 0; } int an, bn; vector<int> a, b; int dp[64][64]; int solve() { int sol = 0; map<int, pair<vector<int>, vector<int>>> ko; bool visa[64], visb[64]; sort(a.begin(), a.end()); sort(b.begin(), b.end()); for (int i = 0; i < an; i++) { for (int j = 0; j < bn; j++) { if (j && b[j] == b[j - 1]) continue; ko[a[i] + b[j]].first.push_back(i); } } for (int j = 0; j < bn; j++) { for (int i = 0; i < an; i++) { if (i && a[i] == a[i - 1]) continue; ko[a[i] + b[j]].second.push_back(j); } } for (auto it = ko.begin(); it != ko.end(); it++) { memset(visa, 0, sizeof(visa)); memset(visb, 0, sizeof(visb)); const auto &va = it->second.first; const auto &vb = it->second.second; for (auto ax : va) visa[ax] = true; for (auto bx : vb) visb[bx] = true; sol = max(sol, (int)(va.size() + vb.size())); for (auto jt = next(it); jt != ko.end(); jt++) { const auto &ua = jt->second.first; const auto &ub = jt->second.second; int cnt = 0; for (auto ax : ua) if (!visa[ax]) cnt++; for (auto bx : ub) if (!visb[bx]) cnt++; int val = va.size() + vb.size() + cnt; sol = max(sol, val); } } return sol; } int main(void) { RI(an, bn); a.resize(an); b.resize(bn); for (int i = 0; i < an; i++) RI(a[i]); for (int i = 0; i < bn; i++) RI(b[i]); PRI(solve()); return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; const int N = 51; int n, m, x; vector<int> a, b; unordered_map<int, unordered_set<int> > mp; int merge(unordered_set<int> &a, unordered_set<int> &b) { int ans = a.size(); for (int i : b) if (a.find(i) == a.end()) ans++; return ans; } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &x), x *= 2, a.push_back(x); for (int i = 0; i < m; i++) scanf("%d", &x), x *= 2, b.push_back(x); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) mp[(a[i] + b[j]) >> 1].insert(i), mp[(a[i] + b[j]) >> 1].insert(n + j); unordered_map<int, unordered_set<int> >::iterator it1 = mp.begin(); int ans = 0; while (it1 != mp.end()) { unordered_set<int> st; for (int i : it1->second) st.insert(i); unordered_map<int, unordered_set<int> >::iterator it2 = mp.begin(); while (it2 != mp.end()) ans = max(ans, merge(st, it2->second)), it2++; it1++; } printf("%d", ans); return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; const int N = 120, M = 3605; int y[2][N]; int C[M]; int C2[M][M]; bool is[N][M]; int f(vector<int> &sum, int x, int sz) { int l = 0, r = sz - 1, mid; while (l < r) { mid = (l + r) / 2; if (x <= sum[mid]) r = mid; else l = mid + 1; } assert(sum[l] == x); return l; } int main() { vector<int> sum; int n[2]; scanf("%d%d", &n[0], &n[1]); for (int i = 0; i < 2; ++i) { for (int j = 0; j < n[i]; ++j) scanf("%d", &y[i][j]); } for (int i = 0; i < n[0]; ++i) { for (int j = 0; j < n[1]; ++j) { sum.push_back(y[0][i] + y[1][j]); } } sort(sum.begin(), sum.end()); int sz = unique(sum.begin(), sum.end()) - sum.begin(); for (int i = 0; i < n[0]; ++i) { for (int j = 0; j < n[1]; ++j) { int ind = f(sum, y[0][i] + y[1][j], sz); is[i][ind] = 1; is[j + n[0]][ind] = 1; } } int nn = n[0] + n[1]; for (int i = 0; i < nn; ++i) { for (int j = 0; j < sz; ++j) if (is[i][j]) ++C[j]; for (int j = 0; j < sz; ++j) for (int k = j + 1; k < sz; ++k) if (is[i][j] && is[i][k]) ++C2[j][k]; } int ret = 0; for (int j = 0; j < sz; ++j) for (int k = j + 1; k < sz; ++k) { int tmp = C[j] + C[k] - C2[j][k]; ret = max(ret, tmp); } for (int i = 0; i < sz; ++i) ret = max(ret, C[i]); cout << ret << endl; return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 65, MAXM = 65; int N, M; int A[MAXN], B[MAXM]; int Id[40011], Pos[MAXN * MAXM], Pc; bool VisA[MAXN], VisB[MAXM]; int Ans, Cnt; int Val[MAXN * MAXM]; int main() { ios_base::sync_with_stdio(false); cin >> N >> M; for (int i = 1; i <= N; ++i) { cin >> A[i]; A[i] <<= 1; } sort(A + 1, A + N + 1); for (int j = 1; j <= M; ++j) { cin >> B[j]; B[j] <<= 1; } sort(B + 1, B + M + 1); for (int i = 1; i <= N; ++i) for (int j = 1, p; j <= M; ++j) { p = (A[i] + B[j]) >> 1; if (!Id[p + 20000]) { ++Pc; Id[p + 20000] = Pc; Pos[Pc] = p; } } for (int a = 1; a <= N; ++a) { for (int b = 1, p; b <= M; ++b) { p = (A[a] + B[b]) >> 1; for (int i = 1; i <= N; ++i) VisA[i] = false; for (int j = 1; j <= M; ++j) VisB[j] = false; for (int i = 1; i <= N; ++i) for (int j = 1; j <= M; ++j) { if (((A[i] + B[j]) >> 1) == p) { VisA[i] = true; VisB[j] = true; } } Cnt = 0; for (int i = 1; i <= N; ++i) if (VisA[i]) ++Cnt; for (int j = 1; j <= M; ++j) if (VisB[j]) ++Cnt; for (int i = Pc; i >= 1; --i) Val[i] = 0; for (int i = 1; i <= N; ++i) { if (VisA[i]) continue; for (int j = 1; j <= M; ++j) { if (j != 1 && B[j] == B[j - 1]) continue; ++Val[Id[((A[i] + B[j]) >> 1) + 20000]]; } } for (int j = 1; j <= M; ++j) { if (VisB[j]) continue; for (int i = 1; i <= N; ++i) { if (i != 1 && A[i] == A[i - 1]) continue; ++Val[Id[((A[i] + B[j]) >> 1) + 20000]]; } } Ans = max(Ans, Cnt); for (int i = Pc; i >= 1; --i) Ans = max(Ans, Val[i] + Cnt); } } cout << Ans << endl; return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 60 + 2; const int C = 1e4 + 10; const int XX = 1e5; int n[2], y[2][MAXN]; bool mark[2][XX]; vector<bitset<MAXN * 2>> vec; bitset<MAXN * 2> temp; bitset<MAXN * 2> get(pair<int, int> p) { bitset<MAXN << 1> ret; for (int w = 0; w < 2; w++) for (int i = 0; i < n[w]; i++) { int id = w * MAXN + i; int y2 = y[w][i] + (p.second - y[w][i]) * 2; if (y2 < 0 || y2 >= XX) continue; if (mark[!w][y2]) ret[id] = 1; } return ret; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n[0] >> n[1]; for (int w = 0; w < 2; w++) for (int i = 0; i < n[w]; i++) cin >> y[w][i], y[w][i] += C, y[w][i] <<= 1, mark[w][y[w][i]] = 1; int ans = 0; for (int i = 0; i < n[0]; i++) for (int j = 0; j < n[1]; j++) { pair<int, int> p(0, y[0][i] + y[1][j] >> 1); vec.push_back(get(p)); } for (auto &x : vec) for (auto &y : vec) { temp = x | y; ans = max(ans, (int)temp.count()); } cout << ans << "\n"; return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return x * f; } map<double, int> mp; map<int, int> A, B; bitset<125> s[10000 * 2 + 5]; int n, m, a[200005], b[200005], cnt; double pos[200005]; int main() { n = read(); m = read(); for (int i = 1; i <= n; i++) a[i] = read(), A[a[i]] = i; for (int i = 1; i <= m; i++) b[i] = read(), B[b[i]] = i; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { mp[((double)a[i] + b[j]) / 2]++; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (mp[((double)a[i] + b[j]) / 2]) { mp[((double)a[i] + b[j]) / 2] = 0; pos[++cnt] = ((double)a[i] + b[j]) / 2; } } } for (int i = 1; i <= cnt; i++) { for (int j = 1; j <= n; j++) { if (B[(int)(pos[i] * 2 - a[j])]) s[i][j] = s[i][n + B[(int)(pos[i] * 2 - a[j])]] = 1; } for (int j = 1; j <= m; j++) { if (A[(int)(pos[i] * 2 - b[j])]) s[i][j + n] = s[i][A[(int)(pos[i] * 2 - b[j])]] = 1; } } int ans = 0; for (int i = 1; i <= cnt; i++) { for (int j = 1; j <= cnt; j++) { bitset<125> f = ((s[i]) | (s[j])); ans = max(ans, (int)f.count()); } } printf("%d\n", ans); return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; int n, m, a[100005], b[100005], ans, v1[100005], v2[100005], val[100005], st[100005], hd, c1[100005], c2[100005]; inline int cal(int x) { int i, j, res = 0, ret = 0; for (i = 1; i <= n; ++i) v1[a[i]] = 0; for (i = 1; i <= m; ++i) v2[b[i]] = 0; for (i = 1; i <= n; ++i) ++v1[a[i]]; for (i = 1; i <= m; ++i) ++v2[b[i]]; for (i = 1; i <= n; ++i) for (j = 1; j <= m; ++j) if (a[i] + b[j] == x) ret += v1[a[i]] + v2[b[j]], v1[a[i]] = v2[b[j]] = 0; hd = 0; for (i = 1; i <= n; ++i) { if (a[i] != a[i + 1]) for (j = 1; j <= m; ++j) { if (b[j] != b[j + 1]) val[st[++hd] = a[i] + b[j]] += v1[a[i]] + v2[b[j]]; } } for (i = 1; i <= hd; ++i) { res = max(res, val[st[i]]), val[st[i]] = 0; } return ret + res; } int i; int main() { cin >> n >> m; for (i = 1; i <= n; ++i) cin >> a[i], a[i] += 10000; for (i = 1; i <= m; ++i) cin >> b[i], b[i] += 10000; sort(a + 1, a + n + 1); sort(b + 1, b + m + 1); a[n + 1] = -1; b[m + 1] = -1; for (i = 0; i <= 40000; ++i) { ans = max(ans, cal(i)); } cout << ans; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; const int Nmax = 4e4 + 5; const int off = 2e4; vector<pair<int, int>> s[Nmax]; vector<int> p; int a[100]; int b[100]; int n, m; bool flag[200]; void solve() { int ans = 0; for (int i = 0; i < p.size(); i++) for (int j = i; j < p.size(); j++) { int res = 0; memset(flag, 0, sizeof(flag)); for (pair<int, int> pii : s[p[i]]) { if (!flag[pii.first]) { flag[pii.first] = true; res++; } if (!flag[pii.second + n]) { flag[pii.second + n] = true; res++; } } for (pair<int, int> pii : s[p[j]]) { if (!flag[pii.first]) { flag[pii.first] = true; res++; } if (!flag[pii.second + n]) { flag[pii.second + n] = true; res++; } } ans = max(ans, res); } cout << ans; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] *= 2; } for (int i = 1; i <= m; i++) { cin >> b[i]; b[i] *= 2; } for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { int res = (a[i] + b[j]) / 2; res += off; if (!s[res].size()) p.push_back(res); s[res].push_back(make_pair(i, j)); } solve(); return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; string itosm(long long x) { if (x == 0) return "0"; string res = ""; while (x > 0) { res += ((x % 10) + '0'); x /= 10; } reverse(res.begin(), res.end()); return res; } long long stoim(string str) { long long res = 0; int p = 0; if (str[0] == '-') p++; for (int i = p; i < str.length(); i++) { res *= 10; res += (str[i] - '0'); } return res; } const long long infll = 1e18 + 3; const int inf = 1009000999; const long double eps = 1e-7; const int maxn = 1e6 + 1146; const int baseint = 1000200013; const long long basell = 1e18 + 3; const long double PI = acos(-1.0); const long long mod = 1e9 + 9; int a[100], b[100]; long long f[maxn][2]; void solve() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; a[i] += 10000; } for (int i = 0; i < m; i++) { cin >> b[i]; b[i] += 10000; } for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) f[a[i] + b[j]][0] |= (1ll << i), f[a[i] + b[j]][1] |= (1ll << j); vector<int> ys; for (int i = 0; i < maxn; i++) if (f[i][0] > 0) ys.push_back(i); int ans = 0; for (int yy1 : ys) { for (int y2 : ys) { ans = max(ans, __builtin_popcountll(f[yy1][0] | f[y2][0]) + __builtin_popcountll(f[yy1][1] | f[y2][1])); } } cout << ans; } int main() { srand(time(0)); ios_base::sync_with_stdio(0); ; cin.tie(0); cout.tie(0); solve(); return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; int y[2][222]; vector<int> v[4000]; int vis[150]; int main(int argc, char const* argv[]) { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> y[0][i]; } for (int i = 0; i < m; i++) { cin >> y[1][i]; } map<int, int> com; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { com[y[0][i] + y[1][j]]; } } int idx = 0; for (auto& i : com) { i.second = idx++; } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { v[com[y[0][i] + y[1][j]]].emplace_back(i << 1); v[com[y[0][i] + y[1][j]]].emplace_back((j << 1) | 1); } } int ans = 0; for (int i = 0; i < idx; i++) { memset(vis, false, sizeof vis); int cnt = 0; for (auto j : v[i]) { if (vis[j] == 0) ++cnt; vis[j] += 1; } for (int j = 0; j < idx; j++) { for (auto k : v[j]) { if (vis[k] == 0) ++cnt; vis[k] += 1; } ans = max(ans, cnt); for (auto k : v[j]) { vis[k] -= 1; if (vis[k] == 0) --cnt; } } } cout << ans << endl; return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = 65; int n, m, ans, coord[2][maxn], w[2][maxn]; bool vis[2][maxn]; int main() { scanf("%d%d", &n, &m); for (int(i) = (0); (i) <= ((n)-1); (i)++) { scanf("%d", &coord[0][i]); coord[0][i] *= 2; } sort(coord[0], coord[0] + n); int tmp = 0; w[0][0] = 1; for (int(i) = (1); (i) <= (n - 1); (i)++) { if (coord[0][i] == coord[0][tmp]) w[0][tmp]++; else { coord[0][++tmp] = coord[0][i]; w[0][tmp] = 1; } } n = tmp + 1; for (int(i) = (0); (i) <= ((m)-1); (i)++) { scanf("%d", &coord[1][i]); coord[1][i] *= 2; } sort(coord[1], coord[1] + m); tmp = 0; w[1][0] = 1; for (int(i) = (1); (i) <= (m - 1); (i)++) { if (coord[1][i] == coord[1][tmp]) w[1][tmp]++; else { coord[1][++tmp] = coord[1][i]; w[1][tmp] = 1; } } m = tmp + 1; for (int(u) = (0); (u) <= ((n)-1); (u)++) for (int(v) = (0); (v) <= ((m)-1); (v)++) { int p = coord[0][u] + coord[1][v] >> 1; memset(vis, 0, sizeof(vis)); int now = 0; for (int(i) = (0); (i) <= ((n)-1); (i)++) for (int(j) = (0); (j) <= ((m)-1); (j)++) { if (coord[0][i] + coord[1][j] >> 1 == p) { vis[0][i] = vis[1][j] = true; now += w[0][i] + w[1][j]; } } unordered_map<int, int> cnt; assert(cnt.empty()); int mmax = 0; for (int(i) = (0); (i) <= ((n)-1); (i)++) { for (int(j) = (0); (j) <= ((m)-1); (j)++) { if (vis[0][i] && vis[1][j]) continue; int cur = coord[0][i] + coord[1][j] >> 1; int inc = 0; if (!vis[0][i]) inc += w[0][i]; if (!vis[1][j]) inc += w[1][j]; cnt[cur] += inc; mmax = max(mmax, cnt[cur]); } } ans = max(now + mmax, ans); } printf("%d\n", ans); return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; const string yno[2] = {"NO\n", "YES\n"}; int dem(vector<int> &a, int k) { return upper_bound(a.begin(), a.end(), k) - lower_bound(a.begin(), a.end(), k); } int dem(long long k) { int ans = 0; while (k) { ans += k & 1; k >>= 1; } return ans; } void process() { int n, m; cin >> n >> m; vector<int> a(n), b(m); for (int &i : a) cin >> i; for (int &i : b) cin >> i; vector<pair<long long, long long> > c; map<int, pair<long long, long long> > M; for (int i = 0; i <= n - 1; i++) { for (int j = 0; j <= m - 1; j++) { M[a[i] + b[j]].first |= (1ll << i); M[a[i] + b[j]].second |= (1ll << j); } } for (auto it = M.begin(); it != M.end(); it++) { c.push_back(it->second); } int ans = 0; for (int i = 0; i < c.size(); i++) { for (int j = i; j < c.size(); j++) { ans = max(ans, __builtin_popcountll(c[i].first | c[j].first) + __builtin_popcountll(c[i].second | c[j].second)); } } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); process(); return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 123, inf = 1e18, mod = 1e9 + 7, N = 360360; int n, m, a[60], b[60], ans; map<int, bitset<120> > dp; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) dp[a[i] + b[j]][i] = 1, dp[a[i] + b[j]][n + j] = 1; for (auto a : dp) for (auto b : dp) ans = max(ans, (int)(a.second | b.second).count()); cout << ans; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> y1(n), y2(m); for (int i = 0; i < n; i++) cin >> y1[i]; for (int i = 0; i < m; i++) cin >> y2[i]; map<int, pair<long long, long long>> f; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) f[(y1[i] + y2[j])].first |= (1LL << i), f[(y1[i] + y2[j])].second |= (1LL << j); vector<pair<long long, long long>> lol; for (auto [a, b] : f) lol.push_back(b); int ans = 0; for (auto [z, x] : lol) for (auto [c, v] : lol) ans = max(ans, __builtin_popcountll((z | c)) + __builtin_popcountll((x | v))); cout << ans; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; void YES() { printf("YES\n"); exit(0); } void NO() { printf("NO\n"); exit(0); } struct Point { int x, y; Point() {} Point(int x, int y) : x(x), y(y) {} }; Point operator+(Point p1, Point p2) { return Point(p1.x + p2.x, p1.y + p2.y); } Point operator-(Point p1, Point p2) { return Point(p1.x - p2.x, p1.y - p2.y); } int operator*(Point p1, Point p2) { return p1.x * p2.y - p1.y * p2.x; } int sign(int v) { if (v > 0) return 1; else if (v < 0) return -1; else return 0; } Point readPoint() { int x, y; scanf("%d%d", &x, &y); return Point(x, y); } int findSq(Point p1, Point p2, Point p3) { return abs((p2 - p1) * (p3 - p1)); } bool isIn(Point p, const vector<Point>& ps) { int sq = findSq(ps[0], ps[1], ps[2]); return 2 * sq == findSq(p, ps[0], ps[1]) + findSq(p, ps[1], ps[2]) + findSq(p, ps[2], ps[3]) + findSq(p, ps[0], ps[3]); } bool areInter(Point p1, Point p2, Point p3, Point p4) { return sign((p2 - p1) * (p3 - p1)) * sign((p2 - p1) * (p4 - p1)) <= 0 && sign((p4 - p3) * (p1 - p3)) * sign((p4 - p3) * (p2 - p3)) <= 0; } int n, m; vector<int> a, b; int main() { int n, m; scanf("%d%d", &n, &m); a.resize(n); b.resize(m); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); a[i] = (a[i] + 10000) * 2; } for (int i = 0; i < m; ++i) { scanf("%d", &b[i]); b[i] = (b[i] + 10000) * 2; } map<int, vector<pair<int, int> > > M; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) M[(a[i] + b[j]) / 2].push_back(make_pair(i, j)); vector<vector<pair<int, int> > > vs; for (map<int, vector<pair<int, int> > >::iterator it = M.begin(); it != M.end(); ++it) vs.push_back(it->second); vector<int> a(n + m, 0); int ind = 0; int ans = 0; for (int i = 0; i < (int)vs.size(); ++i) for (int j = i; j < (int)vs.size(); ++j) { ++ind; int kol = 0; for (int k = 0; k < (int)vs[i].size(); ++k) { pair<int, int> p = vs[i][k]; if (a[p.first] != ind) { a[p.first] = ind; ++kol; } if (a[p.second + n] != ind) { a[p.second + n] = ind; ++kol; } } for (int k = 0; k < (int)vs[j].size(); ++k) { pair<int, int> p = vs[j][k]; if (a[p.first] != ind) { a[p.first] = ind; ++kol; } if (a[p.second + n] != ind) { a[p.second + n] = ind; ++kol; } } ans = max(ans, kol); } printf("%d\n", ans); return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; const int N = 66; int c[1 << 16]; void cc() { int m = 1 << 16, i, j; for (i = 0; i < m; i = i + 1) for (j = 1; j < m; j = j + j) if (i & j) c[i]++; } int cnt(long long x) { if (!x) return 0; return c[(long long)x & 65535] + cnt(x >> 16); } int n, m, a[N], b[N]; map<int, long long> MA, MB; map<int, long long>::iterator it; long long aa[N * N], bb[N * N]; int main() { cc(); int i, j, x, ans = 0; cin >> n >> m; for (i = 0; i < n; i = i + 1) cin >> a[i]; for (i = 0; i < m; i = i + 1) cin >> b[i]; for (i = 0; i < n; i = i + 1) for (j = 0; j < m; j = j + 1) MA[a[i] + b[j]] |= ((long long)1 << i), MB[a[i] + b[j]] |= ((long long)1 << j); for (i = 0; i < n; i = i + 1) for (j = 0; j < m; j = j + 1) aa[i * m + j] = MA[a[i] + b[j]], bb[i * m + j] = MB[a[i] + b[j]]; for (i = 0; i < n * m; i = i + 1) for (j = i; j < n * m; j = j + 1) { x = cnt(aa[i] | aa[j]) + cnt(bb[i] | bb[j]); if (ans < x) ans = x; } cout << ans; return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; bool solve() { int n, m; if (scanf("%d%d", &n, &m) != 2) { return false; } vector<int> a(n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } vector<int> b(m); for (int i = 0; i < m; ++i) { scanf("%d", &b[i]); } vector<pair<int, pair<int, int>>> c; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { c.push_back(make_pair(a[i] + b[j], pair<int, int>(i, j))); } } sort(c.begin(), c.end()); vector<pair<long long, long long>> d; long long mask1 = 0, mask2 = 0; for (int i = 0; i < int(c.size()); ++i) { mask1 |= (1LL << c[i].second.first); mask2 |= (1LL << c[i].second.second); if (i == int(c.size()) - 1 || c[i + 1].first != c[i].first) { d.push_back(pair<long long, long long>(mask1, mask2)); mask1 = 0; mask2 = 0; } } int ans = 0; for (int i = 0; i < int(d.size()); ++i) { for (int j = 0; j <= i; ++j) { ans = max(ans, __builtin_popcountll(d[i].first | d[j].first) + __builtin_popcountll(d[i].second | d[j].second)); } } printf("%d\n", ans); return true; } int main() { while (solve()) ; return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; long long L[100]; long long R[100]; long long Yl[1001000]; long long Yr[1001000]; vector<long long> YL; vector<long long> YR; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> L[i], L[i] += 10010; for (int i = 0; i < m; i++) cin >> R[i], R[i] += 10010; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { Yl[L[i] + R[j]] |= (1LL << i); Yr[L[i] + R[j]] |= (1LL << j); } } for (int i = 0; i < 100100; i++) if (Yl[i]) YL.push_back(Yl[i]); for (int i = 0; i < 100100; i++) if (Yr[i]) YR.push_back(Yr[i]); long long ans = 0; for (int i = 0; i < YL.size(); i++) { for (int j = 0; j < YL.size(); j++) { long long maskL = YL[i] | YL[j]; long long maskR = YR[i] | YR[j]; long long onesMaskL = __builtin_popcountll(maskL); long long onesMaskR = __builtin_popcountll(maskR); ans = max(ans, onesMaskL + onesMaskR); } } cout << ans << endl; return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long double EPS = 1e-8; int n, m; vector<int> a, b; pair<long long, long long> count(int p, int q) { int y = a[p] + b[q]; long long ans1 = 0, ans2 = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i] + b[j] == y) { ans1 |= (1LL << j); } } } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (b[i] + a[j] == y) { ans2 |= (1LL << j); } } } return {ans1, ans2}; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; a.resize(n); b.resize(m); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } vector<pair<long long, long long>> can; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { can.push_back(count(i, j)); } } int ans = 0; for (int i = 0; i < can.size(); i++) { for (int j = i; j < can.size(); j++) { ans = max(ans, __builtin_popcountll(can[i].first | can[j].first) + __builtin_popcountll(can[i].second | can[j].second)); } } cout << ans << '\n'; return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f; const int maxn = 60; int n, m; int a[maxn + 5], b[maxn + 5]; map<int, bitset<maxn << 1> > all; int main() { scanf("%d%d", &n, &m); for (int i = (0), i_end_ = (n); i < i_end_; ++i) scanf("%d", a + i); for (int i = (0), i_end_ = (m); i < i_end_; ++i) scanf("%d", b + i); for (int i = (0), i_end_ = (n); i < i_end_; ++i) for (int j = (0), j_end_ = (m); j < j_end_; ++j) { all[a[i] + b[j]][i] = 1; all[a[i] + b[j]][n + j] = 1; } int ans = 0; for (auto u : all) for (auto v : all) { chkmax(ans, int((u.second | v.second).count())); } printf("%d\n", ans); return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; int n, m, ya[65], yb[65]; vector<int> sums; map<int, pair<long long, long long> > Destroy; pair<long long, long long> dDestroy[65 * 65]; int countbits(long long x) { int rtn = 0; while (x) { rtn += (x & 1); x >>= 1; } return rtn; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 0; i <= n - 1; i++) cin >> ya[i]; for (int i = 0; i <= m - 1; i++) cin >> yb[i]; for (int i = 0; i <= n - 1; i++) for (int j = 0; j <= m - 1; j++) { (Destroy[ya[i] + yb[j]]).first |= (1LL << i); (Destroy[ya[i] + yb[j]]).second |= (1LL << j); sums.push_back(ya[i] + yb[j]); } sort(sums.begin(), sums.end()); auto it = unique(sums.begin(), sums.end()); sums.resize(distance(sums.begin(), it)); int ss = sums.size(); for (int i = 0; i < ss; i++) { dDestroy[i] = Destroy[sums[i]]; } int maxdestroy = 0; for (int i = 0; i < ss; i++) for (int j = 0; j < ss; j++) { maxdestroy = max(maxdestroy, countbits(dDestroy[i].first | dDestroy[j].first) + countbits(dDestroy[i].second | dDestroy[j].second)); } cout << maxdestroy << '\n'; return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; int n[2], a[2][66], ans; int died[2][66], stmp, stmp2; int tg[101010], tg2[101010], vl[101010]; const int M = 50505; void go() { for (int i = 0; i < n[0]; i++) for (int j = 0; j < n[1]; j++) { ++stmp; for (int ii = 0; ii < n[0]; ii++) for (int jj = 0; jj < n[1]; jj++) if (a[0][i] + a[1][j] == a[0][ii] + a[1][jj]) { died[0][ii] = stmp; died[1][jj] = stmp; } int tans = 0; for (int ii = 0; ii < n[0]; ii++) if (died[0][ii] == stmp) tans++; for (int jj = 0; jj < n[1]; jj++) if (died[1][jj] == stmp) tans++; ans = max(ans, tans); for (int ii = 0; ii < n[0]; ii++) { if (died[0][ii] == stmp) continue; ++stmp2; for (int jj = 0; jj < n[1]; jj++) { int g = a[0][ii] + a[1][jj] + M; if (tg[g] != stmp) vl[g] = 0; tg[g] = stmp; if (tg2[g] != stmp2) vl[g]++; tg2[g] = stmp2; ans = max(ans, tans + vl[g]); } } for (int ii = 0; ii < n[1]; ii++) { if (died[1][ii] == stmp) continue; ++stmp2; for (int jj = 0; jj < n[0]; jj++) { int g = a[1][ii] + a[0][jj] + M; if (tg[g] != stmp) vl[g] = 0; tg[g] = stmp; if (tg2[g] != stmp2) vl[g]++; tg2[g] = stmp2; ans = max(ans, tans + vl[g]); } } } } int main() { cin >> n[0] >> n[1]; for (int i = 0; i < 2; i++) { for (int j = 0; j < n[i]; j++) cin >> a[i][j]; sort(a[i], a[i] + n[i]); } go(); cout << ans << endl; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; int a[65], b[65]; bitset<65 * 2> s[10010 * 4]; bool vis[10010 * 4]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &a[i]), a[i] *= 2; for (int i = 0; i < m; i++) scanf("%d", &b[i]), b[i] *= 2; sort(a, a + n); sort(b, b + m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int umr = (a[i] + b[j]) / 2 + 2 * 10010; s[umr][i] = s[umr][n + j] = 1; vis[umr] = 1; } } int ans = 0; for (int i = 0; i < 4 * 10010; i++) { if (!vis[i]) continue; ans = max(ans, (int)s[i].count()); for (int j = i + 1; j < 4 * 10010; j++) if (vis[j]) ans = max(ans, (int)(s[i] | s[j]).count()); } printf("%d\n", ans); return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 63; const int MAXY = 10000; int cntbam[MAXY + MAXY + 13]; int cntdan[MAXY + MAXY + 13]; vector<int> bam, dan; int conjbam[MAXY * 4 + 13][MAXN]; int conjdan[MAXY * 4 + 13][MAXN]; int weight[MAXY * 4 + 13]; int main() { memset(conjbam, -1, sizeof conjbam); memset(conjdan, -1, sizeof conjdan); int n, m; cin >> n >> m; bam.resize(n); dan.resize(m); for (int i = 0; i < n; i++) { cin >> bam[i]; bam[i] += MAXY; cntbam[bam[i]]++; } for (int i = 0; i < m; i++) { cin >> dan[i]; dan[i] += MAXY; cntdan[dan[i]]++; } sort(bam.begin(), bam.end()); bam.erase(unique(bam.begin(), bam.end()), bam.end()); sort(dan.begin(), dan.end()); dan.erase(unique(dan.begin(), dan.end()), dan.end()); set<int> mids; for (int i = 0; i < bam.size(); i++) { for (int j = 0; j < dan.size(); j++) { mids.insert(bam[i] + dan[j]); conjdan[bam[i] + dan[j]][i] = j; conjbam[bam[i] + dan[j]][j] = i; weight[bam[i] + dan[j]]++; } } vector<int> v(mids.begin(), mids.end()); sort(v.begin(), v.end(), [](const int x, const int y) { return weight[x] > weight[y]; }); int ans = 0; for (int i = 0; i < v.size() && i < 10; i++) { for (int j = i; j < v.size(); j++) { vector<bool> bexist(bam.size(), false); vector<bool> dexist(dan.size(), false); for (int k = 0; k < bam.size(); k++) { int l = conjdan[v[i]][k]; if (l != -1) dexist[l] = true, bexist[k] = true; l = conjdan[v[j]][k]; if (l != -1) dexist[l] = true, bexist[k] = true; } int tmp = 0; for (int i = 0; i < bexist.size(); i++) { if (bexist[i]) tmp += cntbam[bam[i]]; } for (int i = 0; i < dexist.size(); i++) { if (dexist[i]) tmp += cntdan[dan[i]]; } ans = max(ans, tmp); } } cout << ans << endl; return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; bool can1[66]; bool can2[66]; long long mask1[44444]; long long mask2[44444]; int BC(long long x) { return __builtin_popcount(x >> 31) + __builtin_popcount(x & 2147483647ll); } int main() { int n, m; cin >> n >> m; vector<int> Y1, Y2; for (int i = 0; i < n; i++) { int y; cin >> y; y += 10000; y = y * 2; Y1.push_back(y); } for (int i = 0; i < m; i++) { int y; cin >> y; y += 10000; y = y * 2; Y2.push_back(y); } set<int> poss; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { poss.insert((Y1[i] + Y2[j]) / 2); } vector<int> poss_vec(poss.begin(), poss.end()); for (int i = 0; i < 44444; i++) mask1[i] = mask2[i] = 0ll; for (int p : poss_vec) { for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { int y1 = Y1[i]; int y2 = Y2[j]; if ((y1 + y2) / 2 == p) { mask1[p] |= (1ll << i); mask2[p] |= (1ll << j); } } } int ans = 0; for (int p1 : poss_vec) for (int p2 : poss_vec) { long long m1 = (mask1[p1] | mask1[p2]); long long m2 = (mask2[p1] | mask2[p2]); ans = max(ans, BC(m1) + BC(m2)); } cout << ans << endl; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") long long mul(long long a, long long b) { return (a * b) % (1000000007); } long long add(long long a, long long b) { return (a + b) % (1000000007); } long long sub(long long a, long long b) { return ((a - b) % (1000000007) + (1000000007)) % (1000000007); } void upd(long long &a, long long b) { a = (a % (1000000007) + b % (1000000007)) % (1000000007); } inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int a[1123456] = {}, b[1123456] = {}; vector<int> v; bool us1[(1123456)] = {}, us2[(1123456)] = {}; long long ans1[(1123456)] = {}, ans2[(1123456)] = {}; int n, m; void ck(int id) { int h = v[id]; for (int i = 0; i < n; i++) { int x = 2 * h - a[i]; if (us2[x]) ans1[id] |= 1LL << i; } for (int i = 0; i < m; i++) { int x = 2 * h - b[i]; if (us1[x]) ans2[id] |= 1LL << i; } } int main() { cin >> n >> m; for (int i = 0; i < n; i++) a[i] = (read() + 10000) * 2; for (int i = 0; i < m; i++) b[i] = (read() + 10000) * 2; for (int i = 0; i < n; i++) us1[a[i]] = 1; for (int i = 0; i < m; i++) us2[b[i]] = 1; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { v.push_back((a[i] + b[j]) / 2); } sort((v).begin(), (v).end()); v.erase(unique((v).begin(), (v).end()), v.end()); int res = 0, sz = ((v).size()); for (int i = 0; i < sz; i++) ck(i); for (int i = 0; i < sz; i++) for (int j = i; j <= sz - 1; j++) { res = max(res, __builtin_popcountll(ans1[i] | ans1[j]) + __builtin_popcountll(ans2[i] | ans2[j])); ; } cout << res << endl; return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; const int N = 66; int x[N], xx[N]; int n, m; map<double, pair<long long, long long> > mp; pair<long long, long long> Or(pair<long long, long long> a, pair<long long, long long> b) { return {a.first | b.first, a.second | b.second}; } int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", x + i); for (int i = 0; i < m; i++) scanf("%d", xx + i); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { double mid = 1.0 * (x[i] + xx[j]) / 2.0; mp[mid] = Or(mp[mid], {1ll << i, 1ll << j}); } int ans = 0; for (auto p1 : mp) for (auto p2 : mp) { long long m1 = p1.second.first | p2.second.first; long long m2 = p1.second.second | p2.second.second; ans = max(ans, __builtin_popcountll(m1) + __builtin_popcountll(m2)); } printf("%d\n", ans); return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; int cal(long long n) { int ans = 0; while (n) { ans++; n -= (n & -n); } return ans; } const int N = 60; int a[N + 10], b[N + 10]; long long sx[40000 + 10], sy[40000 + 10]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= m; i++) scanf("%d", &b[i]); set<int> s; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { sx[a[i] + b[j] + 20000] |= (1ll << i - 1); sy[a[i] + b[j] + 20000] |= (1ll << j - 1); s.insert(a[i] + b[j]); } } int ans = 0; for (set<int>::iterator it1 = s.begin(); it1 != s.end(); it1++) { for (set<int>::iterator it2 = s.begin(); it2 != s.end(); it2++) { int tx = *it1, ty = *it2; ans = max(ans, cal(sx[tx + 20000] | sx[ty + 20000]) + cal(sy[tx + 20000] | sy[ty + 20000])); } } printf("%d", ans); return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; inline int conv(int x) { if (x < 0) { x += N; } return x; } int A[N], B[N]; bitset<65> grpA[N]; bitset<65> grpB[N]; set<int> poss; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> A[i]; } for (int i = 1; i <= m; i++) { cin >> B[i]; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { int mid = (A[i] + B[j]); int c = conv(mid); poss.insert(c); grpA[c][i] = 1; grpB[c][j] = 1; } } int ans = 0; for (auto i : poss) { for (auto j : poss) { bitset<65> setA; bitset<65> setB; setA = grpA[i] | grpA[j]; setB = grpB[i] | grpB[j]; ans = max(ans, (int)(setA.count() + setB.count())); } } cout << ans << "\n"; return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> #pragma GCC optimize "03" using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; int a[N], b[N]; vector<int> f[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int j = 1; j <= m; j++) cin >> b[j]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { f[a[i] + b[j] + 20000].push_back(i); f[a[i] + b[j] + 20000].push_back(n + j); } } vector<int> v; for (int i = 0; i <= 40000; i++) { if ((int)f[i].size()) v.push_back(i); } int d[40005] = {0}, ans = 0; ; for (int i = 0; i < (int)v.size(); i++) { for (int j = i; j < (int)v.size(); j++) { int c = 0; for (auto x : f[v[i]]) if (d[x] == 0) d[x] = 1, c++; for (auto x : f[v[j]]) if (d[x] == 0) d[x] = 1, c++; for (auto x : f[v[i]]) d[x] = 0; for (auto x : f[v[j]]) d[x] = 0; ans = max(ans, c); } } cout << ans; return 0; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); int n, m, p; cin >> n >> m; vector<int> V(n), W(m); for (int i = 0; i < n; ++i) cin >> V[i]; for (int i = 0; i < m; ++i) cin >> W[i]; set<int> all; for (int x : V) for (int y : W) all.insert(x + y); vector<int> av; for (int x : all) av.push_back(x); int idx[50000]; int ile = av.size(); for (int i = 0; i < ile; ++i) idx[av[i] + 25000] = i; vector<set<int>> h(ile); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) { p = idx[V[i] + W[j] + 25000]; h[p].insert(i + m); h[p].insert(j); } int ans = 0; vector<int> ab(30000); for (int i = 0; i < ile; ++i) { for (int j = i; j < ile; ++j) { ab.clear(); auto it = set_union((h[i]).begin(), (h[i]).end(), (h[j]).begin(), (h[j]).end(), ab.begin()); ans = max(ans, (int)(it - ab.begin())); } } cout << ans << endl; }
CPP
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
n, m = map(int, input().strip().split()) y1 = list(map(int, input().strip().split())) y2 = list(map(int, input().strip().split())) y1.sort() y2.sort() u1 = list() u2 = list() p = 0 while p < n: q = p while q < n and y1[q] == y1[p]: q += 1 u1.append((y1[p], q - p)) p = q p = 0 while p < m: q = p while q < m and y2[q] == y2[p]: q += 1 u2.append((y2[p], q - p)) p = q # print(u1) # print(u2) n = len(u1) m = len(u2) res = 0 for i in range(n): for j in range(m): ya = u1[i][0] + u2[j][0] # first small ship y1_stat = [True] * n y2_stat = [True] * m for ii in range(n): for jj in range(m): if u1[ii][0] + u2[jj][0] == ya: y1_stat[ii] = False # right large ship destroyed y2_stat[jj] = False # left large ship destroyed f = dict() for ii in range(n): for jj in range(m): yb = u1[ii][0] + u2[jj][0] # second small ship inc = 0 if y1_stat[ii]: inc += u1[ii][1] if y2_stat[jj]: inc += u2[jj][1] if yb in f: f[yb] += inc else: f[yb] = inc yb = -1 if f: yb = max(f, key=f.get) for ii in range(n): for jj in range(m): if u1[ii][0] + u2[jj][0] == yb: y1_stat[ii] = False y2_stat[jj] = False cur = 0 cur += sum(u1[ii][1] for ii in range(n) if not y1_stat[ii]) cur += sum(u2[jj][1] for jj in range(m) if not y2_stat[jj]) res = max(res, cur) print(res)
PYTHON3
993_C. Careful Maneuvering
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100. Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots. Input The first line contains two integers n and m (1 ≀ n, m ≀ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively. The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the first group. The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≀ 10 000) β€” the y-coordinates of the spaceships in the second group. The y coordinates are not guaranteed to be unique, even within a group. Output Print a single integer – the largest number of enemy spaceships that can be destroyed. Examples Input 3 9 1 2 3 1 2 3 7 8 9 11 12 13 Output 9 Input 5 5 1 2 3 4 5 1 2 3 4 5 Output 10 Note In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed. In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.
2
9
#include <bits/stdc++.h> using namespace std; int bcnt(long long a) { long long r(0); while (a) { r += a & 1; a >>= 1; } return r; } map<int, long long> lma, rma; int __pre[int(1 << 20)]; int main() { for (int i(0); i < int(1 << 20); ++i) __pre[i] = bcnt(i); int n, m; cin >> n >> m; map<int, vector<int> > L, R; for (int i(0), y; i < n; ++i) { cin >> y; y *= 2; L[y].push_back(i); } for (int i(0), y; i < m; ++i) { cin >> y; y += 20000; y *= 2; R[y].push_back(i); } set<int> pt; for (auto l : L) for (auto r : R) pt.insert((l.first + r.first) / 2); for (int p : pt) { for (auto l : L) if (R.count(l.first + (p - l.first) * 2)) for (int i : R[l.first + (p - l.first) * 2]) rma[p] |= 1LL << i; for (auto r : R) if (L.count(r.first + (p - r.first) * 2)) for (int i : L[r.first + (p - r.first) * 2]) lma[p] |= 1LL << i; } int ans(0); for (int i : pt) for (int j : pt) ans = max(ans, __builtin_popcountll(lma[i] | lma[j]) + __builtin_popcountll(rma[i] | rma[j])); cout << ans; }
CPP
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
# get number of integers and noumber of colours n, m = map(int, raw_input().split()) # paint integer c = map(int, raw_input().split()) c.insert(0, c[0]) my_ints = map(int, raw_input().split()) result = [] result.append(c[my_ints[0]]) # for every integer in my_ints for integer in range(1, len(my_ints)): # starting integer val = my_ints[integer] start = result[len(result)-1]+1 while True: # start is divisible by c[integer] #print c, integer if start%c[val] == 0: count = 0 for i in range(val+1, m+1): if start%c[i] == 0: count += 1 break # start is only divisible by c[integer] if count == 0: break else: start += 1 else: start += 1 result.append(start) print result[len(result)-1]
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
import sys def solve(): n, m = map(int, sys.stdin.readline().split()) mints = map(int, sys.stdin.readline().split()) nints = map(int, sys.stdin.readline().split()) cur_num = 1 for val in nints: cur_num = get_next_num(cur_num, val - 1, mints) print cur_num def get_next_num(cur_num, val, mints): c_val = mints[val] candidate_val = cur_num - (cur_num % c_val) + c_val while not is_valid(candidate_val, val, mints): candidate_val = candidate_val + c_val return candidate_val def is_valid(num, val, mints): for ind in range(val+1, len(mints)): if num % mints[ind] == 0: return False return True solve()
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
(n, m) = map(int, raw_input().strip().split(' ')) c = map(int, raw_input().strip().split(' ')) d = map(int, raw_input().strip().split(' ')) ans = [0]*n ans[0]=c[d[0]-1] def isValid(num, label): for i in range(label+1, m): if num%c[i]==0: return False return True def setNum(prev, ci, ci_label): start = (prev/ci)+1 while isValid((start*ci), ci_label)==False: start=start+1 return (start*ci) for i in range(1, n): ans[i] = setNum(ans[i-1], c[d[i]-1], d[i]-1) print ans[n-1]
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
n,m=map(int,raw_input().split()) d=map(int,raw_input().split()) col=[i-1 for i in map(int,raw_input().split())] #print col,d c=d[0] for i in col: flag=True while True: if c%d[i]==0: for j in d[i+1:]: if c%j==0: c=c+d[i] break else: break flag=False else: c=c+1 c=c+1 print c-1
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
# Keep coding and change the world..And do not forget anything..Not Again.. n, m = map(int, raw_input().split()) c = map(int, raw_input().split()) nums = map(int, raw_input().split()) i = 0 num = 0 while i < n: div = c[nums[i] - 1] lst = c[nums[i]:] x = num + (div - num % div) while True: for item in lst: if x % item == 0: break else: break x += div num = x i += 1 print num
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' nums= raw_input().split() n = int(nums[0]) m = int(nums[1]) temp_muls = raw_input().split() temp_lst = raw_input().split() muls = [] lst = [] for i in temp_muls: muls.append(int(i)) for i in temp_lst: lst.append(int(i)) output = [] d = 0 multiple = 0 for i in lst: d = int(multiple/muls[i-1])+1 while(1): product = muls[i-1]*d flag = 1 for j in range(i, m): if product % muls[j] == 0: flag = 0 if flag: break d += 1 multiple = product output.append(product) print output[-1]
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
import sys L=map(int, sys.stdin.read().split()) n, m=L[0], L[1] c=L[2: 2+m] L=L[2+m:] res=1 for x in xrange(len(L)): if x==0: res*=c[L[x]-1] else: temp=(res/c[L[x]-1])+1 while True: flag=0 res=c[L[x]-1]*temp for y in xrange(L[x], len(c)): if res%c[y]==0: temp+=1 flag=1 break if flag==0: break print res
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' def not_divisible(num, lists): for n in lists: if num%n == 0: return False return True def find_next_num(color, prev_ans, colors): ans = max(colors[color-1], prev_ans) while ans%colors[color-1] != 0 or not not_divisible(ans, colors[color:]) or ans <= prev_ans: ans += 1 return ans n, m = map(int, raw_input().split(" ")) colors = map(int, raw_input().split(" ")) numbers = map(int, raw_input().split(" ")) prev_ans = ans = 0 for i in range(len(numbers)): ans = (find_next_num(numbers[i], prev_ans, colors)) prev_ans = ans print ans
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
N,M=list(map(int,raw_input().strip().split(' '))) Co=list(map(int,raw_input().strip().split(' '))) Do=list(map(int,raw_input().strip().split(' '))) A=[] for i in xrange(N): t=Do[i]-1 if len(A)==0: C=1 else: C=A[i-1]//Co[t]+1 while True: x=Co[t]*C for j in xrange(t+1,M): if x % Co[j]==0: C+=1 break else: A.append(x) break print A[N-1]
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
(n, m) = map(int, raw_input().strip().split(' ')) c = map(int, raw_input().strip().split(' ')) d = map(int, raw_input().strip().split(' ')) ans=c[d[0]-1] def isValid(num, label): for i in range(label+1, m): if num%c[i]==0: return False return True def setNum(prev, ci, ci_label): start = (prev/ci)+1 while isValid((start*ci), ci_label)==False: start=start+1 return (start*ci) for i in range(1, n): ans = setNum(ans, c[d[i]-1], d[i]-1) print ans
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
n,m=map(int,raw_input().split()) d=map(int,raw_input().split()) col=[i-1 for i in map(int,raw_input().split())] #print col,d c=d[0] for i in col: flag=True while flag: if c%d[i]==0: #and i<m: for j in d[i+1:]: if c%j==0: c=c+d[i] break else: flag=False else: c=c+1 c=c+1 print c-1
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
[n,m] = map(int,raw_input().strip().split(' ')) M = map(int,raw_input().strip().split(' ')) N = map(int,raw_input().strip().split(' ')) c = [] ct = 1 for i in range(n): a = N[i] b = M[a:] j = ct while True: if j % M[a-1] == 0: temp = [j%rem for rem in b] if 0 not in temp: ct = j + 1 break j += 1 print j
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
N,M=map(int,raw_input().split()) divs=map(int,raw_input().split()) cols=[i-1 for i in map(int,raw_input().split())] i=0 for num in xrange(N): divider=divs[cols[num]] i=(i/divider+1)*divider # next possible while 0 in [i%divs[j] for j in xrange(cols[num]+1,M)]: i+=divider print i
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
#assorted arrangement n,m=map(int,raw_input().split()) a=map(int,raw_input().split()) b=map(int,raw_input().split()) l=[] for i in range(n): if i==0: l.append(a[b[i]-1]) else: s=l[i-1]+1 while s%(a[b[i]-1])!=0: s=s+1 done=False for j in range(b[i],m): if s%a[j]==0: done=True break while done: s=s+a[b[i]-1] count=0 for j in range(b[i],m): if s%a[j]==0: count=count+1 break if count==0: done=False l.append(s) print l[n-1]
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
n,m=map(int,raw_input().split()) d=map(int,raw_input().split()) col=[i-1 for i in map(int,raw_input().split())] #print col,d c=d[0] for i in col: while True: if c%d[i]==0: for j in d[i+1:]: if c%j==0: c=c+d[i] break else: break else: c=c+1 c=c+1 print c-1
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
def find_num(j,d) : val = d/c[j] arr = c[j+1::] while 1 : val += 1 count = 0 z = val*c[j] for _ in xrange(len(arr)) : if z % arr[_] == 0 : count = 1 break if count == 0 : return z n,m = map(int,raw_input().split()) c = map(int,raw_input().split()) a = map(int,raw_input().split()) pre = 0 min_v = c[0] for i in a : min_v = min(c[i-1],min_v) pre = find_num(i-1,pre) print pre
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
import sys def solution(): n, m = map(int, raw_input().strip().split(' ')) arr_m = list(map(int, raw_input().strip().split(' '))) arr = list(map(int, raw_input().strip().split(' '))) '''divide_array = [[] for i in xrange(m)] for i in xrange(m): for j in xrange(i+1, m): if arr_m[j] % arr_m[i] == 0: divide_array[i].append(arr_m[j])''' maxi = 0 for i in arr: #print "^^^", maxi, arr_m[i - 1], divide_array[i - 1], maxi += (arr_m[i - 1] - (maxi % arr_m[i - 1])) if maxi % arr_m[i - 1] != 0 else arr_m[i-1] jump = arr_m[i-1] #print jump while True: #print "***",maxi passed = True if maxi % arr_m[i-1] == 0: for j in arr_m[i:]: #print "&&&",j if maxi % j == 0: passed = False break if passed: break maxi = maxi + jump print "{}".format(maxi) solution()
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
v = raw_input().split(' ') value = [int(num) for num in v] number = value[0] color = value[1] v = raw_input().split(' ') c = [int(num) for num in v] n = raw_input().split(' ') num = [int(i) for i in n] p_num = 1 new_num = [] flag = True for i in num: while(flag == True): if(p_num % c[i-1] == 0): if(i == len(c)): if(p_num % c[i-1] == 0): flag = False else: flag = True else: for j in range(i,len(c)): if(p_num % c[j] == 0): p_num = p_num + 1 flag = True break else: flag = False else: p_num = p_num + 1 if(flag == False): new_num.append(p_num) p_num = p_num + 1 flag = False flag = True print new_num[len(new_num)-1]
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
a1=raw_input("").split(" ") N=(int)(a1[0]) M=(int)(a1[1]) arr_M=raw_input("").split(" ") M_int=[] real=[] for i in range(len(arr_M)): M_int.append((int)(arr_M[i])) arr_N=raw_input("").split(" ") color_int=[] for i in range(len(arr_N)): color_int.append((int)(arr_N[i])) real.append(1) for i in range(len(color_int)): color=color_int[i]-1 if i==0: real[i]=M_int[color] continue color_number=M_int[color] start_value=((real[i-1]/color_number) + 1)*color_number if color == len(M_int)-1: real[i]=start_value else: while(1): check=0 for j in range(color+1,len(M_int)): if start_value%M_int[j] ==0: check =1 break if check == 0: break else: start_value+=M_int[color] real[i]=start_value print real[-1]
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
def process(c, aa): def div(num, arr): for i in arr: if num % i == 0: return False return True ans = [] no = 1 con = c[aa[0] - 1] carr = c[aa[0]:] while len(ans) != len(aa): ans = [] while True: if no % con == 0 and div(no, carr): ans.append(no) break else: no += 1 tmp = no + 1 for i in xrange(1, len(aa)): index = c[aa[i] - 1] cindex = c[aa[i]:] while tmp <= 2000000000000: if tmp % index == 0 and div(tmp, cindex): ans.append(tmp) tmp += 1 break else: tmp += 1 return max(ans) M, N = map(int, raw_input().strip(" \n").split(" ")) c = map(int, raw_input().strip(" \n").split(" ")) aa = map(int, raw_input().strip(" \n").split(" ")) print process(c, aa)
PYTHON
assorted-arrangement-3
You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 to m, paint numbers divisible by c[i] with color i. If multiple rules apply to a number, only the last rule applies. You sorted your set of numbers and painted them. It turns out that no number was left unpainted. Unfortunately, you lost the set of numbers you had originally. Return the smallest possible value of the maximum number in your set. The input will be constructed such that it's guaranteed there is at least one set of numbers that is consistent with the given information. Input format The first line will contain two space separated integers n,m. The second line will contain m space separated integers. The i-th integer in this line denotes c[i]. The third line will contain n space separated integers. This j-th integer in this line denotes the color of the j-th smallest number in your set. Output format Print a single integer on its own line, the minimum possible value of the largest number in your set. Constraints For all subtasks: 1 ≀ n 1 ≀ m Elements in c will be in strictly increasing order. 1 ≀ c[i] ≀ 100 Subtask 1 (65 pts): n ≀ 100 m = 2 c[2] is divisible by c[1] Subtask 2 (25 pts): n ≀ 100,000 m ≀ 5 Subtask 3 (10 pts): n ≀ 100,000 m ≀ 50 SAMPLE INPUT 6 4 3 6 7 9 1 2 1 1 4 3 SAMPLE OUTPUT 42 Explanation For the first sample, we have four colors and six numbers in our set. All numbers with color 1 are divisible by 3, but not 6, 7, or 9. All numbers with color 2 are divisible by 6, but not 7 or 9. All numbers with color 3 are divisible by 7 but not 9. All numbers with color 4 are divisible by 9. One example of the original set could have been {3,6,15,33,36,42}.
3
0
n,m=map(int,raw_input().split()) d=map(int,raw_input().split()) col=[i-1 for i in map(int,raw_input().split())] #print col,d c=d[0] for i in col: flag=True while flag: if c%d[i]==0: for j in d[i+1:]: if c%j==0: c=c+d[i] break else: flag=False else: c=c+1 c=c+1 print c-1
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
import sys def main(): I=sys.stdin.readlines() x=int(I[0]) for i in xrange(x): n,t=map(int,I[i+1].split()) for j in xrange(t): if(n%2==0): n=n/2 else: n=n-((n+1)/2) n=n-(n//4) print n main()
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
q = int(raw_input()) while q: q-=1 n,t = map(int, raw_input().split()) while t: t-=1 if n%2==0: n/=2 else: n-= (n+1)/2 n-= n/4 print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
q = input() while q>0: n,t = map(int, raw_input().split()) table = n while t>0: if table%2 == 0: table = table - table/2 else: table = table -(table+1)/2 table = table-table/4 t=t-1 print table q=q-1
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
for tc in range(int(raw_input())): n,t=[int(i) for i in raw_input().split()] for i in range(t): if n%2==0: n-=n//2 else: n-=(n+1)//2 n-=n//4 print(n)
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' for i in range(int(raw_input())): c, t = [int(i) for i in raw_input().split()] for i in range(t): if c%2 == 0: c -= (c/2) else: c -= ((c+1)/2) c -= c//4 print c
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
test = input() while (test>0): test = test -1; stri = raw_input() stri = stri.split() N = int(stri[0]) T = int(stri[1]) while(T>0 and N>0): T = T-1 # print N, if(N%2==0 ): x = N/2 N = N - x elif(N%2==1 ): x = (N+1)/2 N = N-x # print N, if(N//4>0): x = N//4 N = N-x # print N print N
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
for i in range(int(raw_input())): c,t = [int(i) for i in raw_input().split()] for i in range(t): if c%2 == 0: c -= (c/2) elif c%2==1: c -= ((c+1)/2) c -= c//4 print c
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
for i in range(input()): n,t = map(int,raw_input().split()) cpres = 0 rem = n for j in range(t): if rem%2: rem -= (rem+1)/2 else: rem -= rem/2 rem -= rem//4 print rem
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' q = input() for cases in range(q): [n,t] = [int(x) for x in raw_input().split()] for i in range(t): n = n//2 n = n - (n//4) print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
t = int(raw_input()) while t: t-=1 c,d=map(int,raw_input().split()) while d: d-=1 c = c/2 x = c/4 c= c-x if c<0: c=0 print c
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
q = int(input()) for i in range(q): n,t = list(map(int, raw_input().split())) day = 1 while day <= t: if n%2 == 0: n -= (n/2) else: n -= (n+1)/2 n -= n//4 day += 1 print(n)
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
q = int(raw_input()) while q: n, t = raw_input().split() n = int(n) t = int(t) remCandies = n while t: if remCandies%2==0: remCandies=remCandies/2 else: remCandies=remCandies - (remCandies+1)/2 remCandies = remCandies - (remCandies/4) t = t-1 print remCandies q = q - 1
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
k=int(raw_input()) for i in xrange(0,k): r=str(raw_input()) a,b=(int(x) for x in r.split()) for j in xrange(0,b): if(a%2==0): a=a/2 else: a=a-(a+1)/2 a=a-a/4 print(a)
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' t=input() while t>0: s=raw_input() l=s.split() c=int(l[0]) d=int(l[1]) while d>0: if c>0: if(c%2==0): we=c/2 c=c-we sd=c/4 c=c-sd else: we=(c+1)/2 c=c-we sd=c/4 c=c-sd d=d-1 print c t=t-1
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
q = input() for _ in xrange(q): n,t = map(int,raw_input().split()) for i in xrange(t): n=n/2 n=n-(n//4) print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
n= int(raw_input()) for i in range(n): X,T = map(eval, raw_input().split()) for j in range(T): if(X%2==0): X=X/2 else: X=X -(X+1)/2 X = X-X//4 print X
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
cases = int(raw_input()) for case in range(cases): N, T = map(int, raw_input().split()) for i in range(T): if N % 2 == 0: N = N - N / 2 else: N = N - (N + 1) / 2 N = N - N / 4 print N
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
t=int(raw_input()) for k in xrange(t): n,d=map(int,raw_input().split()) for i in xrange(d): if n%2==0: n=n-int(n/2) else: n=n-int((n+1)/2) n=n-int(n/4) print(n)
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
def floor(x): return int(x) t=int(raw_input()) while(t>0): t=t-1 x,n=raw_input().split() x=int(x) n=int(n) for num in range(n): if(x%2==0): x=x-(x/2) else: x=x-((x+1)/2) x=x-floor(x/4) print x
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
t = input() while t: t -=1 a,b = raw_input().split(" ") a = int(a) b = int(b) for i in range (0,b): if a%2 == 0: a = a - a/2 else: a = a - (a+1)/2 a = a - a/4 print a
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
for _ in xrange(input()): n,t=map(int,raw_input().split()) for _ in xrange(t): if n%2==0: n=n-n/2 else: n=n-(n+1)/2 n=n-n/4 print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
q = int(raw_input()) for i in range(q): data = [int(i) for i in raw_input().split(" ")] n = data[0] t = data[1] for i in range(t): if n % 2 == 0: n = n - n/2 else: n = n - (n + 1)/2 n = n - (n//4) print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
T = int(raw_input()) for _ in xrange(T): N,K = map(int,raw_input().split()) for _ in xrange(K): if N%2 == 0: N -= N/2 else: N -= (N+1)/2 N -= N/4 print N
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
tc=int(raw_input()) for i in range(tc): n,t=raw_input().split(' ') n,t=int(n),int(t) i=0 while i<t: if n%2==0: n=n/2 else: n=(n-1)/2 n=n-n/4 i=i+1 print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
cases = int(raw_input()) for case in range(cases): N, T = map(int, raw_input().split()) for i in range(T): if N % 2 == 0: N /= 2 else: N = N - (N + 1) / 2 N = N - N / 4 print N
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
t=input() while t: t-=1 n,k=map(int,raw_input().split()) for x in range(k): if (n%2==0): n-=n/2 else: n-=(n+1)/2 n-=n/4 if (n<0): n=0 print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
import sys cases = int(sys.stdin.readline()) for case in range(cases): [N,T] = [int(x) for x in sys.stdin.readline().split()] cur = N for day in range(T): if cur % 2 == 0: cur = cur - cur/2 else: cur = cur - (cur + 1)/2 cur = cur - cur/4 print cur
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
q = input() while(q): q -= 1 n,t = map(int,raw_input().split()) while(t): t -= 1 if(n%2): n -= (n+1)/2 else: n -= n/2 n -= n/4 print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
tc = input() for _ in range(tc): n, t = map(int, raw_input().split()) while t > 0: if n%2 == 0: n = n - (n/2) else: n = n - ((n+1)//2) n = n - (n/4) t -= 1 print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
q = int(raw_input()) while q > 0: q -= 1 l = map(int, raw_input().split(' ')) n = l[0] t = l[1] num = n while t > 0: t -= 1 if num % 2 == 0: num /= 2 else: num = num - (num + 1) / 2 num = num - num//4 print num
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
tc = int(raw_input()) while tc: N,T = map(int,raw_input().split(" ")) while T: if N%2 == 0: deduc = N / 2 else: deduc = (N+1)/2 N = N - deduc deduc = N//4 N = N - deduc T = T - 1 print N tc = tc -1
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
__author__ = 'praveen' n1 = int(raw_input()) while n1: n , t = map( int , raw_input().split()) while t: if n % 2 == 0: rem= n // 2 else: rem = (n+1)/2 n-=rem rem = n // 4 n-=rem t-=1 print (n) n1-=1
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
q = int(raw_input()) while (q>0): nos = raw_input().split() n = int(nos[0]) t = int(nos[1]) while(t>=1): if (n%2==0): n = n - n/2 else: n = n - (n+1)/2 n = n - n//4 t = t-1 print n q = q-1
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' x=input() while x>0: x-=1 n,t=raw_input().split(" ") n,t=int(n),int(t) while t>0: t-=1 if n%2==0: n=n-(n/2) else: n=n-((n+1)//2) n=n-(n/4) print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' Q = int(raw_input()) for i in xrange(Q): N,T = map(int,raw_input().strip().split()) while(T!=0): if N < 0: N =0 break if N%2 == 0: N = N-(N/2) #print "Even",N else : N = N-(N+1)/2 N = N -N/4 #print "Odd",N T=T-1 print N
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
t=int(raw_input()) while(t>0): t=t-1 x,n=raw_input().split() x=int(x) n=int(n) for num in range(n): if(x%2==0): x=x-(x/2) else: x=x-((x+1)/2) x=x-(x/4) print x
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
Q=int(raw_input()) for n in range(Q): N, T=raw_input().split() N=int(N) T=int(T) for x in range(T): if N%2==0: N=N-N/2 N=N-N/4 else: N=N-(N+1)/2 N=N-N/4 if N==0: print 0 continue else: print N
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name''' for _ in range(int(raw_input())): n,t=map(long,raw_input().split()) while t: t-=1 if n%2: n-=((n+1)/2) else: n/=2 n=n-long(n/4) print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
test=int(raw_input()) while test>0: test=test-1 n,t=map(int,raw_input().split()) while t>0: t=t-1 if(n%2==0): n=n/2 else: n=n-((n+1)/2) n=n-int(n/4) print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
import sys t = int(sys.stdin.readline()) while t: t-=1 #print sys.stdin.readline().strip().split(" ") n, r = sys.stdin.readline().strip().split(" ") n = int(n) r = int(r) for i in xrange(r): if n%2 == 0: n = n - n//2 else: n = n - (n+1)//2 n = n - n//4 print n
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
q=input() i=0 while i<q: n,t = map(int, raw_input().split()) #size, k for x in xrange(t): if n%2==0: n = n - n/2 else: n = n - (n+1)/2 n = n - n//4 print n i+=1
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
for _ in xrange(input()): x,t=map(int,raw_input().split()) for i in xrange(t): if(x%2==1): x-=(x+1)/2 else: x=x/2 x-=x//4 print x
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
Q = int(raw_input()) for loop in xrange(Q): N, T = map(int, raw_input().split()) for i in xrange(T): if N % 2 == 0: N -= N / 2 else: N -= (N + 1) / 2 N -= N / 4 print N
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' q=input() while q: inp=raw_input() inp=inp.split(' ') n=int(inp[0]) t=int(inp[1]) while t: if(n%2==0): n=n/2 else: n=n-(n+1)/2 n=n-n//4 t-=1 print n q-=1
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
for _ in range(int(raw_input())): n,t = map(int,raw_input().split()) c = n days=t while( t>0 ): if(c%2 == 0): c -= (c/2) elif(c%2==1): c -= ((c+1)/2) c -= c//4 t -= 1 print c
PYTHON
children-love-candies
Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X/2 candies. Otherwise, he will take (X+1)/2 candies. In addition, every day at 10 PM, another child will come and take X//4, where the "//" here represents integer division. Please, find the number of candies left at 11 PM after T days have passed. Input: The first line contains one integer, Q, the number of test cases. The next Q lines contain two integers, N and T. Output: Output Q lines, the answer for each test case. Constraints: 1 ≀ Q ≀ 10 1 ≀ N ≀ 10^16 1 ≀ T ≀ 50 SAMPLE INPUT 1 2 1 SAMPLE OUTPUT 1
3
0
inp = input() while(inp>0): n,t = map(int, raw_input().split()) for i in xrange(t): if(n%2 == 0): n = n-(n/2) else: n = n -((n+1)/2) n = n - n//4 print n inp -=1
PYTHON