Skip to content

Commit c7db186

Browse files
committedJul 30, 2017
Add recent codeforces.com
1 parent 13ef34f commit c7db186

18 files changed

+915
-0
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
* [russiancodecup.ru](https://russiancodecup.ru)
1212
* [spoj.com](http://www.spoj.com/users/kronos_vano/)
1313
* [contest.yandex.ru](https://contest.yandex.ru)
14+
* [codechef.com](https://www.codechef.com/users/kronos_vano)

‎codeforces/8xx/814A.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <iostream>
2+
#include <set>
3+
#include <vector>
4+
#include <map>
5+
#include <algorithm>
6+
#include <math.h>
7+
8+
using namespace std;
9+
10+
int n, k;
11+
int a[100];
12+
int b[100];
13+
vector<int> z;
14+
int main() {
15+
cin.tie(0);
16+
ios_base::sync_with_stdio(false);
17+
cin >> n >> k;
18+
for (int i = 0; i < n; i++) {
19+
cin >> a[i];
20+
if (a[i] == 0) {
21+
z.push_back(i);
22+
}
23+
}
24+
25+
for (int i = 0; i < k; i++) {
26+
cin >> b[i];
27+
}
28+
29+
sort(b, b+k);
30+
int mmin = b[0];
31+
int mmax = b[k-1];
32+
bool can = false;
33+
bool cons = false;
34+
35+
for (int i = 1; (i < z.size()) && !cons; i++) {
36+
cons = z[i] - z[i-1];
37+
}
38+
39+
can = cons && mmin != mmax;
40+
41+
for (int i = 1; (i < n) && !can; i++) {
42+
can = a[i] != 0 && a[i-1] != 0 && a[i] < a[i-1];
43+
}
44+
45+
for (int i = 0; (i < z.size()) && !can; i++) {
46+
int idx = z[i];
47+
if (idx > 0) {
48+
can = (a[idx-1] > mmin) || (idx + 1 < n && a[idx+1] > 0 && a[idx+1] < mmax);
49+
} else {
50+
can = a[1] != 0 && mmax > a[1];
51+
}
52+
}
53+
54+
if (can) {
55+
cout << "Yes";
56+
} else {
57+
cout << "No";
58+
}
59+
return 0;
60+
}

‎codeforces/8xx/814B.cpp

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include <iostream>
2+
#include <set>
3+
#include <vector>
4+
#include <map>
5+
#include <algorithm>
6+
#include <math.h>
7+
8+
using namespace std;
9+
10+
int n, m;
11+
int a[1000];
12+
int b[1000];
13+
int c[1000];
14+
bool used[1001];
15+
int main() {
16+
cin.tie(0);
17+
ios_base::sync_with_stdio(false);
18+
cin >> n;
19+
for (int i = 0; i < n; i++) {
20+
cin >> a[i];
21+
}
22+
23+
for (int i = 0; i < n; i++) {
24+
cin >> b[i];
25+
}
26+
27+
bool first = false;
28+
int first_idx;
29+
int second_idx = -1;
30+
31+
for (int i = 0; i < n; i++) {
32+
if (a[i] == b[i]) {
33+
c[i] = a[i];
34+
used[c[i]] = true;
35+
} else {
36+
if (first) {
37+
second_idx = i;
38+
} else {
39+
first = true;
40+
first_idx = i;
41+
}
42+
}
43+
}
44+
45+
if (second_idx > 0) {
46+
vector<int> nums;
47+
if (!used[a[first_idx]]) {
48+
nums.push_back(a[first_idx]);
49+
used[a[first_idx]] = true;
50+
}
51+
52+
if (!used[b[first_idx]]) {
53+
nums.push_back(b[first_idx]);
54+
used[b[first_idx]] = true;
55+
}
56+
57+
if (!used[a[second_idx]]) {
58+
nums.push_back(a[second_idx]);
59+
used[a[second_idx]] = true;
60+
}
61+
62+
if (!used[b[second_idx]]) {
63+
nums.push_back(b[second_idx]);
64+
}
65+
66+
if (((a[first_idx] == nums[0] && a[second_idx] != nums[1]) ||
67+
(a[first_idx] != nums[0] && a[second_idx] == nums[1])) &&
68+
((b[first_idx] == nums[0] && b[second_idx] != nums[1]) ||
69+
(b[first_idx] != nums[0] && b[second_idx] == nums[1]))) {
70+
c[first_idx] = nums[0];
71+
c[second_idx] = nums[1];
72+
} else {
73+
c[first_idx] = nums[1];
74+
c[second_idx] = nums[0];
75+
}
76+
} else {
77+
for (int i = 1; i <= n; i++) {
78+
if (!used[i]) {
79+
c[first_idx] = i;
80+
break;
81+
}
82+
}
83+
}
84+
85+
for (int i = 0; i < n; i++) {
86+
cout << c[i] << " ";
87+
}
88+
89+
return 0;
90+
}

‎codeforces/8xx/814C.cpp

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <iostream>
2+
#include <set>
3+
#include <vector>
4+
#include <map>
5+
#include <algorithm>
6+
#include <math.h>
7+
8+
using namespace std;
9+
10+
int len, q;
11+
string s;
12+
int occ[27];
13+
int ans[27][1501];
14+
15+
int main() {
16+
cin.tie(0);
17+
ios_base::sync_with_stdio(false);
18+
cin >> len >> s >> q;
19+
int m, replace_count;
20+
char c, ccc;
21+
22+
for (int i = 0; i < s.length(); i++) {
23+
occ[s[i]-'a']++;
24+
}
25+
26+
for (int i = 0; i < 27; i++) {
27+
ccc = 'a' + i;
28+
if (occ[i] > 0) {
29+
for (int j = 0; j < len; j++) {
30+
replace_count = 0;
31+
for (int k = j; k < len; k++) {
32+
if (s[k] != ccc) {
33+
replace_count++;
34+
}
35+
ans[i][replace_count] = max(ans[i][replace_count], k-j+1);
36+
}
37+
}
38+
39+
for (int j = 1; j < len; j++) {
40+
ans[i][j] = max(ans[i][j], ans[i][j-1]);
41+
}
42+
}
43+
}
44+
45+
while (q--) {
46+
cin >> m >> c;
47+
if (occ[c-'a']) {
48+
if (m >= len - occ[c-'a']) {
49+
cout << len << "\n";
50+
} else {
51+
cout << ans[c-'a'][m] << "\n";
52+
}
53+
} else {
54+
cout << m << "\n";
55+
}
56+
}
57+
return 0;
58+
}

‎codeforces/8xx/819A.cpp

+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
#include <iostream>
2+
#include <set>
3+
#include <vector>
4+
#include <map>
5+
#include <algorithm>
6+
#include <math.h>
7+
8+
using namespace std;
9+
10+
int a, b, l, r;
11+
12+
size_t simulate_a(int l, int r) {
13+
bool taken[30];
14+
string s = "";
15+
char c;
16+
for (int i = 0; i < 30; i++) {
17+
taken[i] = false;
18+
}
19+
20+
// initial string
21+
for (int i = 0; i < a; i++) {
22+
taken[i] = true;
23+
c = 'a' + i;
24+
s += c;
25+
}
26+
27+
// B move
28+
for (int i = 0; i < b; i++) {
29+
taken[i] = false;
30+
taken[c - 'a'] = true;
31+
s += c;
32+
}
33+
34+
35+
size_t count = 0;
36+
37+
// first comp move
38+
for (int i = 0; count < a;i++) {
39+
if (!taken[i]) {
40+
c = 'a' + i;
41+
s += c;
42+
count++;
43+
}
44+
}
45+
46+
// B move
47+
for (int i = 0; i < b; i++) {
48+
s += c;
49+
}
50+
51+
for (int i = 0; i < 30; i++) {
52+
taken[i] = false;
53+
}
54+
int mmax = 0;
55+
for (int i = 0; i < s.length(); i++) {
56+
if (!taken[s[i]-'a']) {
57+
taken[s[i]-'a'] = true;
58+
mmax++;
59+
}
60+
}
61+
for (int i = 0; i < 30; i++) {
62+
taken[i] = false;
63+
}
64+
65+
int len = s.length();
66+
int k_l = l/len;
67+
r -= k_l*len;
68+
l -= k_l*len;
69+
if (l == 0) {
70+
r += len;
71+
l += len;
72+
}
73+
74+
count = 0;
75+
l--; r--;
76+
s += s;
77+
s += s;
78+
79+
for (int i = l; (i <= r) && (count < mmax); i++) {
80+
if (!taken[s[i]-'a']) {
81+
taken[s[i]-'a'] = true;
82+
count++;
83+
}
84+
}
85+
86+
return count;
87+
}
88+
89+
size_t simulate_b(int l, int r) {
90+
bool taken[30];
91+
string s = "";
92+
char c;
93+
for (int i = 0; i < 30; i++) {
94+
taken[i] = false;
95+
}
96+
97+
// initial string
98+
for (int i = 0; i < a; i++) {
99+
taken[i] = true;
100+
s += 'a' + i;
101+
}
102+
103+
// B move
104+
for (int i = 0; i < b; i++) {
105+
taken[i] = false;
106+
if (b >= a) {
107+
taken[s[a-1] - 'a'] = true;
108+
s += s[a-1];
109+
} else {
110+
taken[s[a-b-1] - 'a'] = true;
111+
s += s[a-b-1];
112+
}
113+
}
114+
115+
size_t count = 0;
116+
117+
// first comp move
118+
for (int i = 0; count < a;i++) {
119+
if (!taken[i]) {
120+
c = 'a' + i;
121+
s += c;
122+
count++;
123+
}
124+
}
125+
126+
// B move
127+
for (int i = 0; i < b; i++) {
128+
s += c;
129+
}
130+
131+
for (int i = 0; i < 30; i++) {
132+
taken[i] = false;
133+
}
134+
int mmax = 0;
135+
for (int i = 0; i < s.length(); i++) {
136+
if (!taken[s[i]-'a']) {
137+
taken[s[i]-'a'] = true;
138+
mmax++;
139+
}
140+
}
141+
for (int i = 0; i < 30; i++) {
142+
taken[i] = false;
143+
}
144+
145+
int len = s.length();
146+
int k_l = l/len;
147+
r -= k_l*len;
148+
l -= k_l*len;
149+
if (l == 0) {
150+
r += len;
151+
l += len;
152+
}
153+
154+
count = 0;
155+
l--; r--;
156+
s += s;
157+
s += s;
158+
159+
for (int i = l; (i <= r) && (count < mmax); i++) {
160+
if (!taken[s[i]-'a']) {
161+
taken[s[i]-'a'] = true;
162+
count++;
163+
}
164+
}
165+
return count;
166+
}
167+
168+
int main() {
169+
cin.tie(0);
170+
ios_base::sync_with_stdio(false);
171+
cin >> a >> b >> l >> r;
172+
173+
cout << min(simulate_a(l, r), simulate_b(l, r));
174+
return 0;
175+
}

‎codeforces/8xx/820A.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <iostream>
2+
#include <set>
3+
#include <vector>
4+
#include <map>
5+
#include <algorithm>
6+
#include <math.h>
7+
8+
using namespace std;
9+
10+
unsigned long long c, v0, v1, a, l;
11+
12+
int main() {
13+
cin.tie(0);
14+
ios_base::sync_with_stdio(false);
15+
cin >> c >> v0 >> v1 >> a >> l;
16+
unsigned long long ans = 0, days = 0, speed = 0, read = 0;
17+
18+
while (true) {
19+
days++;
20+
speed = min(v0 + a*(days-1), v1);
21+
read += speed;
22+
if (read >= c) {
23+
break;
24+
}
25+
read -= l;
26+
}
27+
cout << days;
28+
return 0;
29+
}

‎codeforces/8xx/820B.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <iostream>
2+
#include <set>
3+
#include <vector>
4+
#include <map>
5+
#include <algorithm>
6+
#include <cmath>
7+
8+
using namespace std;
9+
10+
int n;
11+
double a;
12+
13+
int main() {
14+
cin.tie(0);
15+
ios_base::sync_with_stdio(false);
16+
cin >> n >> a;
17+
double one_angle = 180.0/n;
18+
double best = 180.0;
19+
double current = 0;
20+
int best_x = 3;
21+
for (int i = 3; i <= n; i++) {
22+
current += one_angle;
23+
if (abs(a - current) < best) {
24+
best = abs(a - current);
25+
best_x = i;
26+
}
27+
}
28+
cout << "2 1 " << best_x << endl;
29+
return 0;
30+
}

‎codeforces/8xx/821A.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
#include <set>
5+
#include <map>
6+
7+
using namespace std;
8+
int n;
9+
unsigned long long ans;
10+
int a[50][50];
11+
12+
int main() {
13+
cin.tie(0);
14+
ios_base::sync_with_stdio(false);
15+
16+
cin >> n;
17+
for (int i = 0; i < n; i++) {
18+
for (int j = 0; j < n; j++) {
19+
cin >> a[i][j];
20+
}
21+
}
22+
bool rgood = true;
23+
for (int i = 0; (i < n) && rgood; i++) {
24+
for (int j = 0; (j < n) && rgood ; j++) {
25+
if (a[i][j] != 1) {
26+
bool good = false;
27+
for (int ii = 0; (ii < n) && !good; ii++) {
28+
for (int jj = 0; (jj < n) && !good; jj++) {
29+
good = a[ii][j] + a[i][jj] == a[i][j];
30+
}
31+
}
32+
33+
if (!good) {
34+
rgood = false;
35+
}
36+
}
37+
}
38+
}
39+
if (rgood) {
40+
cout << "Yes";
41+
} else {
42+
cout << "No";
43+
}
44+
45+
return 0;
46+
}

‎codeforces/8xx/821B.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
#include <set>
5+
#include <map>
6+
7+
using namespace std;
8+
int n;
9+
unsigned long long b,m,ans;
10+
11+
unsigned long long cnt(unsigned long long x, unsigned long long y) {
12+
unsigned long long a;
13+
a = (1+x)*x/2;
14+
return (y+1)*a + (x+1 + (x+1)*y)*y/2;
15+
}
16+
17+
int main() {
18+
cin.tie(0);
19+
ios_base::sync_with_stdio(false);
20+
unsigned long long x,y,z;
21+
cin >> m >> b;
22+
23+
for (unsigned long long y = 0; y <= b; y++) {
24+
x = (b-y)*m;
25+
z = cnt(x,y);
26+
27+
if (z > ans) {
28+
ans = z;
29+
}
30+
}
31+
cout << ans;
32+
return 0;
33+
}

‎codeforces/8xx/821C.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
#include <set>
5+
#include <map>
6+
7+
using namespace std;
8+
int n, q;
9+
unsigned long long ans;
10+
int stack[300000];
11+
int top;
12+
13+
int main() {
14+
cin.tie(0);
15+
ios_base::sync_with_stdio(false);
16+
string cmd;
17+
cin >> n;
18+
int current = 1;
19+
int last_sorted = 0;
20+
int size = 0;
21+
int ordered_top = -1;
22+
for (int i = 0; i < n*2; i++) {
23+
cin >> cmd;
24+
if (cmd[0] == 'a') {
25+
cin >> stack[top];
26+
top++;
27+
} else {
28+
if (stack[top-1] == current || ordered_top == top-1) {
29+
top--;
30+
if (ordered_top >= top) {
31+
ordered_top = top-1;
32+
}
33+
} else {
34+
top--;
35+
ans++;
36+
ordered_top = top-1;
37+
}
38+
current++;
39+
}
40+
}
41+
cout << ans << "\n";
42+
return 0;
43+
}

‎codeforces/8xx/822A.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
#include <set>
3+
#include <vector>
4+
#include <map>
5+
#include <algorithm>
6+
#include <math.h>
7+
8+
using namespace std;
9+
10+
long long a, b;
11+
int main() {
12+
cin >> a >> b;
13+
long long q = min(a,b);
14+
long long ans = 1;
15+
for (int i = 2; i <= q; i++) {
16+
ans *= i;
17+
}
18+
cout << ans;
19+
return 0;
20+
}

‎codeforces/8xx/822B.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <iostream>
2+
#include <set>
3+
#include <vector>
4+
#include <map>
5+
#include <algorithm>
6+
#include <math.h>
7+
8+
using namespace std;
9+
10+
int n, m;
11+
string s, t;
12+
int cnt[1000];
13+
int main() {
14+
cin >> n >> m;
15+
cin >> s >> t;
16+
for (int i = 0; i <= m-n; i++) {
17+
for (int j = 0; j < n; j++) {
18+
if (s[j] != t[i + j]) {
19+
cnt[i]++;
20+
}
21+
}
22+
}
23+
int imax = 0;
24+
for (int i = 1; i <= m-n; i++) {
25+
if (cnt[i] < cnt[imax]) {
26+
imax = i;
27+
}
28+
}
29+
cout << cnt[imax] << endl;
30+
for (int i = 0; i < n; i++) {
31+
if (s[i] != t[i+imax]) {
32+
cout << i + 1 << " ";
33+
}
34+
}
35+
return 0;
36+
}

‎codeforces/8xx/822D.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <iostream>
2+
#include <set>
3+
#include <vector>
4+
#include <map>
5+
#include <algorithm>
6+
#include <math.h>
7+
8+
using namespace std;
9+
10+
const long long mod = 1000000007;
11+
long long t, l, r, ans;
12+
13+
long long d[5000001];
14+
long long f[5000001];
15+
int main() {
16+
cin.tie(0);
17+
ios_base::sync_with_stdio(false);
18+
cin >> t >> l >> r;
19+
long long q = 1;
20+
int to = sqrt(r);
21+
22+
for (int i = 2; i <= to; i++) {
23+
if (d[i] == 0) {
24+
for (int j = i*i; j <= r; j += i) {
25+
if (d[j] == 0) {
26+
d[j] = i;
27+
}
28+
}
29+
}
30+
}
31+
32+
for (long long i = 2; i <= r; i++) {
33+
if (d[i]) {
34+
f[i] = (i/d[i] * f[d[i]] + f[i/d[i]]) % mod;
35+
} else {
36+
f[i] = i*(i-1)/2 % mod;
37+
}
38+
}
39+
40+
for (long long i = l; i <= r; i++) {
41+
ans = (ans + q*f[i]) % mod;
42+
q = q*t % mod;
43+
}
44+
cout << ans;
45+
return 0;
46+
}

‎codeforces/8xx/832A.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
#include <set>
3+
#include <vector>
4+
#include <map>
5+
#include <algorithm>
6+
#include <math.h>
7+
8+
using namespace std;
9+
10+
long long n,k;
11+
int main() {
12+
cin.tie(0);
13+
ios_base::sync_with_stdio(false);
14+
cin >> n >> k;
15+
long long q = n / k;
16+
if (q % 2 == 1) {
17+
cout << "YES";
18+
} else {
19+
cout << "NO";
20+
}
21+
return 0;
22+
}

‎codeforces/8xx/832B.cpp

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#include <iostream>
2+
#include <set>
3+
#include <vector>
4+
#include <map>
5+
#include <algorithm>
6+
#include <math.h>
7+
8+
using namespace std;
9+
10+
string g,s,t;
11+
bool good[27];
12+
13+
bool check(const string& s) {
14+
if (s.length() < t.length() - 1) {
15+
return false;
16+
}
17+
18+
int from = -1;
19+
int len = min(t.length(), s.length());
20+
for (int i = 0; i < len; i++) {
21+
if (t[i] == '?') {
22+
if (!good[s[i]-'a']) {
23+
return false;
24+
}
25+
} else if (t[i] == '*') {
26+
from = i;
27+
break;
28+
} else {
29+
if (t[i] != s[i]) {
30+
return false;
31+
}
32+
}
33+
}
34+
35+
if (from >= 0) {
36+
int to = s.length() - 1;
37+
int ti = t.length() - 1;
38+
while (t[ti] != '*') {
39+
if (t[ti] == '?') {
40+
if (!good[s[to]-'a']) {
41+
return false;
42+
}
43+
} else if (t[ti] == '*') {
44+
break;
45+
} else {
46+
if (t[ti] != s[to]) {
47+
return false;
48+
}
49+
}
50+
ti--;
51+
to--;
52+
}
53+
for (int i = from; i <= to; i++) {
54+
if (good[s[i]-'a']) {
55+
return false;
56+
}
57+
}
58+
} else {
59+
if (t.length() == s.length()) {
60+
return true;
61+
}
62+
63+
if ((t.length() == s.length() + 1) && t[t.length()-1] == '*') {
64+
return true;
65+
} else {
66+
return false;
67+
}
68+
}
69+
70+
return true;
71+
}
72+
73+
int main() {
74+
cin.tie(0);
75+
ios_base::sync_with_stdio(false);
76+
cin >> g >> t;
77+
for (int i = 0; i < g.length(); i++) {
78+
good[g[i] - 'a'] = true;
79+
}
80+
int n;
81+
cin >> n;
82+
while (n--) {
83+
cin >> s;
84+
if (check(s)) {
85+
cout << "YES\n";
86+
} else {
87+
cout << "NO\n";
88+
}
89+
}
90+
return 0;
91+
}

‎codeforces/8xx/833A.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
#include <set>
5+
#include <map>
6+
#include <vector>
7+
8+
using namespace std;
9+
int n;
10+
long long sqrt3(long long a) {
11+
long long l = 0;
12+
long long r = 1000001;
13+
long long mid;
14+
while (r-l > 1) {
15+
mid = (r+l)/2;
16+
if (mid * mid * mid <= a) {
17+
l = mid;
18+
} else {
19+
r = mid;
20+
}
21+
}
22+
23+
return l;
24+
}
25+
26+
int main() {
27+
cin.tie(0);
28+
ios_base::sync_with_stdio(false);
29+
long long a,b,z,q;
30+
cin >> n;
31+
for (int i = 0; i < n; i++) {
32+
cin >> a >> b;
33+
q = a * b; // => x^3*y^3
34+
z = __gcd(a,b);
35+
long long c = sqrt3(q);
36+
if (c*c*c == q && (a/c)*(b/c) == c) {
37+
cout << "Yes\n";
38+
} else {
39+
cout << "No\n";
40+
}
41+
}
42+
return 0;
43+
}
44+

‎codeforces/8xx/834A.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
#include <set>
5+
#include <map>
6+
#include <vector>
7+
8+
using namespace std;
9+
int n;
10+
string s;
11+
map<char, string> cw;
12+
map<char, string> ccw;
13+
int main() {
14+
cin.tie(0);
15+
ios_base::sync_with_stdio(false);
16+
17+
cw['^'] = "^>v<^";
18+
cw['>'] = ">v<^>";
19+
cw['v'] = "v<^>v";
20+
cw['<'] = "<^>v<";
21+
22+
ccw['^'] = "^<v>^";
23+
ccw['>'] = ">^<v>";
24+
ccw['v'] = "v>^<v";
25+
ccw['<'] = "<v>^<";
26+
char c,c2;
27+
28+
cin >> c >> c2;
29+
s = c; s+= c2;
30+
cin >> n;
31+
n = n % 4;
32+
33+
if (cw[s[0]][n] == ccw[s[0]][n]) {
34+
cout << "undefined";
35+
} else if (cw[s[0]][n] == s[1]) {
36+
cout << "cw";
37+
} else if (ccw[s[0]][n] == s[1]) {
38+
cout << "ccw";
39+
} else {
40+
cout << "ERROR";
41+
}
42+
43+
return 0;
44+
}

‎codeforces/8xx/834B.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
#include <set>
5+
#include <map>
6+
#include <vector>
7+
8+
using namespace std;
9+
int n, k;
10+
string s;
11+
bool bad;
12+
int first[26];
13+
int last[26];
14+
15+
int main() {
16+
cin.tie(0);
17+
ios_base::sync_with_stdio(false);
18+
cin >> n >> k;
19+
cin >> s;
20+
int p;
21+
22+
for (int i = 0; i < 26; i++) {
23+
first[i] = 1000001;
24+
}
25+
26+
for (int i = 0; i < n; i++) {
27+
first[s[i]-'A'] = min(first[s[i]-'A'], i);
28+
last[s[i]-'A'] = i;
29+
}
30+
31+
for (int i = 0; (i < n) && !bad; i++) {
32+
p = 0;
33+
for (int j = 0; j < 26; j++) {
34+
if (first[j] <= i && last[j] >= i) {
35+
p++;
36+
}
37+
}
38+
bad = p > k;
39+
}
40+
41+
if (bad) {
42+
cout << "YES";
43+
} else {
44+
cout << "NO";
45+
}
46+
return 0;
47+
}

0 commit comments

Comments
 (0)
Please sign in to comment.