Skip to content

Commit cff8402

Browse files
committed
.
1 parent ccb77b9 commit cff8402

18 files changed

+921
-29
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
2+
//------------------------------------------------------------------------------
3+
#include <iostream>
4+
#include <vector>
5+
// #include <bits/stdc++.h>
6+
// #include <cmath>
7+
// #include <algorithm>
8+
// #include <unordered_map>
9+
// #include <map>
10+
// #include <set>
11+
// #include <unordered_set>
12+
//------------------------------------------------------------------------------
13+
using namespace std;
14+
//------------------------------------------------------------------------------
15+
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
16+
#define v(Type) vector<Type>
17+
#define w(T) \
18+
int T; \
19+
cin >> T; \
20+
while (T--)
21+
#define int long long int
22+
#define mod 1000000007ll
23+
#define endl "\n"
24+
//------------------------------------------------------------------------------
25+
// Any fucntion can be called using Math.function_name();
26+
//------------------------------------------------------------------------------
27+
class Math
28+
{
29+
public:
30+
//Returns gcd of two numbers
31+
int gcd(int a, int b)
32+
{
33+
return (a % b == 0) ? b : gcd(b, a % b);
34+
}
35+
36+
//Returns lcm of two numbers
37+
int lcm(int a, int b)
38+
{
39+
return a * (b / gcd(a, b));
40+
}
41+
42+
// Returns flag array isPrime
43+
// isPrime[i] = true (if i is Prime)
44+
// isPrime[i] = false (if i is not Prime)
45+
vector<bool> *seiveOfEratosthenes(const int N)
46+
{
47+
vector<bool> *isPrime = new vector<bool>(N + 1, true);
48+
(*isPrime)[0] = (*isPrime)[1] = false;
49+
for (int i = 2; i * i <= N; ++i)
50+
if ((*isPrime)[i])
51+
for (int j = i * i; j <= N; j += i)
52+
(*isPrime)[j] = false;
53+
54+
return isPrime;
55+
}
56+
57+
//Returns (x ^ n)
58+
int pow(const int &x, int n)
59+
{
60+
if (n == 0)
61+
return 1;
62+
int h = pow(x, n / 2);
63+
return (n & 1) ? h * h * x : h * h;
64+
}
65+
66+
//Returns (x ^ n) % M
67+
int pow(const int &x, int n, const int &M)
68+
{
69+
if (n == 0)
70+
return 1;
71+
int h = pow(x, n / 2) % M;
72+
return (n & 1) ? (h * h * x) % M : (h * h) % M;
73+
}
74+
75+
//Returns all Primes <= N
76+
vector<int> *primesUptoN(const int N)
77+
{
78+
vector<bool> *isPrime = seiveOfEratosthenes(N);
79+
vector<int> *Primes = new vector<int>;
80+
if (2 <= N)
81+
(*Primes).push_back(2);
82+
for (int i = 3; i <= N; i += 2)
83+
if ((*isPrime)[i])
84+
(*Primes).push_back(i);
85+
return Primes;
86+
}
87+
88+
} Math;
89+
//------------------------------------------------------------------------------
90+
void solve()
91+
{
92+
int n, l, r, s;
93+
cin >> n >> l >> r >> s;
94+
v(int) A(n);
95+
v(int) Ans(n, 0);
96+
for (int i = 0; i < n; i++)
97+
A[i] = i + 1;
98+
int sum1 = 0, sum2 = 0;
99+
int window = r - l + 1;
100+
101+
for (int i = 0; i < window; i++)
102+
sum1 += A[i];
103+
for (int i = n - 1, j = 0; j < window; j++, i--)
104+
sum2 += A[i];
105+
106+
bool ans = sum1 <= s and s <= sum2;
107+
108+
if (ans)
109+
{
110+
int dp[n + 1][s + 1][window + 1];
111+
for (int i = 0; i <= n; i++)
112+
for (int j = 0; j <= s; j++)
113+
for (int k = 0; k <= window; k++)
114+
if (i == 0)
115+
dp[i][j][k] = true;
116+
else if (j == 0 or k == 0)
117+
dp[i][j][k] = false;
118+
else
119+
{
120+
if (A[i - 1] <= s)
121+
dp[i][j][k] = dp[i - 1][j - A[i - 1]][k] or dp[i - 1][j][k];
122+
else
123+
dp[i][j][k] = dp[i - 1][j][k];
124+
}
125+
126+
}
127+
else
128+
cout << -1;
129+
cout << endl;
130+
}
131+
//------------------------------------------------------------------------------
132+
int32_t main()
133+
{
134+
FastIO;
135+
136+
w(T)
137+
solve();
138+
139+
return 0;
140+
}
141+
//------------------------------------------------------------------------------
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"A. Review Site","group":"Codeforces - Educational Codeforces Round 107 (Rated for Div. 2)","url":"https://codeforces.com/contest/1511/problem/0","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1618238182748,"input":"4\n1\n2\n3\n1 2 3\n5\n1 1 1 1 1\n3\n3 3 2","output":"0\n2\n5\n2"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AReviewSite"}},"batch":{"id":"68539143-38b4-46dc-8ed0-5ce50fefbfd6","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeForces\\Educational Codeforces Round 107 (Rated for Div. 2)\\A_Review_Site.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"B. GCD Length","group":"Codeforces - Educational Codeforces Round 107 (Rated for Div. 2)","url":"https://codeforces.com/contest/1511/problem/B","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1618238881473,"input":"4\n2 3 1\n2 2 2\n6 5 5\n1 1 1","output":"11 492\n13 26\n140133 160776\n1 1"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BGCDLength"}},"batch":{"id":"ac8e9072-b8c3-4df4-a67e-13f87c1b164f","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeForces\\Educational Codeforces Round 107 (Rated for Div. 2)\\B_GCD_Length.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"C. Yet Another Card Deck","group":"Codeforces - Educational Codeforces Round 107 (Rated for Div. 2)","url":"https://codeforces.com/contest/1511/problem/C","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"input":"7 5\n2 1 1 4 3 3 1\n3 2 1 1 4\n","output":"5 2 3 1 5\n","id":1618240780728}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CYetAnotherCardDeck"}},"batch":{"id":"5d159028-f23b-499b-886f-fa23152cef07","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeForces\\Educational Codeforces Round 107 (Rated for Div. 2)\\C_Yet_Another_Card_Deck.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"D. Min Cost String","group":"Codeforces - Educational Codeforces Round 107 (Rated for Div. 2)","url":"https://codeforces.com/contest/1511/problem/D","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1618242344339,"input":"13 4","output":"aabacadbb"},{"input":"5 1\n","output":"aaaaa\n","id":1618242344349},{"input":"10 26\n","output":"codeforces\n","id":1618242344303},{"id":1618243248091,"input":"100 2","output":""}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"DMinCostString"}},"batch":{"id":"d9b430b4-34e7-4583-8f36-6091ba079496","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeForces\\Educational Codeforces Round 107 (Rated for Div. 2)\\D_Min_Cost_String.cpp"}
58.9 KB
Binary file not shown.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
2+
//------------------------------------------------------------------------------
3+
#include <iostream>
4+
#include <vector>
5+
// #include <bits/stdc++.h>
6+
// #include <cmath>
7+
// #include <algorithm>
8+
// #include <unordered_map>
9+
// #include <map>
10+
// #include <set>
11+
// #include <unordered_set>
12+
//------------------------------------------------------------------------------
13+
using namespace std;
14+
//------------------------------------------------------------------------------
15+
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
16+
#define v(Type) vector<Type>
17+
#define w(T) \
18+
int T; \
19+
cin >> T; \
20+
while (T--)
21+
#define int long long int
22+
#define mod 1000000007ll
23+
#define endl "\n"
24+
//------------------------------------------------------------------------------
25+
// Any fucntion can be called using Math.function_name();
26+
//------------------------------------------------------------------------------
27+
class Math
28+
{
29+
public:
30+
//Returns gcd of two numbers
31+
int gcd(int a, int b)
32+
{
33+
return (a % b == 0) ? b : gcd(b, a % b);
34+
}
35+
36+
//Returns lcm of two numbers
37+
int lcm(int a, int b)
38+
{
39+
return a * (b / gcd(a, b));
40+
}
41+
42+
// Returns flag array isPrime
43+
// isPrime[i] = true (if i is Prime)
44+
// isPrime[i] = false (if i is not Prime)
45+
vector<bool> *seiveOfEratosthenes(const int N)
46+
{
47+
vector<bool> *isPrime = new vector<bool>(N + 1, true);
48+
(*isPrime)[0] = (*isPrime)[1] = false;
49+
for (int i = 2; i * i <= N; ++i)
50+
if ((*isPrime)[i])
51+
for (int j = i * i; j <= N; j += i)
52+
(*isPrime)[j] = false;
53+
54+
return isPrime;
55+
}
56+
57+
//Returns (x ^ n)
58+
int pow(const int &x, int n)
59+
{
60+
if (n == 0)
61+
return 1;
62+
int h = pow(x, n / 2);
63+
return (n & 1) ? h * h * x : h * h;
64+
}
65+
66+
//Returns (x ^ n) % M
67+
int pow(const int &x, int n, const int &M)
68+
{
69+
if (n == 0)
70+
return 1;
71+
int h = pow(x, n / 2) % M;
72+
return (n & 1) ? (h * h * x) % M : (h * h) % M;
73+
}
74+
75+
//Returns all Primes <= N
76+
vector<int> *primesUptoN(const int N)
77+
{
78+
vector<bool> *isPrime = seiveOfEratosthenes(N);
79+
vector<int> *Primes = new vector<int>;
80+
if (2 <= N)
81+
(*Primes).push_back(2);
82+
for (int i = 3; i <= N; i += 2)
83+
if ((*isPrime)[i])
84+
(*Primes).push_back(i);
85+
return Primes;
86+
}
87+
88+
} Math;
89+
//------------------------------------------------------------------------------
90+
void solve()
91+
{
92+
int n;
93+
cin >> n;
94+
v(int) A(n);
95+
for (int &x : A)
96+
cin >> x;
97+
int up = 0, down = 0;
98+
for (int i = 0; i < n; i++)
99+
{
100+
if (A[i] == 1 or A[i] == 3)
101+
up++;
102+
else
103+
down++;
104+
}
105+
cout << up << endl;
106+
}
107+
//------------------------------------------------------------------------------
108+
int32_t main()
109+
{
110+
FastIO;
111+
112+
w(T)
113+
solve();
114+
115+
return 0;
116+
}
117+
//------------------------------------------------------------------------------
46.6 KB
Binary file not shown.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
2+
//------------------------------------------------------------------------------
3+
#include <iostream>
4+
#include <vector>
5+
// #include <bits/stdc++.h>
6+
// #include <cmath>
7+
// #include <algorithm>
8+
// #include <unordered_map>
9+
// #include <map>
10+
// #include <set>
11+
// #include <unordered_set>
12+
//------------------------------------------------------------------------------
13+
using namespace std;
14+
//------------------------------------------------------------------------------
15+
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
16+
#define v(Type) vector<Type>
17+
#define w(T) \
18+
int T; \
19+
cin >> T; \
20+
while (T--)
21+
#define int long long int
22+
#define mod 1000000007ll
23+
#define endl "\n"
24+
//------------------------------------------------------------------------------
25+
// Any fucntion can be called using Math.function_name();
26+
//------------------------------------------------------------------------------
27+
class Math
28+
{
29+
public:
30+
//Returns gcd of two numbers
31+
int gcd(int a, int b)
32+
{
33+
return (a % b == 0) ? b : gcd(b, a % b);
34+
}
35+
36+
//Returns lcm of two numbers
37+
int lcm(int a, int b)
38+
{
39+
return a * (b / gcd(a, b));
40+
}
41+
42+
// Returns flag array isPrime
43+
// isPrime[i] = true (if i is Prime)
44+
// isPrime[i] = false (if i is not Prime)
45+
vector<bool> *seiveOfEratosthenes(const int N)
46+
{
47+
vector<bool> *isPrime = new vector<bool>(N + 1, true);
48+
(*isPrime)[0] = (*isPrime)[1] = false;
49+
for (int i = 2; i * i <= N; ++i)
50+
if ((*isPrime)[i])
51+
for (int j = i * i; j <= N; j += i)
52+
(*isPrime)[j] = false;
53+
54+
return isPrime;
55+
}
56+
57+
//Returns (x ^ n)
58+
int pow(const int &x, int n)
59+
{
60+
if (n == 0)
61+
return 1;
62+
int h = pow(x, n / 2);
63+
return (n & 1) ? h * h * x : h * h;
64+
}
65+
66+
//Returns (x ^ n) % M
67+
int pow(const int &x, int n, const int &M)
68+
{
69+
if (n == 0)
70+
return 1;
71+
int h = pow(x, n / 2) % M;
72+
return (n & 1) ? (h * h * x) % M : (h * h) % M;
73+
}
74+
75+
//Returns all Primes <= N
76+
vector<int> *primesUptoN(const int N)
77+
{
78+
vector<bool> *isPrime = seiveOfEratosthenes(N);
79+
vector<int> *Primes = new vector<int>;
80+
if (2 <= N)
81+
(*Primes).push_back(2);
82+
for (int i = 3; i <= N; i += 2)
83+
if ((*isPrime)[i])
84+
(*Primes).push_back(i);
85+
return Primes;
86+
}
87+
88+
} Math;
89+
//------------------------------------------------------------------------------
90+
pair<int, int> solve(int a, int b, int c)
91+
{
92+
pair<int, int> ans;
93+
ans.first = Math.pow(10, a - 1);
94+
ans.second = Math.pow(10, c - 1);
95+
if (b - c + 1 >= 0)
96+
ans.second *= (Math.pow(10, b - c + 1) - 1);
97+
// cout << ans.first << " " << ans.second << endl;
98+
return ans;
99+
}
100+
void solve()
101+
{
102+
int a, b, c;
103+
cin >> a >> b >> c;
104+
pair<int, int> ans;
105+
if (a >= b)
106+
107+
ans = solve(a, b, c);
108+
else
109+
{
110+
ans = solve(b, a, c);
111+
swap(ans.first, ans.second);
112+
}
113+
cout << ans.first << " " << ans.second << endl;
114+
}
115+
//------------------------------------------------------------------------------
116+
int32_t main()
117+
{
118+
FastIO;
119+
120+
w(T)
121+
solve();
122+
123+
return 0;
124+
}
125+
//------------------------------------------------------------------------------
61.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)