Skip to content

Commit 748de0d

Browse files
committed
Competetive Programming and Contest course homeworks
1 parent 6b2ff12 commit 748de0d

34 files changed

+2168
-0
lines changed

Codeforces/1058A.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <bits/stdc++.h> // all c++ libraries
2+
3+
#define faster_io ios_base::sync_with_stdio(false);cin.tie()
4+
#define MX 400005
5+
6+
using namespace std;
7+
8+
int N, x;
9+
string answer = "EASY";
10+
11+
inline void read()
12+
{
13+
14+
cin >> N;
15+
for( int i = 0; i < N; i++ ) {
16+
17+
cin >> x;
18+
if(x)
19+
answer = "HARD";
20+
21+
}
22+
23+
}
24+
25+
26+
inline void solve()
27+
{
28+
29+
cout << answer;
30+
31+
}
32+
33+
34+
35+
int main()
36+
{
37+
38+
faster_io;
39+
40+
read();
41+
solve();
42+
43+
return 0;
44+
}

Codeforces/1058B.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <bits/stdc++.h> // all c++ libraries
2+
3+
#define faster_io ios_base::sync_with_stdio(false);cin.tie()
4+
#define MX 400005
5+
6+
using namespace std;
7+
8+
int N, D, M;
9+
struct {
10+
int x, y;
11+
} CORD[105];
12+
13+
inline void read()
14+
{
15+
16+
cin >> N >> D >> M;
17+
18+
for( int i = 1; i <= M; i++ ) {
19+
20+
cin >> CORD[i].x >> CORD[i].y;
21+
22+
}
23+
24+
}
25+
26+
27+
inline void solve()
28+
{
29+
30+
int area = 2 * D * (N - D);
31+
// cerr << "Area of the full area : " << area;
32+
33+
for ( int i = 1; i <= M; i++ ) {
34+
35+
int x = CORD[i].x;
36+
int y = CORD[i].y;
37+
38+
int newArea =
39+
abs(x * D - y * 0 + 0 * 0 - D * D + D * y - 0 * x) +
40+
abs(x * 0 - y * D + D * (N-D) - N * 0 + N * y - (N-D) * x) +
41+
abs(x * (N-D) - N * y + N * N - (N-D) * (N-D) + (N-D) * y - x * N) +
42+
abs(x * N - y * (N-D) + (N-D) * D - N * 0 + 0 * y - D * x);
43+
44+
newArea /= 2;
45+
46+
if( area == newArea ) {
47+
cout << "YES";
48+
} else {
49+
cout << "NO";
50+
}
51+
cout << "\n";
52+
53+
// cerr << "\n\t For grasshopper " << i << " : " << newArea;
54+
55+
}
56+
57+
}
58+
59+
60+
61+
int main()
62+
{
63+
64+
faster_io;
65+
66+
read();
67+
solve();
68+
69+
return 0;
70+
}

Codeforces/1058C.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#include <bits/stdc++.h> // all c++ libraries
2+
3+
// defines
4+
#define faster_io ios_base::sync_with_stdio(false);cin.tie()
5+
#define range(i,a,b) for(int i=a;i<=b;i++)
6+
#define rrange(i,a,b) for(int i=a;i>=b;i--)
7+
#define MX 400005
8+
9+
10+
using namespace std;
11+
12+
int N;
13+
string ticket_number;
14+
int sumArr[105][105];
15+
int answer = 0;
16+
17+
inline void read()
18+
{
19+
20+
cin >> N >> ticket_number;
21+
22+
}
23+
24+
25+
void dfs(int index, int value)
26+
{
27+
28+
cerr << index << " --- " << value << "\n\n";
29+
30+
if(sumArr[index][index] == value) {
31+
if(index == N-1)
32+
answer = 1;
33+
dfs(index + 1, value);
34+
}
35+
36+
range(i, index+1, N-1) {
37+
38+
cerr << "value : " << sumArr[index][i] << "\n";
39+
if(sumArr[index][i] == value) {
40+
if(i == N-1) {
41+
answer = 1;
42+
return;
43+
} else {
44+
dfs(i+1, value);
45+
}
46+
}
47+
48+
}
49+
return;
50+
51+
}
52+
53+
54+
inline void solve()
55+
{
56+
57+
range(i, 0, N-1) {
58+
59+
sumArr[i][i] = (int)ticket_number[i] - 48;
60+
range(j, i+1, N-1) {
61+
62+
sumArr[i][j] = sumArr[i][j - 1] + (int)ticket_number[j] - 48;
63+
64+
}
65+
66+
}
67+
68+
if(N == 2) {
69+
if(ticket_number[0] == ticket_number[1])
70+
cout << "YES";
71+
else
72+
cout << "NO";
73+
return;
74+
}
75+
76+
range(i, 1, N-2) {
77+
dfs(i, sumArr[0][i-1]);
78+
if(answer) {
79+
cout << "YES";
80+
return;
81+
}
82+
}
83+
cout << "NO";
84+
85+
}
86+
87+
88+
89+
int main()
90+
{
91+
92+
faster_io;
93+
94+
read();
95+
solve();
96+
97+
return 0;
98+
}

Codeforces/1058D.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <bits/stdc++.h> // all c++ libraries
2+
3+
// defines
4+
#define faster_io ios_base::sync_with_stdio(false);cin.tie()
5+
#define range(i,a,b) for(int i=a;i<=b;i++)
6+
#define rrange(i,a,b) for(int i=a;i>=b;i--)
7+
#define MX 400005
8+
9+
10+
using namespace std;
11+
12+
int N, M, K;
13+
14+
inline void read()
15+
{
16+
17+
cin >> N >> M >> K;
18+
19+
}
20+
21+
22+
inline void solve()
23+
{
24+
25+
if( (N * M * 2) % K ) {
26+
cout << "NO";
27+
return;
28+
}
29+
int area = N * M / K;
30+
int double_area = 2 * area;
31+
int sqrt_double_area = int(sqrt(double_area));
32+
33+
if(sqrt_double_area < 2) {
34+
cout << "NO";
35+
return;
36+
}
37+
38+
int height = 0, width = 0;
39+
range(i, 2, sqrt_double_area) {
40+
if(double_area%i == 0) {
41+
height = i;
42+
width = double_area / i;
43+
break;
44+
}
45+
}
46+
47+
if(height == 0 || width == 0) {
48+
cout << "NO";
49+
return;
50+
}
51+
52+
cout << "YES\n0 0\n";
53+
cout << "0 " << width << "\n";
54+
cout << height << " 0\n";
55+
56+
}
57+
58+
59+
60+
int main()
61+
{
62+
63+
faster_io;
64+
65+
read();
66+
solve();
67+
68+
return 0;
69+
}

Codeforces/141C.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <bits/stdc++.h> // all c++ libraries
2+
3+
// defines
4+
#define faster_io ios_base::sync_with_stdio(false);cin.tie()
5+
#define range(i,a,b) for(int i=a;i<=b;i++)
6+
#define rrange(i,a,b) for(int i=a;i>=b;i--)
7+
#define rangev(i,a) for(int i=0;i<a.size();i++)
8+
#define rrangev(i,a) for(int i=a.size()-1;i>=0;i--)
9+
#define clr(a) memset(a, 0, sizeof(a))
10+
#define all(a) a.begin(), a.end()
11+
#define mp make_pair
12+
#define pb push_back
13+
#define st first
14+
#define nd second
15+
#define MX 100005
16+
17+
18+
using namespace std;
19+
20+
typedef long long ll;
21+
typedef vector <int> vi;
22+
typedef pair <int, int> pii;
23+
typedef vector <pii> vii;
24+
typedef pair <int, pii> pip;
25+
26+
const ll INF = 1e9 + 100;
27+
const ll MOD = 1e9 + 7;
28+
29+
30+
int N;
31+
struct People {
32+
string name;
33+
int pos, height, new_height;
34+
People(string _n, int _p, int _h) {
35+
name = _n, pos = _p, height = _h;
36+
}
37+
};
38+
39+
bool comp(People A, People B) {
40+
return A.height < B.height;
41+
}
42+
43+
int main() {
44+
45+
faster_io;
46+
47+
cin >> N;
48+
vector <People> arr;
49+
range(i, 1, N) {
50+
string n;
51+
int h;
52+
cin >> n >> h;
53+
arr.pb( People(n, i, h) );
54+
}
55+
sort(all(arr), comp);
56+
57+
vi por;
58+
rangev(i, arr) {
59+
if(arr[i].height > i) {
60+
cout << "-1";
61+
return 0;
62+
}
63+
por.pb(i);
64+
int x = por.size() - 1;
65+
while(x > por.size() - 1 - arr[i].height) {
66+
swap(por[x], por[x - 1]);
67+
x--;
68+
}
69+
}
70+
71+
rangev(i, por) {
72+
arr[por[i]].new_height = i + 1;
73+
}
74+
75+
rangev(i, arr) {
76+
cout << arr[i].name << " " << arr[i].new_height << "\n";
77+
}
78+
79+
return 0;
80+
}

0 commit comments

Comments
 (0)