This commit is contained in:
Zengtudor 2024-08-03 15:28:26 +08:00
parent 58bac001f2
commit d9c82a9e66
6 changed files with 216 additions and 1 deletions

76
day2/U111091/sun.cpp Normal file
View File

@ -0,0 +1,76 @@
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_N = 10'0000;
int times;
int x[MAX_N];
int l[MAX_N];
int prefix_r[MAX_N];
int r[MAX_N];
// void debug_array(int array[],size_t size,string name){
// cout<<"\n"<<name<<" [";
// for(int i=0;i<size;i++){
// cout<<array[i]<<(i!=size-1?",":"");
// }
// cout<<"]\n";
// }
signed main(){
cin.sync_with_stdio(false);
cin.tie(0);
cin>>times;
for(int t=1;t<=times;t++){
int n,k,m;
cin>>n>>k>>m;
for (int i=1; i<=n; i++) {
cin>>x[i];
}
string s;
cin>>s;
int sum=0,cnt=0;
vector<int> v;
int last0=1;
for (int i=2; i<=n; i++) {
if(s[i-2]=='0')
{
int dif=x[i-1]-x[last0];
sum+=dif;
cnt+=dif/m;
v.push_back(dif%m);
last0=i;
}
}
int dif=x[n]-x[last0];
sum+=dif;
cnt+=dif/m;
v.push_back(dif%m);
sort(v.begin(),v.end(),greater<int>());
if(k<=cnt)
{
sum-=k*m;
}
else
{
sum-=cnt*m;
k-=cnt;
for(int j:v)
{
if(k==0)
{
break;
}
sum-=min(j,m);
k--;
}
}
cout<<sum<<"\n";
}
}

BIN
day2/U111091/tempCodeRunnerFile Executable file

Binary file not shown.

View File

@ -0,0 +1,79 @@
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_N = 10'0000;
int times;
int x[MAX_N];
int l[MAX_N];
int prefix_r[MAX_N];
int r[MAX_N];
// void debug_array(int array[],size_t size,string name){
// cout<<"\n"<<name<<" [";
// for(int i=0;i<size;i++){
// cout<<array[i]<<(i!=size-1?",":"");
// }
// cout<<"]\n";
// }
signed main(){
cin.sync_with_stdio(false);
cin.tie(0);
cin>>times;
for(int t=1;t<=times;t++){
int n,k,m;
cin>>n>>k>>m;
for (int i=1; i<=n; i++) {
cin>>x[i];
}
string s;
cin>>s;
int sum=0,cnt=0;
vector<int> v;
int last0=1;
for (int i=2; i<=n; i++) {
if(s[i-2]=='0')
{
int dif=x[i-1]-x[last0];
sum+=dif;
cnt+=dif/m;
v.push_back(dif%m);
last0=i;
}
}
int dif=x[n]-x[last0];
sum+=dif;
cnt+=dif/m;
v.push_back(dif%m);
sort(v.begin(),v.end(),greater<int>());
if(k<=cnt)
{
sum-=k*m;
}
else
{
sum-=cnt*m;
k-=cnt;
for(int j:v)
{
if(k==0)
{
break;
}
sum-=min(j,m);
k--;
}
}
cout<<sum<<"\n";
}
}

View File

@ -11,7 +11,6 @@ signed main(){
for(int i=1;i<=q1;i++){
int r1,r2,c1,c2,x;
cin>>r1>>r2>>c1>>c2;
}
for (int i=1 ;i<=q2;i++) {
int r1,r2,c1,c2;

BIN
day2/U232856/chat Executable file

Binary file not shown.

61
day2/U232856/chat.cpp Normal file
View File

@ -0,0 +1,61 @@
#include <iostream>
#include <vector>
#include <algorithm>
const int MOD = 1e4 + 7;
using namespace std;
int count_black_rectangles(const vector<vector<int>>& grid, int n) {
vector<vector<int>> heights(n, vector<int>(n, 0));
int total_rectangles = 0;
for (int j = 0; j < n; ++j) {
for (int i = 0; i < n; ++i) {
if (grid[i][j]) {
heights[i][j] = (i > 0 ? heights[i - 1][j] + 1 : 1);
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (grid[i][j]) {
int min_height = heights[i][j];
for (int k = j; k >= 0 && grid[i][k]; --k) {
min_height = min(min_height, heights[i][k]);
if (min_height >= 2) {
total_rectangles += min_height - 1;
}
}
}
}
}
return total_rectangles;
}
int main() {
int n;
cin >> n;
vector<vector<int>> grid(n, vector<int>(n, 0));
for (int i = 0; i < n; ++i) {
string row;
cin >> row;
for (int j = 0; j < n; ++j) {
grid[i][j] = row[j] - '0';
}
}
int total_rectangles = count_black_rectangles(grid, n);
long long result = (1LL * total_rectangles * (total_rectangles - 1) / 2) % MOD;
cout << result << endl;
return 0;
}