diff --git a/CF1861D.cpp b/CF1861D.cpp new file mode 100644 index 0000000..33296fb --- /dev/null +++ b/CF1861D.cpp @@ -0,0 +1,50 @@ +#include +using namespace std; +typedef long long LL ; +typedef pair 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 + */ \ No newline at end of file diff --git a/CF1864D.cpp b/CF1864D.cpp new file mode 100644 index 0000000..382defa --- /dev/null +++ b/CF1864D.cpp @@ -0,0 +1,61 @@ +#include +using namespace std; +typedef long long LL ; +typedef pair 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 + */ \ No newline at end of file diff --git a/CF1870D.cpp b/CF1870D.cpp new file mode 100644 index 0000000..569ffb5 --- /dev/null +++ b/CF1870D.cpp @@ -0,0 +1,43 @@ +#include +using namespace std; +typedef long long LL ; +typedef pair 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 + */