#include <iostream>
#include <vector>
using namespace std;
int n, m;
vector<int> suff;
vector<vector<int> > a, dp;
void solve_3()
{
int ans = 1e9;
suff.resize(m + 5, 0);
dp.resize(m + 5, vector<int>(2, 0));
for (int i = m; i >= 1; --i) suff[i] = suff[i + 1] + (a[1][i] == 1);
for (int i = 1; i <= m; ++i)
{
dp[i][0] = dp[i - 1][0] + (a[1][i] == 1);
dp[i][1] = min(dp[i - 1][1] + (a[1][i] == 0), dp[i - 1][0] + (a[1][i] == 1));
ans = min(ans, dp[i][1] + suff[i + 1]);
}
cout << ans;
}
int main()
{
cin >> n >> m;
a.resize(n + 5, vector<int>(m + 5, 0));
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
cin >> a[i][j];
if (n == 1)
solve_3();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
572 KB |
Output is correct |
2 |
Correct |
2 ms |
572 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
3 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2204 KB |
Output is correct |
2 |
Correct |
7 ms |
2204 KB |
Output is correct |
3 |
Correct |
7 ms |
2204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
340 ms |
85308 KB |
Output is correct |
2 |
Correct |
342 ms |
87168 KB |
Output is correct |
3 |
Correct |
321 ms |
89220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
43 ms |
89220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
89220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
145 ms |
89220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |