File tree Expand file tree Collapse file tree 2 files changed +126
-0
lines changed
2020/Div 2/616 Div 2/Programs Expand file tree Collapse file tree 2 files changed +126
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+
4
+ using namespace std ;
5
+
6
+ void solve ()
7
+ {
8
+ int no_of_elements;
9
+ cin >> no_of_elements;
10
+
11
+ vector <int > A (no_of_elements + 1 );
12
+ for (int i = 1 ; i <= no_of_elements; i++)
13
+ {
14
+ cin >> A[i];
15
+ }
16
+
17
+ vector <int > prefix_possible (no_of_elements + 1 , false );
18
+ for (int i = 1 ; i <= no_of_elements; i++)
19
+ {
20
+ if (A[i] < i - 1 )
21
+ {
22
+ break ;
23
+ }
24
+
25
+ prefix_possible[i] = true ;
26
+ }
27
+
28
+ vector <int > suffix_possible (no_of_elements + 1 , false );
29
+ for (int i = no_of_elements; i >= 1 ; i--)
30
+ {
31
+ if (A[i] < (no_of_elements - i))
32
+ {
33
+ break ;
34
+ }
35
+
36
+ suffix_possible[i] = true ;
37
+ }
38
+
39
+ int possible = (no_of_elements == 1 ? true : false );
40
+
41
+ for (int i = 1 ; i <= no_of_elements; i++)
42
+ {
43
+ if (i == 1 )
44
+ {
45
+ if (A[i] >= (no_of_elements - i) && suffix_possible[i + 1 ])
46
+ {
47
+ possible = true ;
48
+ break ;
49
+ }
50
+ }
51
+
52
+ if (i == no_of_elements)
53
+ {
54
+ if (A[i] >= (i - 1 ) && prefix_possible[i - 1 ])
55
+ {
56
+ possible = true ;
57
+ break ;
58
+ }
59
+ }
60
+
61
+ if (A[i] >= (i - 1 ) && prefix_possible[i - 1 ] && A[i] >= (no_of_elements - i) && suffix_possible[i + 1 ])
62
+ {
63
+ possible = true ;
64
+ break ;
65
+ }
66
+ }
67
+
68
+ cout << (possible ? " Yes\n " : " No\n " );
69
+ }
70
+
71
+ int main ()
72
+ {
73
+ int no_of_test_cases;
74
+ cin >> no_of_test_cases;
75
+
76
+ while (no_of_test_cases--)
77
+ solve ();
78
+
79
+ return 0 ;
80
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+
3
+ using namespace std ;
4
+
5
+ void solve ()
6
+ {
7
+ int length;
8
+ string S;
9
+
10
+ cin >> length >> S;
11
+
12
+ int odd_count = 0 ;
13
+ for (int i = 0 ; i < length; i++)
14
+ {
15
+ odd_count += (S[i] - ' 0' )%2 ;
16
+ }
17
+
18
+ if (odd_count < 2 )
19
+ {
20
+ cout << " -1\n " ;
21
+
22
+ return ;
23
+ }
24
+
25
+ string answer;
26
+ for (int i = 0 ; i < length && answer.size () < 2 ; i++)
27
+ {
28
+ if ( (S[i] - ' 0' )%2 == 1 )
29
+ {
30
+ answer += S[i];
31
+ }
32
+ }
33
+
34
+ cout << answer << " \n " ;
35
+ }
36
+
37
+ int main ()
38
+ {
39
+ int no_of_test_cases;
40
+ cin >> no_of_test_cases;
41
+
42
+ while (no_of_test_cases--)
43
+ solve ();
44
+
45
+ return 0 ;
46
+ }
You can’t perform that action at this time.
0 commit comments