File tree Expand file tree Collapse file tree 3 files changed +107
-0
lines changed Expand file tree Collapse file tree 3 files changed +107
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Idea:
3
+ - Implementation, Frequency array.
4
+ */
5
+
6
+ #include < bits/stdc++.h>
7
+
8
+ using namespace std ;
9
+
10
+ int n;
11
+ string s;
12
+
13
+ int main () {
14
+ cin >> n >> s;
15
+
16
+ if (n == 1 ) {
17
+ puts (" Yes" );
18
+ return 0 ;
19
+ }
20
+
21
+ int fr[26 ] = {0 };
22
+ for (int i = 0 ; i < n; ++i)
23
+ ++fr[s[i] - ' a' ];
24
+
25
+ for (int i = 0 ; i < 26 ; ++i)
26
+ if (fr[i] > 1 ) {
27
+ puts (" Yes" );
28
+ return 0 ;
29
+ }
30
+
31
+ puts (" No" );
32
+
33
+ return 0 ;
34
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ Idea:
3
+ - Brute force the divisors of the first pair, is there is no
4
+ answer, then print "No", otherwise print "Yes".
5
+ */
6
+
7
+ #include < bits/stdc++.h>
8
+
9
+ using namespace std ;
10
+
11
+ int const N = 2e5 + 1 ;
12
+ int n;
13
+ pair<int , int > a[N];
14
+ vector<int > d;
15
+ set<int > st;
16
+
17
+ void calc_div (int x) {
18
+ d.clear ();
19
+ int sqrtx = sqrt (x) + 1 ;
20
+ for (int i = 1 ; i <= sqrtx; ++i) {
21
+ if (x % i == 0 ) {
22
+ d.push_back (i);
23
+
24
+ if (x / i != i)
25
+ d.push_back (x / i);
26
+ }
27
+ }
28
+ }
29
+
30
+ void solve () {
31
+ for (int i = 0 , cur, dd; i < d.size (); ++i) {
32
+ if (d[i] == 1 )
33
+ continue ;
34
+ cur = 0 ;
35
+ dd = d[i];
36
+
37
+ if (st.count (dd) == 1 )
38
+ continue ;
39
+ st.insert (dd);
40
+
41
+ for (int j = 1 ; j < n; ++j)
42
+ if (a[j].first % dd == 0 || a[j].second % dd == 0 )
43
+ ++cur;
44
+ else
45
+ break ;
46
+
47
+ if (cur == n - 1 ) {
48
+ printf (" %d\n " , dd);
49
+ exit (0 );
50
+ }
51
+ }
52
+ }
53
+
54
+ int main () {
55
+ scanf (" %d" , &n);
56
+ for (int i = 0 ; i < n; ++i)
57
+ scanf (" %d %d" , &a[i].first , &a[i].second );
58
+
59
+ sort (a, a + n);
60
+ reverse (a, a + n);
61
+
62
+ calc_div (a[0 ].first );
63
+ solve ();
64
+
65
+ calc_div (a[0 ].second );
66
+ solve ();
67
+
68
+ puts (" -1" );
69
+
70
+ return 0 ;
71
+ }
Original file line number Diff line number Diff line change 554
554
- [ 1023B. Pair of Toys] ( http://codeforces.com/contest/1023/problem/B )
555
555
- [ 1023C. Bracket Subsequence] ( http://codeforces.com/contest/1023/problem/C )
556
556
- [ 1023D. Array Restoration] ( http://codeforces.com/contest/1023/problem/D )
557
+ - [ 1025A. Doggo Recoloring] ( http://codeforces.com/contest/1025/problem/A )
558
+ - [ 1025B. Weakened Common Divisor] ( http://codeforces.com/contest/1025/problem/B )
557
559
- [ 1027A. Palindromic Twist] ( http://codeforces.com/contest/1027/problem/A )
558
560
- [ 1027B. Numbers on the Chessboard] ( http://codeforces.com/contest/1027/problem/B )
559
561
- [ 1027C. Minimum Value Rectangle] ( http://codeforces.com/contest/1027/problem/C )
You can’t perform that action at this time.
0 commit comments