Skip to content

Commit 840e984

Browse files
Add files via upload
1 parent 6b2c5f9 commit 840e984

File tree

5 files changed

+484
-0
lines changed

5 files changed

+484
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
void solve()
8+
{
9+
int no_of_elements, present_RAM;
10+
cin >> no_of_elements >> present_RAM;
11+
12+
vector <pair <int, int> > ram(no_of_elements);
13+
for(int i = 0; i < no_of_elements; i++)
14+
{
15+
cin >> ram[i].first;
16+
}
17+
18+
for(int i = 0; i < no_of_elements; i++)
19+
{
20+
cin >> ram[i].second;
21+
}
22+
23+
sort(ram.begin(), ram.end());
24+
25+
int answer = present_RAM;
26+
for(int i = 0; i < no_of_elements; i++)
27+
{
28+
if(ram[i].first <= answer)
29+
{
30+
answer += ram[i].second;
31+
}
32+
}
33+
34+
cout << answer << "\n";
35+
}
36+
37+
int main()
38+
{
39+
int no_of_test_cases;
40+
cin >> no_of_test_cases;
41+
42+
while(no_of_test_cases--)
43+
solve();
44+
45+
return 0;
46+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
int odd_till(int n)
8+
{
9+
return (n/2) + n%2;
10+
}
11+
12+
void solve()
13+
{
14+
int left, right, no_of_operations;
15+
cin >> left >> right >> no_of_operations;
16+
17+
int odd_integers = odd_till(right) - odd_till(left - 1);
18+
19+
cout << (no_of_operations >= odd_integers || (left == right && left != 1) ? "YES" : "NO") << "\n";
20+
}
21+
22+
int main()
23+
{
24+
int no_of_test_cases;
25+
cin >> no_of_test_cases;
26+
27+
while(no_of_test_cases--)
28+
solve();
29+
30+
return 0;
31+
}
32+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
long long power_mod(long long x, long long power, long long m)
7+
{
8+
long long result = 1;
9+
10+
while(power > 0)
11+
{
12+
if(power%2 == 1)
13+
result = (result*x)%m;
14+
15+
x = (x*x)%m;
16+
power = power >> 1;
17+
}
18+
19+
return result;
20+
}
21+
22+
long long inverse(long long x, long long m)
23+
{
24+
return power_mod(x, m - 2, m);
25+
}
26+
27+
void solve()
28+
{
29+
long long no_of_moves, add_moves, range;
30+
cin >> no_of_moves >> add_moves >> range;
31+
32+
const int MOD = 1e9 + 7;
33+
vector <vector <long long> > score(no_of_moves + 1, vector <long long> (add_moves + 1, 0));
34+
for(int i = 0; i <= no_of_moves; i++)
35+
{
36+
for(int j = 0; j <= add_moves; j++)
37+
{
38+
if(i == 0 || j == 0)
39+
{
40+
score[i][j] = 0;
41+
continue;
42+
}
43+
if(j == i)
44+
{
45+
score[i][j] = (range*j)%MOD;
46+
continue;
47+
}
48+
49+
score[i][j] = (score[i - 1][j - 1] + score[i - 1][j])%MOD;
50+
score[i][j] *= inverse(2, MOD);
51+
score[i][j] %= MOD; //cout << "F(" << i << "," << j << ") = " << score[i][j] << "\n";
52+
}
53+
}
54+
55+
cout << score[no_of_moves][add_moves] << "\n";
56+
}
57+
58+
int main()
59+
{
60+
int no_of_test_cases;
61+
cin >> no_of_test_cases;
62+
63+
while(no_of_test_cases--)
64+
solve();
65+
66+
return 0;
67+
}
68+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
const int BLACK = 0, WHITE = 1;
7+
8+
int get_colour(int x, int y)
9+
{
10+
return (x + y)%2;
11+
}
12+
13+
int is_inside(int i, int j, int rows, int columns)
14+
{
15+
return (1 <= i && i <= rows && 1 <= j && j <= columns);
16+
}
17+
18+
int get_xor_sum(vector <vector <int> > &G, int n, int colour)
19+
{
20+
vector <vector <int> > counted(n + 1, vector <int> (n + 1, false));
21+
22+
const int NO_OF_NEIGHBOURS = 4;
23+
int next_x[NO_OF_NEIGHBOURS] = {-1, 0, 0, 1}, next_y[NO_OF_NEIGHBOURS] = {0, 1, -1, 0};
24+
int xor_sum = 0;
25+
for(int i = 1; i <= n; i++)
26+
{
27+
for(int j = 1; j <= n; j++)
28+
{
29+
if(get_colour(i, j) != colour)
30+
{
31+
continue;
32+
}
33+
34+
int counted_neighbours = 0;
35+
for(int k = 0; k < NO_OF_NEIGHBOURS; k++)
36+
{
37+
int next_i = i + next_x[k], next_j = j + next_y[k];
38+
39+
if(is_inside(next_i, next_j, n, n) && counted[next_i][next_j])
40+
{
41+
counted_neighbours++;
42+
}
43+
}
44+
45+
if(counted_neighbours == 0)
46+
{
47+
xor_sum ^= G[i][j];
48+
49+
for(int k = 0; k < NO_OF_NEIGHBOURS; k++)
50+
{
51+
int next_i = i + next_x[k], next_j = j + next_y[k];
52+
53+
if(is_inside(next_i, next_j, n, n))
54+
{
55+
counted[next_i][next_j] = true;
56+
}
57+
}
58+
}
59+
}
60+
}
61+
62+
return xor_sum;
63+
}
64+
65+
void solve()
66+
{
67+
int n;
68+
cin >> n;
69+
70+
vector <vector <int> > grid(n + 1, vector <int> (n + 1, 0));
71+
for(int i = 1; i <= n; i++)
72+
{
73+
for(int j = 1; j <= n; j++)
74+
{
75+
cin >> grid[i][j];
76+
}
77+
}
78+
79+
int answer = get_xor_sum(grid, n, BLACK)^get_xor_sum(grid, n, WHITE);
80+
cout << answer << "\n";
81+
}
82+
83+
int main()
84+
{
85+
int no_of_test_cases;
86+
cin >> no_of_test_cases;
87+
88+
while(no_of_test_cases--)
89+
solve();
90+
91+
return 0;
92+
}

0 commit comments

Comments
 (0)