Codeforces|Leetcode|Codechef free solutions
前往频道在 Telegram
Free codeforces, Codechef, Leetcode solutions are available 😍😍😍😍😍😍 Helped More than 200+ students to crack coding round in 2022 and helped placed them in Good companies. 🥳🥳🥳🤩🤩🤩 Dm @Cpsoln if you want help in coding round.
显示更多4 317
订阅者
无数据24 小时
-137 天
-5230 天
帖子存档
We will upload more codes for free just subscribe and share channel link with your friends😊😊😊
include <bits/stdc++.h> using namespace std; const int MAX_N = 1000000 + 100; int n, m; unordered_map<int, char> grid[MAX_N]; unordered_map<int, int> component_id[MAX_N]; unordered_map<int, int> component_size; int curr_id; #define ll long long int dfs(int i, int j) { if (i < 0 || i >= n || j < 0 || j >= m || grid[i][j] == '.' || component_id[i][j] != -1) { return 0; } component_id[i][j] = curr_id; int size = 1; size += dfs(i - 1, j); size += dfs(i + 1, j); size += dfs(i, j - 1); size += dfs(i, j + 1); return size; } int main() { int t; cin >> t; while (t--) { cin >> n >> m; component_size.clear(); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> grid[i][j]; component_id[i][j] = -1; } } curr_id = 1; int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (grid[i][j] == '#' && component_id[i][j] == -1) { component_size[curr_id] = dfs(i, j); ans = max(ans, component_size[curr_id]); curr_id++; } } } int max_size = ans; for (int i = 0; i < n; i++) { int extra = 0; unordered_set<int> s; for (int j = 0; j < m; j++) { if (grid[i][j] == '#') { s.insert(component_id[i][j]); } else { extra++; // checking any other component is present in the same row or column // check up down left and right of the current cell if (i > 0 && grid[i - 1][j] == '#') { s.insert(component_id[i - 1][j]); } if (i < n - 1 && grid[i + 1][j] == '#') { s.insert(component_id[i + 1][j]); } if (j > 0 && grid[i][j - 1] == '#') { s.insert(component_id[i][j - 1]); } if (j < m - 1 && grid[i][j + 1] == '#') { s.insert(component_id[i][j + 1]); } } } auto it = s.begin(); while (it != s.end()) { extra += component_size[*it]; it++; } max_size = max(max_size, extra); } // do this for column also for (int j = 0; j < m; j++) { int extra = 0; unordered_set<int> s; for (int i = 0; i < n; i++) { if (grid[i][j] == '#') { s.insert(component_id[i][j]); } else { extra++; // checking any other component is present in the same row or column // check up down left and right of the current cell if (i > 0 && grid[i - 1][j] == '#') { s.insert(component_id[i - 1][j]); } if (i < n - 1 && grid[i + 1][j] == '#') { s.insert(component_id[i + 1][j]); } if (j > 0 && grid[i][j - 1] == '#') { s.insert(component_id[i][j - 1]); } if (j < m - 1 && grid[i][j + 1] == '#') { s.insert(component_id[i][j + 1]); } } } auto it = s.begin(); while (it != s.end()) { extra += component_size[*it]; it++; } max_size = max(max_size, extra); } cout << max_size << endl; } return 0; }#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll H;
bool check(vector<ll> &a, vector<ll> &b, ll val) {
ll dmg = 0;
for(int i=0; i<a.size(); i++) {
ll curDmg = ((val/b[i])+1)*a[i];
dmg += curDmg;
if(dmg >= H) return true;
}
return dmg >= H;
}
void sol() {
ll h, n;
cin >> h >> n;
H = h;
vector<ll> a(n), c(n);
for(int i=0; i<n; i++) {
cin >> a[i];
}
for(int i=0; i<n; i++) {
cin >> c[i];
}
ll lo = 0;
ll hi = 1e12;
while(hi - lo > 1) {
ll mid = (lo+hi)/2;
if(check(a, c, mid)) {
hi = mid;
}else {
lo = mid;
}
}
if(check(a, c, lo)) {
cout << lo+1 << endl;
return;
}
cout << hi+1 << endl;
}
int main() {
int t = 1;
cin >> t;
while(t--) sol();
return 0;
}
#include <iostream>
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define pb push_back
void sol(){
int x,y,z,k;
cin>>x>>y>>z>>k;
int count = 0;
for(int i = 1;i<=x;i++){
for(int j = 1;j<=y;j++){
if(k%(i*j)==0&&(k/(i*j)<=z)){
count=max(count,(x-i+1)*(y-j+1)*(z-(k/(i*j))+1));
}
}
}
cout<<count<<endl;
return;
}
signed main()
{
int test;
cin>>test;
while(test--){
sol();
}
return 0;
}
After 1920 subscribers I will post E code for free in this channel
