And here is the Editorial!
We hope you liked the problems. Thanks everyone!
\[^-^]/
Don't forget to praise the sun!
Tutorial
Tutorial is loading...
Solution
#include <iostream>
using namespace std;
void solve() {
int n;
cin >> n;
int cnt[10] = {};
bool f = 0;
for (int i = 0; i < n; i++) {
int dig;
cin >> dig;
cnt[dig]++;
if (cnt[0] >= 3 && cnt[1] >= 1 && cnt[2] >= 2 &&
cnt[3] >= 1 && cnt[5] >= 1 && !f) {
cout << i + 1 << endl;
f = 1;
}
}
if (!f) cout << 0 << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
Tutorial
Tutorial is loading...
Solution
#include <iostream>
#include <algorithm>
using namespace std;
void solve() {
int n, x;
cin >> n >> x;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
reverse(a, a + n);
int ans = 0;
for (int i = 0, cnt = 1; i < n; i++, cnt++) {
if (a[i] * cnt >= x) {
ans++;
cnt = 0;
}
}
cout << ans << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
Tutorial
Tutorial is loading...
Solution
#include <iostream>
using namespace std;
void solve() {
int n;
cin >> n;
if (n % 2 == 0) {
cout << -1 << endl;
return;
}
for (int i = n; i > 0; i--) {
cout << i << ' ';
}
cout << endl;
}
int main() {
int t = 1;
cin >> t;
while (t--)
solve();
}
Tutorial
Tutorial is loading...
Solution
#include <iostream>
using namespace std;
void solve() {
long long n, m, k, l, r, mid;
cin >> n >> m >> k;
l = 0, r = m;
while (l + 1 < r) {
mid = (l + r) / 2;
if ((m / (mid + 1) * mid + m % (mid + 1)) * n >= k) {
r = mid;
} else {
l = mid;
}
}
cout << r << endl;
}
int main() {
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
Tutorial
Tutorial is loading...
Solution
#include <iostream>
using namespace std;
const int MAXN = 10000001;
bool prime[MAXN];
void solve() {
int n, ans = 0;
cin >> n;
for (int i = 2; i <= n; i++) {
if (prime[i]) {
ans += n / i;
}
}
cout << ans << endl;
}
int main() {
for (int i = 0; i < MAXN; i++) prime[i] = 1;
prime[0] = prime[1] = 0;
for (int i = 2; i * i < MAXN; i++) {
if (!prime[i]) continue;
for (int j = i * i; j < MAXN; j += i)
prime[j] = 0;
}
int t;
cin >> t;
while (t--) {
solve();
}
}
Tutorial
Tutorial is loading...
Solution
#include <iostream>
using namespace std;
const int MAXN = 2010;
const int MOD = 998244353;
string s[MAXN];
int dp[MAXN][MAXN][2];
long long sdp[MAXN][MAXN][2];
int n, m, d;
long long getsum(int x, int y1, int y2, int f) {
long long res = sdp[x][y2][f];
if (y1) res -= sdp[x][y1 - 1][f];
return res;
}
int get(int i, int j, int f) {
if (s[i][j] != 'X') return 0;
long long res = 0;
if (i == n - 1) res++;
if (!f) {
res += getsum(i, max(0, j - d),
min(m - 1, j + d), 1);
res -= dp[i][j][1];
}
if (i < n - 1) {
res += getsum(i + 1, max(0, j - d + 1),
min(m - 1, j + d - 1), 0);
}
return res % MOD;
}
void solve() {
cin >> n >> m >> d;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = n - 1; i >= 0; i--) {
for (int f = 1; f >= 0; f--) {
for (int j = 0; j < m; j++) {
sdp[i][j][f] = dp[i][j][f] = get(i, j, f);
}
for (int j = 1; j < m; j++) {
sdp[i][j][f] += sdp[i][j - 1][f];
}
}
}
long long ans = 0;
for (int j = 0; j < m; j++) {
ans += dp[0][j][0];
}
cout << ans % MOD << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
Tutorial
Tutorial is loading...
Solution
#include <iostream>
#include <vector>
using namespace std;
int s, k, p;
vector<bool> was1, was2;
void bfs() {
vector<int> v;
for (int i = 0; i < s; i++) {
if (was1[i])
v.push_back(i);
}
int q = 0;
while (q < v.size()) {
int x = v[q++];
int y = x + p * k;
if (y >= 0 && y <= s && !was1[y]) {
was1[y] = 1;
v.push_back(y);
}
}
}
void solve() {
cin >> s >> k;
if (s % k == 0) {
cout << k << endl;
return;
}
if (s > k * k) {
cout << max(1, k - 2) << endl;
return;
}
was1.resize(s + 1);
was2.resize(s + 1);
for (int i = 0; i <= s; i++) {
was1[i] = was2[i] = 0;
}
p = 1;
was1[k] = 1;
while (1) {
bfs();
if (was1[s]) {
cout << k << endl;
return;
}
k = max(k - 1, 1);
p *= -1;
for (int i = 0; i <= s; i++) {
was2[i] = 0;
}
for (int i = 0; i < s; i++) {
if (was1[i]) {
if (i + p * k >= 0 && i + p * k <= s) {
was2[i + p * k] = 1;
}
}
}
swap(was1, was2);
}
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
Problem D O(1)
void solve(){
}
int main(){
}
wcnb
F has a nice explanation
Praise the sun! Solaire posture
\[T]/
long may the sunshine !
In G, I wasn't able to prove the fact where the answer will always be $$$k$$$ or $$$k - 2$$$ for $$$s \ge k^2$$$, so I am posting my solution for the same.
Main thing to note is that for each value of power $$$x$$$, we only need to consider $$$x$$$ different residues modulo $$$x$$$, and particularly for each turn around step we only need to consider the maximum $$$x$$$ values we can reach if we are travelling forwards or the minimum $$$x$$$ values if we are travelling backwards. Running complexity is $$$O(k^2)$$$ for each valid $$$k$$$ resulting in overall complexity of $$$\begin{equation} \sum_{i=1}^{k} i^2 = O\left(\frac{k(k+1)(2k+1)}{6}\right) \end{equation}$$$
Edit: My Submission — 312461704
What is the reason behind of making k <= 1000 and sum of k <= 2000 in G? I just didn't write the code because I have never wrote an n^3 algorithm for n <= 1000. And yes it has very nice constant factor and in practice works very fast. But why couldn't u make it like k <= 800, sum <= 800, any unintended solutions that pass under smaller constraints?
When it comes to this kind of question it is safe to guess the conclusion, we are almost certain that not all $$$k$$$ will be traversed, and ultimately there must be very few valuable $$$k$$$, see my submission 312426354, where we note that the run time is very short.
Edit: I think this problem may be related to the harmonic series, which has only about $$$\log{k}$$$ valid numbers.
Cool contest!
In fact there are two ways to approach the problem $$$F$$$: either by counting ways to reach the current 'X' index from the neighboring 'X' indices or vice versa, counting ways to reach the neighboring 'X' indices from the current. The first approach can be implemented with prefix sums and the second via a difference array.
In problem G I just "felt" the algorithm wouldn't run slow, then I submitted the code and got AC.
Interesting G.
Using derivatives to prove the $$$\Theta$$$ of G may be more intuitive&simple (⑅˃◡˂⑅)
Thanks for a great contest!!!
As per my current rating, of 1076, If I have solved questions till E, how much will the rating change ?
0 as your solutions will be skipped for copying from chat gpt lol
intuition might be of your own but the implementation is completely done by gpt, solve less but when you do, fully understand and implement on your own, it's just more satisfactory, also I have nothing against you so chill ^_^
Problem D
Maybe it will not be bad to expand a little bit on how k * k < s will result in either k or k — 2, l didn't realize this fact during the contest qwq.
Problem D O(1)
Can G problem be solved in $$$O(K^2)$$$
My Solution: Submission
Consider that $$$s < k*k$$$
Can any one explain another approach for problem f ?
in d part for the binary search suose you wrote while(l<=r) you get TLE error ,can someone tell me the calculation why ?
you are not changing the l to mid+1 or changing r to mid-1, that is the issue. you are just writing l and r = mid.
gotcha
can anyone please explain me in problem-G; when s=10 and k=4 how is the answer 2
got it thanks!
go forward twice with power 4 go backward twice with power 3 then, you can go forward to x=10 with power 2
too late ;(
Guys I can see my rank on friends standing but not on common standings page, will my submissions be skipped?
I didn't copy from anyone else. I copied SieveOfEratosthenes which was available before contest on gfg page which doesn't violate cf rules. So why can't I see myself on final standings page?
Some how I find C is the most difficult one among A-F, I have read the editorial, but can not I find a way to come up with solution, why people can relate to the fact that even length can not be constructed in the first place then gradually come up with the solution?
Great Contest!
What's the approx limit of operations in 1 sec on CF ? In prob E, what's the final tc of the whole code. imo its [1o^3 * (n / ln(n))] which is still 7 * 10e8. Wouldn't it give tle given 2 secs?
How easy is problem c,but it still trouble me a long time
Don't forget to praise the moon!
There is an O(1) solution for D. It is as follows (Python 3):
very easy to understand (for me at least), thank you
O(k^2logk) solution for G.
For convenience, we will only consider the round of jumping to the right here. The turn that jumps to the left is symmetrical. If the current jump distance is k0, then for each modulo result of k0, we only need to record the smallest position. Because smaller positions can always jump to larger positions. Next, consider turning at each position. These positions, such as d, d+k0, and d+2k0, must form a cyclic interval in the form of k0-1. What we need to do is to take the maximum value of the cyclic interval for the arithmetic sequence. It can be achieved using a suitable data structure.
Problem D O(1)