I would like to request the Codeforces team to take action against cheaters. I have evidence against a prominent YouTube channel that consistently leaks solutions. Cheating demotivates genuine participants who work hard but don't see improvements in their ratings.
If anyone else has a better idea, please share it with the team.
Problem A
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int testCaseCount;
cin >> testCaseCount;
while (testCaseCount--) {
int rowCount, columnCount;
cin >> rowCount >> columnCount;
vector<vector<int>> originalMatrix(rowCount, vector<int>(columnCount));
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
cin >> originalMatrix[rowIndex][columnIndex];
if (rowCount == 1 && columnCount == 1) {
cout << -1 << endl;
continue;
}
vector<int> flatElements;
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
flatElements.push_back(originalMatrix[rowIndex][columnIndex]);
rotate(flatElements.begin(), flatElements.begin() + 1, flatElements.end());
vector<vector<int>> transformedMatrix(rowCount, vector<int>(columnCount));
int elementIndex = 0;
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
transformedMatrix[rowIndex][columnIndex] = flatElements[elementIndex++];
bool isValid = true;
for (int rowIndex = 0; rowIndex < rowCount && isValid; rowIndex++)
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
if (originalMatrix[rowIndex][columnIndex] == transformedMatrix[rowIndex][columnIndex])
isValid = false;
if (!isValid) {
cout << -1 << endl;
} else {
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
cout << transformedMatrix[rowIndex][columnIndex] << " ";
}
cout << endl;
}
}
}
return 0;
}
Problem B
#include <iostream>
#include <vector>
using namespace std;
// Function prototypes
int getA();
vector<char> getB(int size);
void displayC();
void displayD();
void processE() {
int f = getA();
vector<char> g = getB(f);
vector<char> h = getB(f);
for (int i = 0; i < f; i++) {
if (g[i] == '0' && h[i] == '1') {
displayC();
return;
}
if (g[i] == '0' && h[i] == '0') continue;
else break;
}
displayD();
}
void startF() {
int j = 1;
j = getA();
while (j-- > 0) processE();
}
int main() {
startF();
return 0;
}
// Helper functions
int getA() {
int k;
cin >> k;
return k;
}
vector<char> getB(int size) {
vector<char> l(size);
for (int m = 0; m < size; ++m) {
cin >> l[m];
}
return l;
}
void displayC() {
cout << "NO" << endl;
}
void displayD() {
cout << "YES" << endl;
}
Problem C
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void process_subsegments() {
ll num_elements, max_sum;
cin >> num_elements >> max_sum;
ll elements_array[num_elements], prefix_sum_array[num_elements + 1] = {0}, dynamic_programming_array[num_elements + 3] = {0};
// Read elements array
for (ll i = 0; i < num_elements; ++i) {
cin >> elements_array[i];
prefix_sum_array[i + 1] = prefix_sum_array[i] + elements_array[i];
}
ll total_valid_subsegments = 0;
// Process subsegments in reverse order
for (ll i = num_elements - 1; i >= 0; --i) {
ll target_sum = prefix_sum_array[i] + max_sum;
// Find the lower bound of the target sum in the prefix sum array
auto lower_bound_index = lower_bound(prefix_sum_array, prefix_sum_array + num_elements + 1, target_sum) - prefix_sum_array;
// Calculate the number of valid subsegments
if (lower_bound_index == num_elements + 1)
dynamic_programming_array[i] += (num_elements - i);
else if (target_sum == prefix_sum_array[lower_bound_index])
dynamic_programming_array[i] += (lower_bound_index - i) + dynamic_programming_array[lower_bound_index + 1];
else
dynamic_programming_array[i] += (lower_bound_index - i - 1) + dynamic_programming_array[lower_bound_index];
}
// Calculate the total number of valid subsegments
for (ll i = 0; i < num_elements + 3; ++i) {
total_valid_subsegments += dynamic_programming_array[i];
}
cout << total_valid_subsegments << endl;
}
int main() {
ll test_cases = 1;
cin >> test_cases;
while (test_cases--) {
process_subsegments();
}
return 0;
}
Some Nice Screenshots from Live Stream Chat