File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+ using ll = int64_t ;
5
+ using ff = long double ;
6
+
7
+ bool solve (string const & S) {
8
+ vector<int > count (10 , 0 );
9
+ for (auto c : S) {
10
+ int i = c - ' 0' ;
11
+ count[i] = min (3 , count[i]+1 );
12
+ }
13
+
14
+ vector<int > xs;
15
+ for (int i = 0 ; i < 10 ; ++i) {
16
+ while (count[i] > 0 ) {
17
+ xs.push_back (i);
18
+ --count[i];
19
+ }
20
+ }
21
+
22
+ int const M = xs.size ();
23
+ assert (M >= 1 );
24
+ if (M == 1 ) {
25
+ return xs[0 ] % 8 == 0 ;
26
+ }
27
+ if (M == 2 ) {
28
+ int s1 = xs[0 ] * 10 + xs[1 ];
29
+ int s2 = xs[1 ] * 10 + xs[0 ];
30
+ return (s1 % 8 == 0 || s2 % 8 == 0 );
31
+ }
32
+ for (int i = 0 ; i < M; ++i) {
33
+ for (int j = 0 ; j < M; ++j) {
34
+ if (i == j) continue ;
35
+ for (int k = 0 ; k < M; ++k) {
36
+ if (k == i || k == j) continue ;
37
+ int s = xs[i] * 100 + xs[j] * 10 + xs[k];
38
+ if (s % 8 == 0 ) return true ;
39
+ }
40
+ }
41
+ }
42
+ return false ;
43
+ }
44
+
45
+ int main () {
46
+ ios_base::sync_with_stdio (false );
47
+ cin.tie (0 ); cout.tie (0 );
48
+
49
+ string S;
50
+ cin >> S;
51
+ auto ans = solve (S) ? " Yes" : " No" ;
52
+ cout << ans << endl;
53
+
54
+ return 0 ;
55
+ }
You can’t perform that action at this time.
0 commit comments