QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#107411 | #6185. Best Problem | zhoukangyang | WA | 2ms | 3412kb | C++17 | 1.7kb | 2023-05-21 11:21:08 | 2023-05-21 11:21:10 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector < int >
#define sz(a) ((int) (a).size())
#define ll long long
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a))
#define eb emplace_back
#define uint unsigned int
using namespace std;
const int N = 1e6 + 7;
char s[N];
int n, a[N];
void slv(vi a) {
while(sz(a) && !a[0]) a.erase(a.begin());
if(!sz(a)) return ;
int n = sz(a) - 1;
a[n] = 0;
L(i, 1, n - 1) {
if(a[i] > 1 && a[i + 1] == 0) {
vi A, B;
L(j, 0, i) {
A.emplace_back(a[j]);
}
L(j, i + 1, n) {
B.emplace_back(a[j]);
}
slv(A), slv(B);
return ;
}
}
for(auto u : a)
cout << u << ' ';
cout << endl;
}
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> (s + 1);
n = strlen(s + 1);
int cur = 0;
L(i, 1, n) {
if(s[i] == '1') {
++cur;
} else {
a[cur] += 1;
}
}
// vi T(cur + 1);
// L(i, 0, cur) T[i] = a[i];
// slv(T);
// L(i, 0, cur) {
// cout << a[i] << ' ';
// }
// cout << endl;
int ans = 0;
while(true) {
int ok = 0;
R(j, cur - 1, 1) {
if(a[j - 1] > 0 && a[j] == 1 && a[j + 1] != 1) {
ok = 1;
--a[j - 1];
++a[j + 1];
break;
}
}
if(!ok) {
R(j, cur - 1, 1) {
if(a[j - 1] > 0 && a[j] == 1) {
ok = 1;
--a[j - 1];
++a[j + 1];
break;
}
}
}
if(!ok) break;
++ans;
}
cout << ans << '\n';
return 0;
}
/*
0000010101100110101101010110000110100111000010010111111100101101110101000111101111010101010010101010
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3356kb
input:
10100010011001011111
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3412kb
input:
0000010101100110101101010110000110100111000010010111111100101101110101000111101111010101010010101010
output:
55
result:
wrong answer 1st numbers differ - expected: '58', found: '55'