Skip to content

Commit ad30f4d

Browse files
Add files via upload
1 parent bd66953 commit ad30f4d

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <map>
4+
5+
using namespace std;
6+
7+
void solve()
8+
{
9+
int length;
10+
string S;
11+
cin >> length >> S;
12+
13+
int minimum_moves = 0, remaining = length;
14+
for(int i = 0; i + 1 < length; i++)
15+
{
16+
if(S[i] == '(')
17+
{
18+
minimum_moves++;
19+
remaining -= 2;
20+
i++;
21+
}
22+
else if(S[i] == ')')
23+
{
24+
int j = i + 1;
25+
while(j < length && S[j] != ')')
26+
{
27+
j++;
28+
}
29+
30+
if(j == length)
31+
{
32+
break;
33+
}
34+
35+
minimum_moves++;
36+
remaining -= (j - i + 1); //cout << "i = " << i << " j = " << j << "\n";
37+
i = j;
38+
}
39+
}
40+
41+
cout << minimum_moves << " " << remaining << "\n";
42+
}
43+
44+
int main()
45+
{
46+
int no_of_test_cases;
47+
cin >> no_of_test_cases;
48+
49+
while(no_of_test_cases--)
50+
solve();
51+
52+
return 0;
53+
}
54+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int is_square(int n)
6+
{
7+
for(int i = 1; i*i <= n; i++)
8+
{
9+
if(i*i == n)
10+
{
11+
return true;
12+
}
13+
}
14+
15+
return false;
16+
}
17+
18+
void solve()
19+
{
20+
int x, y;
21+
cin >> x >> y;
22+
23+
int answer = 0;
24+
if(x == 0 && y == 0)
25+
{
26+
answer = 0;
27+
}
28+
else if(is_square(x*x + y*y))
29+
{
30+
answer = 1;
31+
}
32+
else
33+
{
34+
answer = 2;
35+
}
36+
37+
cout << answer << "\n";
38+
}
39+
40+
int main()
41+
{
42+
int no_of_test_cases;
43+
cin >> no_of_test_cases;
44+
45+
while(no_of_test_cases--)
46+
solve();
47+
48+
return 0;
49+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
void solve()
7+
{
8+
int no_of_elements, x, y, max_limit;
9+
cin >> no_of_elements >> max_limit >> x >> y;
10+
11+
long long sum = 0;
12+
vector <long long> A(no_of_elements + 1);
13+
for(int i = 1; i <= no_of_elements; i++)
14+
{
15+
if(A[i - 1] + x <= max_limit)
16+
{
17+
A[i] = A[i - 1] + x;
18+
}
19+
else
20+
{
21+
A[i] = A[i - 1] - y;
22+
}
23+
24+
sum += A[i];
25+
}
26+
27+
cout << sum << "\n";
28+
}
29+
30+
int main()
31+
{
32+
int no_of_test_cases;
33+
cin >> no_of_test_cases;
34+
35+
while(no_of_test_cases--)
36+
solve();
37+
38+
return 0;
39+
}

0 commit comments

Comments
 (0)