File tree Expand file tree Collapse file tree 4 files changed +159
-1
lines changed
Codeforces Round #387 (Div. 2) Expand file tree Collapse file tree 4 files changed +159
-1
lines changed Original file line number Diff line number Diff line change
1
+ // http://codeforces.com/contest/747/problem/A
2
+
3
+ #include < bits/stdc++.h>
4
+ using namespace std ;
5
+
6
+ #define endl ' \n '
7
+ #define D (x ) cout << #x << " = " << (x) << endl;
8
+
9
+ int main () {
10
+ int n;
11
+ cin >> n;
12
+
13
+ int mm = INT_MAX;
14
+ int a, b;
15
+ for (int i = 1 ; i <= n ; ++i) {
16
+ if (n % i != 0 ) continue ;
17
+ int other = n / i;
18
+ if (other - i < mm && other >= i) {
19
+ a = i;
20
+ b = other;
21
+ mm = b - a;
22
+ }
23
+ }
24
+
25
+ cout << a << " " << b << endl;
26
+ return 0 ;
27
+ }
Original file line number Diff line number Diff line change
1
+ // http://codeforces.com/contest/747/problem/B
2
+
3
+ #include < bits/stdc++.h>
4
+ using namespace std ;
5
+
6
+ #define endl ' \n '
7
+ #define D (x ) cout << #x << " = " << (x) << endl;
8
+
9
+ int main () {
10
+ int n;
11
+ string s;
12
+ cin >> n >> s;
13
+
14
+ if (n % 4 != 0 ) {
15
+ cout << " ===" << endl;
16
+ return 0 ;
17
+ }
18
+
19
+ char v[] = {' A' , ' C' , ' G' ,' T' };
20
+ int tot[] = {0 , 0 , 0 , 0 };
21
+ for (int i = 0 ; i < n; ++i) {
22
+ if (s[i] == v[0 ]) tot[0 ] ++;
23
+ if (s[i] == v[1 ]) tot[1 ] ++;
24
+ if (s[i] == v[2 ]) tot[2 ] ++;
25
+ if (s[i] == v[3 ]) tot[3 ] ++;
26
+ }
27
+
28
+ int len = n / 4 ;
29
+ for (int i = 0 ; i < 4 ; ++i) {
30
+ int t = len - tot[i];
31
+ for (int j = 0 ; j < n && t; ++j) {
32
+ if (s[j] == ' ?' && t) {
33
+ s[j] = v[i];
34
+ t --;
35
+ }
36
+ }
37
+ }
38
+
39
+ memset (tot, 0 , sizeof tot);
40
+ for (int i = 0 ; i < n; ++i) {
41
+ if (s[i] == v[0 ]) tot[0 ] ++;
42
+ if (s[i] == v[1 ]) tot[1 ] ++;
43
+ if (s[i] == v[2 ]) tot[2 ] ++;
44
+ if (s[i] == v[3 ]) tot[3 ] ++;
45
+ }
46
+
47
+ bool ok = true ;
48
+ for (int i = 0 ; i < 4 ; ++i) {
49
+ if (tot[i] != len) ok = false ;
50
+ }
51
+
52
+ cout << (ok ? s : " ===" ) << endl;
53
+ return 0 ;
54
+ }
Original file line number Diff line number Diff line change
1
+ // http://codeforces.com/contest/747/problem/C
2
+
3
+ #include < bits/stdc++.h>
4
+ using namespace std ;
5
+
6
+ #define endl ' \n '
7
+ #define D (x ) cout << #x << " = " << (x) << endl;
8
+
9
+ struct task {
10
+ int t, k, d;
11
+ task () {}
12
+ task (int a, int b, int c) {
13
+ t = a;
14
+ k = b;
15
+ d = c;
16
+ }
17
+ };
18
+
19
+ int main () {
20
+ int n, q;
21
+ cin >> n >> q;
22
+
23
+ vector<task> v (q);
24
+
25
+ int a, b, c;
26
+ for (int i = 0 ; i < q; ++i) {
27
+ cin >> a >> b >> c;
28
+ v[i] = task (a, b, c);
29
+ }
30
+
31
+ reverse (v.begin (), v.end ());
32
+
33
+ vector<int > servers (n, 0 );
34
+ for (int i = 1 ; i <= 1e6 + 3333 ; ++i) {
35
+ if (v.size ()) {
36
+ task cur = v.back ();
37
+ a = cur.t ;
38
+ b = cur.k ;
39
+ c = cur.d ;
40
+
41
+ if (a == i) {
42
+ int free = 0 ;
43
+ for (int j = 0 ; j < servers.size (); ++j) {
44
+ if (!servers[j]) free ++;
45
+ }
46
+
47
+ int tot = b;
48
+ int sum = 0 ;
49
+ if (free >= b) {
50
+ for (int j = 0 ; j < servers.size () && tot > 0 ; ++j) {
51
+ if (servers[j] == 0 ) {
52
+ servers[j] = c;
53
+ sum += j + 1 ;
54
+ tot --;
55
+ }
56
+ }
57
+
58
+ cout << sum << endl;
59
+ }
60
+ else {
61
+ cout << -1 << endl;
62
+ }
63
+
64
+ v.pop_back ();
65
+ }
66
+ }
67
+
68
+ for (int j = 0 ; j < servers.size (); ++j) {
69
+ if (servers[j] > 0 ) servers[j] --;
70
+ }
71
+ }
72
+
73
+ return 0 ;
74
+ }
Original file line number Diff line number Diff line change 922
922
24132337
923
923
24366846
924
924
24374352
925
- 24384579
925
+ 24384579
926
+ 24358027
927
+ 24357514
928
+ 24357587
You can’t perform that action at this time.
0 commit comments