File tree Expand file tree Collapse file tree 2 files changed +61
-1
lines changed
Codeforces Round #221 (Div. 2) Expand file tree Collapse file tree 2 files changed +61
-1
lines changed Original file line number Diff line number Diff line change
1
+ // http://codeforces.com/contest/376/problem/C
2
+
3
+ #include < bits/stdc++.h>
4
+ using namespace std ;
5
+
6
+ #define IO ios_base::sync_with_stdio (false ); cin.tie(NULL );
7
+ #define endl ' \n '
8
+ #define D (x ) cout << #x << " = " << (x) << endl;
9
+
10
+ int main () { IO
11
+ int m = 7 ;
12
+ vector<int > v = {1 , 6 , 8 , 9 };
13
+ vector<int > p = {1 , 10 , 100 , 1000 };
14
+ vector<int > vmod[7 ];
15
+
16
+ do {
17
+ int mod = 0 ;
18
+ for (int i = 0 , j = 3 ; i < 4 ; ++i, --j)
19
+ mod += (v[j] * p[i]) % m;
20
+
21
+ vmod[mod % m] = v;
22
+ }
23
+ while (next_permutation (v.begin (), v.end ()));
24
+
25
+ string s;
26
+ cin >> s;
27
+
28
+ vector<int > count (10 , 0 );
29
+ for (int i = 0 ; i < s.size (); ++i) {
30
+ count[s[i] - ' 0' ] ++;
31
+ }
32
+
33
+ count[1 ] --;
34
+ count[6 ] --;
35
+ count[8 ] --;
36
+ count[9 ] --;
37
+
38
+ string ans;
39
+ long long mod = 0 ;
40
+ long long pot = 1000 * 10 ;
41
+ for (int i = 1 ; i < 10 ; ++i) {
42
+ while (count[i] --> 0 ) {
43
+ pot %= m;
44
+ mod += (i * pot) % m;
45
+ mod %= m;
46
+ pot *= 10 ;
47
+ ans.push_back (i + ' 0' );
48
+ }
49
+ }
50
+
51
+ int ind = m - mod;
52
+ reverse (ans.begin (), ans.end ());
53
+ cout << ans;
54
+ if (!mod) ind = 0 ;
55
+ for (int i = 0 ; i < 4 ; ++i) cout << vmod[ind][i];
56
+ while (count[0 ] --> 0 ) cout << 0 ;
57
+
58
+ return 0 ;
59
+ }
Original file line number Diff line number Diff line change 763
763
15559828
764
764
15580563
765
765
15722200
766
- 15722151
766
+ 15722151
767
+ 15832285
You can’t perform that action at this time.
0 commit comments