#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define int long long
#define ld long double
#define pii pair<int,int>
#define rand() abs((rand()<<15)|rand())
#define randll() abs(((long long)rand()<<30)|rand())
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long seed;
asm("rdtsc" : "=A"(seed));
srand(seed);
int n, m;
cin >> n >> m;
if(n == 1) {
vector<int> grid(m+1, 0);
int totalOnes = 0;
for(int i = 1; i <= m; i++) {
cin >> grid[i];
if(grid[i])
totalOnes++;
}
int ans = 1ll<<29;
int carried = totalOnes;
for(int i = 1; i <= m; i++) {
if(grid[i] == 1) {
carried--;
carried = min(carried, totalOnes-1);
ans = min(ans, carried);
} else {
carried++;
carried = min(carried, totalOnes+1);
ans = min(ans, carried);
}
}
cout << ans << endl;
} else {
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
3 ms |
552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
552 KB |
Output is correct |
2 |
Correct |
3 ms |
636 KB |
Output is correct |
3 |
Correct |
3 ms |
712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
8408 KB |
Output is correct |
2 |
Correct |
82 ms |
8408 KB |
Output is correct |
3 |
Correct |
86 ms |
8408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |