QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117713 | #6628. Flip it and Stick it | somethingnew# | 0 | 1ms | 3524kb | C++23 | 4.2kb | 2023-07-02 00:09:34 | 2024-05-31 18:47:06 |
Judging History
answer
// ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
// ➡ @roadfromroi ⬅
// ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include "array"
#include "set"
#define all(x) x.begin(), x.end()
using namespace std;
int get0(string s) {
for (auto i : s) {
if (i == '0')
return -1;
}
return 0;
}
int get00(string s) {
vector<int> ema;
int cr = 0;
for (auto i : s) {
if (i == '1') {
ema.push_back(cr);
cr = 0;
} else {
cr++;
}
}
ema.push_back(cr);
sort(all(ema));
int sm = 0;
for (auto i : ema)
sm += i;
if (ema.size() < sm)
return -1;
int res = 0;
for (auto i : ema) {
if (i > 1)
res += i - 1;
}
return res;
}
int get01(string s) {
char prv = '?';
int res = 0;
for (auto i : s) {
if (i == prv)
continue;
if (prv != '?' and i == '1')
res++;
prv = i;
}
return res;
}
int get010(string s) {
int res = 0;
string s2;
for (auto i : s) {
if (s2.empty())
s2 += i;
else if (s2.back() != '0' or i != '0')
s2 += i;
}
s = s2;
s2.clear();
for (int i = 1; i + 1 < s.size(); ++i) {
if (s[i-1] == '0' and s[i] == '1' and s[i + 1] == '0') {
res++;
}
}
//cout << s << '\n';
return (res+1)/2;
}
int get001(string s) {
char prv = '?';
int res = 0;
while (!s.empty() and s.back() == '0')
s.pop_back();
reverse(all(s));
int cn = 0;
for (auto i : s) {
if (i == prv) {
cn++;
continue;
}
if (prv == '0' and cn >= 2)
res++;
prv = i;
cn = 1;
}
if (prv == '0' and cn >= 2)
res++;
return res;
}
int get000(string s) {
vector<int> ema;
int cr = 0;
for (auto i : s) {
if (i == '1') {
ema.push_back(cr);
cr = 0;
} else {
cr++;
}
}
ema.push_back(cr);
sort(all(ema));
int sm = 0;
for (auto i : ema)
sm += i;
if (ema.size() * 2 < sm)
return -1;
vector<int> ema2;
vector<int> cnt(3);
int res = 0;
for (int i = 0; i < ema.size(); ++i) {
if (ema[i] > 2)
ema2.push_back(ema[i]-2);
else {
cnt[2-ema[i]]++;
}
}
for (auto &i : ema2) {
// cout << i << ' ';
while (i > 1 and cnt[2]) {
cnt[2]--;
i -= 2;
res++;
}
}
//cout << '\n';
for (auto &i : ema2) {
//cout << i << ' ';
while (i > 0 and cnt[2]) {
cnt[2]--;
cnt[1]++;
i -= 1;
res++;
}
while (i > 0 and cnt[1]) {
cnt[1]--;
i -= 1;
res++;
}
}
//cout << '\n';
return res;
}
void solve() {
string s, t = "000";
cin >> s;
int cn = 0;
for (auto i : t) {
if (i == '0')
cn++;
else
cn--;
}
if (cn < 0) {
for (auto &i : t) {
i = '1' - i + '0';
}
for (auto &i : s) {
i = '1' - i + '0';
}
}
if (t[0] != '0') {
reverse(all(t));
reverse(all(s));
}
//cout << s << '\n' << t << '\n';
if (t == "0") {
cout << get0(s) << '\n';
}
if (t == "00") {
cout << get00(s) << '\n';
}
if (t == "01") {
cout << get01(s) << '\n';
}
if (t == "000") {
cout << get000(s) << '\n';
}
if (t == "001") {
cout << get001(s) << '\n';
}
if (t == "010") {
cout << get010(s) << '\n';
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t = 10000;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3468kb
input:
1 0
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer Output contains longer sequence [length = 10000], but answer contains 1 elements
Subtask #2:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 1ms
memory: 3500kb
input:
0 01
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer Output contains longer sequence [length = 10000], but answer contains 1 elements
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #40:
score: 0
Wrong Answer
time: 1ms
memory: 3524kb
input:
11 011
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer Output contains longer sequence [length = 10000], but answer contains 1 elements
Subtask #5:
score: 0
Wrong Answer
Test #53:
score: 0
Wrong Answer
time: 1ms
memory: 3516kb
input:
11 011
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer Output contains longer sequence [length = 10000], but answer contains 1 elements
Subtask #6:
score: 0
Skipped
Dependency #4:
0%