Thanks for participating!
Idea: SlavicG
Tutorial
Tutorial is loading...
Solution
#include "bits/stdc++.h"
using namespace std;
int main() {
int t; cin >> t;
while(t--) {
int x; cin >> x;
if(x < 1400) cout << "Division 4\n";
else if(x < 1600) cout << "Division 3\n";
else if(x < 1900) cout << "Division 2\n";
else cout << "Division 1\n";
}
}
Idea: Errichto
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
int t; cin >> t;
while(t--) {
int n; cin >> n;
vector<int> cnt(n + 1, 0);
int ans = -1;
for(int i = 0; i < n; i++) {
int x; cin >> x;
if(++cnt[x] >= 3) {
ans = x;
}
}
cout << ans << endl;
}
}
Idea: mesanu
Tutorial
Tutorial is loading...
Solution
#include "bits/stdc++.h"
using namespace std;
int main() {
int t; cin >> t;
while(t--) {
int n; cin >> n;
vector<int> a(n);
int even1 = 0, even2 = 0, odd1 = 0, odd2 = 0;
for(int i = 0; i < n; ++i) {
cin >> a[i];
if(i % 2 == 0) {
if(a[i] % 2 == 1) odd1 = 1;
else even1 = 1;
} else {
if(a[i] % 2 == 1) odd2 = 1;
else even2 = 1;
}
}
if(even1 && odd1) {
cout << "NO\n";
} else if(even2 && odd2) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
}
Idea: flamestorm
Tutorial
Tutorial is loading...
Solution
for i in range(int(input())):
n = int(input())
l = input().split('W')
bad = False
for s in l:
b1 = 'R' in s
b2 = 'B' in s
if (b1 ^ b2):
bad = True
print("NO" if bad else "YES")
Idea: SlavicG
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
int t; cin >> t;
while(t--) {
int n; cin >> n;
vector<vector<int>> cnt(12, vector<int>(12, 0));
long long ans = 0;
for(int i = 0;i < n; ++i) {
string s; cin >> s;
for(int j = 0;j < 2; ++j) {
for(char c = 'a'; c <= 'k'; ++c) {
if(c == s[j]) continue;
string a = s; a[j] = c;
ans += cnt[a[0] - 'a'][a[1] - 'a'];
}
}
++cnt[s[0] - 'a'][s[1] - 'a'];
}
cout << ans << "\n";
}
}
Idea: MikeMirzayanov
Tutorial
Tutorial is loading...
Solution
t = int(input())
for test in range(t):
n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
suml = a[0]
sumr = a[n-1]
ans = 0
while l < r:
if suml == sumr:
ans = max(ans, l + 1 + n - r)
if suml <= sumr:
l+=1
suml+=a[l]
elif sumr < suml:
r-=1
sumr+=a[r]
print(ans)
Idea: MikeMirzayanov
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200007;
const int MOD = 1000000007;
void solve() {
int n, m;
cin >> n >> m;
char g[n + 7][m + 7];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> g[i][j];
}
}
for (int j = 0; j < m; j++) {
int last = n - 1;
for (int i = n - 1; i >= 0; i--) {
if (g[i][j] == 'o') {last = i - 1;}
else if (g[i][j] == '*') {swap(g[i][j], g[last][j]); last--;}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << g[i][j];
}
cout << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
// solve();
}
Idea: SlavicG
Tutorial
Tutorial is loading...
Solution
#include "bits/stdc++.h"
using namespace std;
int main() {
int t; cin >> t;
while(t--) {
int n, k; cin >> n >> k;
vector<int> cnt(31, 0), a(n);
for(int i = 0;i < n; ++i) {
cin >> a[i];
for(int j = 30; j >= 0; --j) {
if(a[i] & (1 << j)) ++cnt[j];
}
}
int ans = 0;
for(int i = 30; i >= 0; --i) {
int need = n - cnt[i];
if(need <= k) {
k -= need;
ans += (1 << i);
}
}
cout << ans << "\n";
}
}
flamestorm orz
flamestorm orz
flamestorm orz
flamestorm orz
orz
flamestorm orz
orz
orz
orz
orz
orz
orz
orz!
orz
orz
orz
orz (what does that mean btw?)
Thanks for the round, I loved it!
props on hosting a div 4 round
Thanks for the awesome round and light fast editorial!
My first full solved round! Let's goooo!
same to me
same for me
Looking forward to more div.4 rounds, so I can have flawless solves like this <3.
same hahahaha
Also, there are video solutions here for people who prefer those.
that's really helpful, thank you!
I was too slow. Feels so bad knowing I could've done tons better if only I was faster. :( I'll try harder next time. Thanks for the contest guys!
This may come off as an unpopular opinion but I feel the round should have at least consisted of 1 ~ 2 1600 rated greedy or ad-hoc style problems.
Lately, most CF div 2 rounds had very annoying C or B problems and it would have been nice to have a problem of those nature in this round. (Today's D was the closest to what I am trying to say)
The div 3 rounds's most difficult problems are at least of 1900 rating (non inflated) even though it is meant to be for < 1600 rated people.
I think it is as fair to have at least 1 ~ 2 1600 problems in div 4 rounds too following the div 3 standards.
Just some suggestions from my end.
Hi, can someone point out why i am getting wrong answer here for Question F. If i am running that test case on my system then i am getting the correct output but here it shows a different output. Can someone point it out why. Thanks in advance.
Code : https://mirror.codeforces.com/contest/1669/submission/154423744
I think you miss the case where the amount of candies the two eat overlapped
No NO, actually for this test case
6 1127 5715 4917 682 1721 4439
Judge is telling my output is 6, but on my system its coming 5 which is the correct answer
You do not initialize variable
temp
, so its value is unpredictable:Check this out 154423790
使用双指针试试 use double poiters, and move both while left and right have same amount,move only left when left has less,otherwise move the right
import java.util.*; import java.io.*; public class Main { public static void main(String args[]) throws IOException{ BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=0;i<n;i++){ int k=sc.nextInt(); int arr[]=new int[k]; for(int j=0;j<k;j++){ arr[j]=sc.nextInt(); } int ans=0; int l=0,r=k-1; int a=arr[0],b=arr[k-1]; while(l<r){; if(a==b){ ans=l+1+k-r; l++; if(l<k){ a+=arr[l]; } r--; if(r>=0){ b+=arr[r]; } } else if(a<b){ l++; if(l<k){ a+=arr[l]; } } else{ r--; if(r>=0){ b+=arr[r]; } } } System.out.println(ans); } } }
I waste all the time debugging the split string in D. Look like I should learn some python :D
Problems F and G were (in my opinion) the coolest ones in the round. Not surprised to realise that was Mike who proposed them.
in problem H why we not initialize ans=A[1]&A[2]&...A[N-1]&A[N] because why not that also contribute to final answer?? please reply
If some bit from A[1]&...&A[N] contributes to the answer, it means that every number has it, so in that case, n−count_i will be 0. In that case, that bit is catched by the answer anyways (since always k >= 0)
Very good contest for beginners. It would be better if the H problem has a Python solution. The same solution like in tutorial gets TLE.
Unfortunately, it's pretty rare to see a contest with vanilla cpython fully supported all the way up through its hardest problems.
The main way around this has been for platforms to add pypy support (for which 64-bit has been a vast improvement), combined with substituting in faster input functions... and it's pretty workable (not without quirks/caveats though).
For reference: 154321651 154359653
154457903
154457994
For some reason, my code for D didn't work even though the algo is the exact same lol Edit: small bug cost me badly :( but I had to leave the contest early
In problem E, why does multiset get TLE and map get AC 154413991 154415571.
Reason
Thanks. P/s: I have upvote your comment.
第一次参加codeforces,打卡 first time to participate contest on codeforces
Problem G is 1861. Rotating the Box.
orz
Orz, what iş means?
Meaning
Hi! This was my first contest. I solved three problems but did not get any rating points. Can someone explain why so?
You should wait, then give your points
Me with 1300 others after solving all problems! .... Le-m-gendary Greend_mister. (><)
orz
Screencast + video editorial
Amazing tutorial. I upsolved all the problems using this tutorial and also improve my logic in solved problems. Thanks.
flamestorm, if it is possible, can you tell me what is the difference between test 3 and test 45 in problem B? A reasonable Python solution takes 125ms on test 3, but more than 1s on test 45. Is there an anti-hashmap pattern, or something that I don't know of?
Hey community, I need help with problem H. I saw the solution video for problem H, but I don't know how it's working. Can anyone help me? 269545742
good job boys