codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1669.md (5600B)


      1 Source: https://codeforces.com/blog/entry/102101
      2 
      3 Thanks for participating!
      4 
      5 [1669A - Division?](/contest/1669/problem/A "Codeforces Round 784 (Div. 4)")
      6 
      7 Idea: [SlavicG](/profile/SlavicG "Expert SlavicG")
      8 
      9 **Tutorial**
     10 
     11 Tutorial is loading...
     12 
     13 **Solution**
     14 
     15 ```
     16 #include "bits/stdc++.h"
     17 using namespace std;
     18 
     19 int main() {
     20     int t; cin >> t;
     21     while(t--) {
     22         int x; cin >> x;
     23         if(x < 1400) cout << "Division 4\n";
     24         else if(x < 1600) cout << "Division 3\n";
     25         else if(x < 1900) cout << "Division 2\n";
     26         else cout << "Division 1\n";
     27     }
     28 }
     29 ```
     30 
     31 [1669B - Triple](/contest/1669/problem/B "Codeforces Round 784 (Div. 4)")
     32 
     33 Idea: [Errichto](/profile/Errichto "International Grandmaster Errichto")
     34 
     35 **Tutorial**
     36 
     37 Tutorial is loading...
     38 
     39 **Solution**
     40 
     41 ```
     42 #include <bits/stdc++.h>
     43 using namespace std;
     44 
     45 int main() {
     46 	int t; cin >> t;
     47 	while(t--) {
     48 	    int n; cin >> n;
     49     	vector<int> cnt(n + 1, 0);
     50     	int ans = -1;
     51     	for(int i = 0; i < n; i++) {
     52     		int x; cin >> x;
     53     		if(++cnt[x] >= 3) {
     54     			ans = x;
     55     		}
     56     	}
     57     	cout << ans << endl;
     58 	}
     59 }
     60 ```
     61 
     62 [1669C - Odd/Even Increments](/contest/1669/problem/C "Codeforces Round 784 (Div. 4)")
     63 
     64 Idea: [mesanu](/profile/mesanu "Expert mesanu")
     65 
     66 **Tutorial**
     67 
     68 Tutorial is loading...
     69 
     70 **Solution**
     71 
     72 ```
     73 #include "bits/stdc++.h"
     74 using namespace std;
     75  
     76 int main() {
     77     int t; cin >> t;
     78     while(t--) {
     79         int n; cin >> n;
     80         vector<int> a(n);
     81 
     82         int even1 = 0, even2 = 0, odd1 = 0, odd2 = 0;
     83         for(int i = 0; i < n; ++i) {
     84             cin >> a[i];
     85             if(i % 2 == 0) {
     86                 if(a[i] % 2 == 1) odd1 = 1;
     87                 else even1 = 1; 
     88             } else {
     89                 if(a[i] % 2 == 1) odd2 = 1;
     90                 else even2 = 1;
     91             }
     92         }
     93 
     94         if(even1 && odd1) {
     95             cout << "NO\n";
     96         } else if(even2 && odd2) {
     97             cout << "NO\n";
     98         } else {
     99             cout << "YES\n";
    100         }
    101     }
    102 }
    103 ```
    104 
    105 [1669D - Colorful Stamp](/contest/1669/problem/D "Codeforces Round 784 (Div. 4)")
    106 
    107 Idea: [flamestorm](/profile/flamestorm "Candidate Master flamestorm")
    108 
    109 **Tutorial**
    110 
    111 Tutorial is loading...
    112 
    113 **Solution**
    114 
    115 ```
    116 for i in range(int(input())):
    117     n = int(input())
    118     l = input().split('W')
    119     bad = False
    120     for s in l:
    121     	b1 = 'R' in s
    122     	b2 = 'B' in s
    123     	if (b1 ^ b2):
    124     		bad = True
    125     print("NO" if bad else "YES")
    126 ```
    127 
    128 [1669E - 2-Letter Strings](/contest/1669/problem/E "Codeforces Round 784 (Div. 4)")
    129 
    130 Idea: [SlavicG](/profile/SlavicG "Expert SlavicG")
    131 
    132 **Tutorial**
    133 
    134 Tutorial is loading...
    135 
    136 **Solution**
    137 
    138 ```
    139 #include <bits/stdc++.h>
    140 using namespace std;
    141 
    142 int main() {
    143     int t; cin >> t;
    144     while(t--) {
    145         int n; cin >> n;
    146 
    147         vector<vector<int>> cnt(12, vector<int>(12, 0));
    148         long long ans = 0;
    149         
    150         for(int i = 0;i < n; ++i) {
    151             string s; cin >> s;
    152             for(int j = 0;j < 2; ++j) {
    153                 for(char c = 'a'; c <= 'k'; ++c) {
    154                     if(c == s[j]) continue;
    155                     string a = s; a[j] = c;
    156                     ans += cnt[a[0] - 'a'][a[1] - 'a'];
    157                 }
    158             }
    159             ++cnt[s[0] - 'a'][s[1] - 'a'];
    160         }
    161         cout << ans << "\n";
    162     }
    163 }
    164 ```
    165 
    166 [1669F - Eating Candies](/contest/1669/problem/F "Codeforces Round 784 (Div. 4)")
    167 
    168 Idea: [MikeMirzayanov](/profile/MikeMirzayanov "Headquarters, MikeMirzayanov")
    169 
    170 **Tutorial**
    171 
    172 Tutorial is loading...
    173 
    174 **Solution**
    175 
    176 ```
    177 t = int(input())
    178 for test in range(t):
    179     n = int(input())
    180     a = list(map(int, input().split()))
    181     l = 0
    182     r = n - 1
    183     suml = a[0]
    184     sumr = a[n-1]
    185     ans = 0
    186     while l < r:
    187         if suml == sumr:
    188             ans = max(ans, l + 1 + n - r)
    189 
    190         if suml <= sumr:
    191             l+=1
    192             suml+=a[l]
    193 
    194         elif sumr < suml:
    195             r-=1
    196             sumr+=a[r]
    197             
    198     print(ans)
    199 ```
    200 
    201 [1669G - Fall Down](/contest/1669/problem/G "Codeforces Round 784 (Div. 4)")
    202 
    203 Idea: [MikeMirzayanov](/profile/MikeMirzayanov "Headquarters, MikeMirzayanov")
    204 
    205 **Tutorial**
    206 
    207 Tutorial is loading...
    208 
    209 **Solution**
    210 
    211 ```
    212 #include <bits/stdc++.h>
    213 
    214 using namespace std;
    215 
    216 const int MAX = 200007;
    217 const int MOD = 1000000007;
    218 
    219 void solve() {
    220 	int n, m;
    221 	cin >> n >> m;
    222 	char g[n + 7][m + 7];
    223 	for (int i = 0; i < n; i++) {
    224 		for (int j = 0; j < m; j++) {
    225 			cin >> g[i][j];
    226 		}
    227 	}
    228 	for (int j = 0; j < m; j++) {
    229 		int last = n - 1;
    230 		for (int i = n - 1; i >= 0; i--) {
    231 			if (g[i][j] == 'o') {last = i - 1;}
    232 			else if (g[i][j] == '*') {swap(g[i][j], g[last][j]); last--;}
    233 		}
    234 	}
    235 	for (int i = 0; i < n; i++) {
    236 		for (int j = 0; j < m; j++) {
    237 			cout << g[i][j];
    238 		}
    239 		cout << '\n';
    240 	}
    241 }
    242 
    243 int main() {
    244     ios::sync_with_stdio(false);
    245     cin.tie(nullptr);
    246     int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
    247     // solve();
    248 }
    249 ```
    250 
    251 [1669H - Maximal AND](/contest/1669/problem/H "Codeforces Round 784 (Div. 4)")
    252 
    253 Idea: [SlavicG](/profile/SlavicG "Expert SlavicG")
    254 
    255 **Tutorial**
    256 
    257 Tutorial is loading...
    258 
    259 **Solution**
    260 
    261 ```
    262 #include "bits/stdc++.h"
    263 using namespace std;
    264 
    265 int main() {
    266     int t; cin >> t;
    267     while(t--) {
    268         int n, k; cin >> n >> k;
    269         vector<int> cnt(31, 0), a(n);
    270         for(int i = 0;i < n; ++i) {
    271             cin >> a[i];
    272             for(int j = 30; j >= 0; --j) {
    273                 if(a[i] & (1 << j)) ++cnt[j];
    274             }
    275         }
    276         int ans = 0;
    277         for(int i = 30; i >= 0; --i) {
    278             int need = n - cnt[i];
    279             if(need <= k) {
    280                 k -= need;
    281                 ans += (1 << i);
    282             }
    283         }
    284         cout << ans << "\n";
    285     }
    286 }
    287 ```