Skip to content

Commit 69f6957

Browse files
committed
cf723
1 parent 4a0c143 commit 69f6957

File tree

9 files changed

+615
-4
lines changed

9 files changed

+615
-4
lines changed

CF1.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ int fact(int n)
5858
}
5959
return res % MOD;
6060
}
61-
6261
bool isPrime(int n)
6362
{
6463
if (n <= 1)

CF2.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ int fact(int n)
5858
}
5959
return res % MOD;
6060
}
61-
6261
bool isPrime(int n)
6362
{
6463
if (n <= 1)

Contests Solutions/CF731/CF1.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
#############################################
3+
Author: Siddharth Mishra
4+
GitHub: https://github.com/Hard-Coder05
5+
#############################################
6+
*/
7+
#include <bits/stdc++.h>
8+
using namespace std;
9+
#define endl "\n"
10+
#define MOD 1000000007
11+
#define INF INT_MAX
12+
#define ll long long
13+
#define int long long
14+
#define vi vector<int>
15+
#define pii pair<int, int>
16+
#define ld long double
17+
#define PB push_back
18+
#define MP make_pair
19+
#define FF first
20+
#define SS second
21+
#define max(a, b) ( \
22+
{ \
23+
__typeof__(a) _a = (a); \
24+
__typeof__(b) _b = (b); \
25+
_a > _b ? _a : _b; \
26+
})
27+
#define min(a, b) ( \
28+
{ \
29+
__typeof__(a) _a = (a); \
30+
__typeof__(b) _b = (b); \
31+
_a < _b ? _a : _b; \
32+
})
33+
//////////////////////////////////////////////////////////////////////////////
34+
int power(int a, int b)
35+
{
36+
int res = 1ll;
37+
while (b > 0)
38+
{
39+
if (b % 2ll)
40+
res = (res * a) % MOD;
41+
a = (a * a) % MOD;
42+
b /= 2ll;
43+
}
44+
return res;
45+
}
46+
int GCD(int a, int b)
47+
{
48+
if (b == 0)
49+
return a;
50+
return GCD(b, a % b);
51+
}
52+
int fact(int n)
53+
{
54+
int res = 1;
55+
for (int i = 2; i <= n; i++)
56+
{
57+
res = (res * i) % MOD;
58+
}
59+
return res % MOD;
60+
}
61+
bool isPrime(int n)
62+
{
63+
if (n <= 1)
64+
return false;
65+
if (n <= 3)
66+
return true;
67+
if (n % 2 == 0 || n % 3 == 0)
68+
return false;
69+
for (int i = 5; i * i <= n; i = i + 6)
70+
if (n % i == 0 || n % (i + 2) == 0)
71+
return false;
72+
return true;
73+
}
74+
//////////////////////////////////////////////////////////////////////////////
75+
76+
void solve()
77+
{
78+
int a1, b1, a2, b2, a3, b3;
79+
cin >> a1 >> b1;
80+
cin >> a3 >> b3;
81+
if (a1 > a3)
82+
swap(a1, a3);
83+
if (b1 > b3)
84+
swap(b1, b3);
85+
cin >> a2 >> b2;
86+
int ans = abs(a3 - a1) + abs(b3 - b1);
87+
if ((a1 == a2 && a2 == a3 && b2 > b1 && b2 < b3) || (b1 == b2 && b2 == b3 && a2 > a1 && a2 < a3))
88+
ans += 2;
89+
cout << ans << endl;
90+
}
91+
signed main()
92+
{
93+
ios_base::sync_with_stdio(false);
94+
cin.tie(NULL);
95+
cout.tie(NULL);
96+
#ifndef ONLINE_JUDGE
97+
freopen("input.txt", "r", stdin);
98+
freopen("output.txt", "w", stdout);
99+
#endif
100+
int tc;
101+
cin >> tc;
102+
while (tc--)
103+
{
104+
solve();
105+
}
106+
}

Contests Solutions/CF731/CF2.cpp

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
#############################################
3+
Author: Siddharth Mishra
4+
GitHub: https://github.com/Hard-Coder05
5+
#############################################
6+
*/
7+
#include <bits/stdc++.h>
8+
using namespace std;
9+
#define endl "\n"
10+
#define MOD 1000000007
11+
#define INF INT_MAX
12+
#define ll long long
13+
#define int long long
14+
#define vi vector<int>
15+
#define pii pair<int, int>
16+
#define ld long double
17+
#define PB push_back
18+
#define MP make_pair
19+
#define FF first
20+
#define SS second
21+
#define max(a, b) ( \
22+
{ \
23+
__typeof__(a) _a = (a); \
24+
__typeof__(b) _b = (b); \
25+
_a > _b ? _a : _b; \
26+
})
27+
#define min(a, b) ( \
28+
{ \
29+
__typeof__(a) _a = (a); \
30+
__typeof__(b) _b = (b); \
31+
_a < _b ? _a : _b; \
32+
})
33+
//////////////////////////////////////////////////////////////////////////////
34+
int power(int a, int b)
35+
{
36+
int res = 1ll;
37+
while (b > 0)
38+
{
39+
if (b % 2ll)
40+
res = (res * a) % MOD;
41+
a = (a * a) % MOD;
42+
b /= 2ll;
43+
}
44+
return res;
45+
}
46+
int GCD(int a, int b)
47+
{
48+
if (b == 0)
49+
return a;
50+
return GCD(b, a % b);
51+
}
52+
int fact(int n)
53+
{
54+
int res = 1;
55+
for (int i = 2; i <= n; i++)
56+
{
57+
res = (res * i) % MOD;
58+
}
59+
return res % MOD;
60+
}
61+
bool isPrime(int n)
62+
{
63+
if (n <= 1)
64+
return false;
65+
if (n <= 3)
66+
return true;
67+
if (n % 2 == 0 || n % 3 == 0)
68+
return false;
69+
for (int i = 5; i * i <= n; i = i + 6)
70+
if (n % i == 0 || n % (i + 2) == 0)
71+
return false;
72+
return true;
73+
}
74+
//////////////////////////////////////////////////////////////////////////////
75+
76+
void solve()
77+
{
78+
string s;
79+
cin >> s;
80+
string a = s;
81+
sort(a.begin(), a.end());
82+
int n = s.length();
83+
if (a[0] != 'a')
84+
{
85+
cout << "NO" << endl;
86+
return;
87+
}
88+
bool answerCan = true;
89+
for (int i = 0; i < n - 1; i++)
90+
if (a[i + 1] - a[i] != 1)
91+
{
92+
answerCan = false;
93+
break;
94+
}
95+
if (!answerCan)
96+
{
97+
cout << "NO" << endl;
98+
return;
99+
}
100+
int i = 0;
101+
for (; i < n; i++)
102+
if (s[i] == 'a')
103+
break;
104+
for (int j = i - 1; j >= 0; j--)
105+
if (s[j] - s[j + 1] < 0)
106+
{
107+
answerCan = false;
108+
break;
109+
}
110+
if (!answerCan)
111+
{
112+
cout << "NO" << endl;
113+
return;
114+
}
115+
for (int j = i + 1; j < n - 1; j++)
116+
if (s[j + 1] - s[j] < 0)
117+
{
118+
answerCan = false;
119+
break;
120+
}
121+
if (!answerCan)
122+
{
123+
cout << "NO" << endl;
124+
return;
125+
}
126+
cout << "YES" << endl;
127+
}
128+
signed main()
129+
{
130+
ios_base::sync_with_stdio(false);
131+
cin.tie(NULL);
132+
cout.tie(NULL);
133+
#ifndef ONLINE_JUDGE
134+
freopen("input.txt", "r", stdin);
135+
freopen("output.txt", "w", stdout);
136+
#endif
137+
int tc;
138+
cin >> tc;
139+
while (tc--)
140+
{
141+
solve();
142+
}
143+
}

0 commit comments

Comments
 (0)