Skip to content

Commit

Permalink
2024.10.23
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-yidie committed Oct 23, 2024
1 parent ff7b836 commit cab2ba4
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 0 deletions.
50 changes: 50 additions & 0 deletions CF1861D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
typedef pair<int,int> pii;
const int N = 2e5+100 , mod = 1e9+7;
LL n ,a[N] , k ,T , dp[N][3] ;


void AC() {
cin >> n ;
for (int i = 1; i <= n ; i++ ) cin >> a[i] ;
dp[1][0] = 0 ;dp[1][1] = 1;dp[1][2] = 1;
for (int i = 2 ; i <= n ; i++ ) {
LL mnn = (dp[i-1][0] < dp[i-1][1]) ? ( (dp[i-1][0] < dp[i-1][2]) ? dp[i-1][0] : dp[i-1][2] ) : ( (dp[i-1][1] < dp[i-1][2]) ? dp[i-1][1] : dp[i-1][2] );
if (a[i] == a[i-1]) {
dp[i][0] = dp[i-1][2] ;
dp[i][1] = 1LL + mnn;
dp[i][2] = dp[i-1][2] + 1;
} else if (a[i] > a[i-1]) {
dp[i][0] = mnn ;
dp[i][1] = min(dp[i-1][0] + 1 , dp[i-1][1] ) ;
dp[i][2] = dp[i-1][2] + 1;
} else {
dp[i][0] = dp[i-1][2] ;
dp[i][1] = 1LL + mnn ;
dp[i][2] = dp[i-1][2] ;
}
}
cout << min({dp[n][0] , dp[n][1] , dp[n][2]} ) << '\n';
}

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
T = 1 ;
cin >> T ;
while (T--) {
AC();
}
return 0;
}

/*
5
00100
01110
11111
11111
11111
*/
61 changes: 61 additions & 0 deletions CF1864D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
typedef pair<int,int> pii;
const int N = 3e3+10 , mod = 1e9+7;
LL n , a[N][N] , s[N][N];


void AC() {
cin >> n ;
for (int i = 1; i <= n ; i++ ) {
for (int j =1 ; j <= n ; j++ ) {
char c ; cin >> c ;
if (c == '0') a[i][j] = 0 ;
else a[i][j] = 1 ;
s[i][j] = 0 ;
}
}
LL ans = 0 ;
for (int i = 1; i <= n ; i++ ) {

for (int j =1 ; j <= n ; j++ ) {

if (s[i][j] & 1) { a[i][j] = 1 - a[i][j] ; }

if (a[i][j] & 1) {
a[i][j] = 1 - a[i][j] ;
ans+= 1;
s[i][j] += 1 ;
}
if (s[i][j] & 1) {
a[i+1][j] = 1 - a[i+1][j] ;
s[i+1][j-1]++ ; s[i+1][j+1] ++ ;
if (j != 1 && j != n) s[i+2][j] += s[i][j] ;
}

}

}
cout << ans << '\n';
}

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int T = 1 ;
cin >> T ;
while (T--) {
AC();
}
return 0;
}

/*
5
00100
01110
11111
11111
11111
*/
43 changes: 43 additions & 0 deletions CF1870D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
typedef pair<int,int> pii;
const int N = 2e5+100 , mod = 1e9+7;
LL n ,ans[N],a[N] , k , mn ,T ;


void AC() {
cin >> n ;
for( int i =0 ; i <= n+5 ; i++ ) ans[i] = 0 ;
ans[0] = INT_MAX , mn = INT_MAX;
for (int i =1 ; i <= n ; i++ ) { cin >> a[i] ; }
cin >> k ;
for (int i = n ; i >= 1 ; i-- ) mn = min( mn , a[i]) , a[i] = mn ;
for (int i = 1 ; i <= n ; i++ ) {
if (a[i] == a[i-1]) ans[i] = ans[i-1] ;
else ans[i] = min(ans[i-1] , k/(a[i]-a[i-1])) ;
k = k - (a[i] - a[i-1]) * ans[i];
cout << ans[i] << " " ;
}
cout << '\n';
}

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
T = 1 ;
cin >> T ;
while (T--) {
AC();
}
return 0;
}

/*
5
00100
01110
11111
11111
11111
*/

0 comments on commit cab2ba4

Please sign in to comment.