## A. Erasing Zeroes

• time limit per test: 1 second
• memory limit per test: 256 megabytes

You are given a string $s$. Each character is either $0$ or $1$.

You want all $1$’s in the string to form a contiguous subsegment. For example, if the string is $0$, $1$, $00111$ or $01111100$, then all 1’s form a contiguous subsegment, and if the string is $0101$, $100001$ or $11111111111101$, then this condition is not met.

You may erase some (possibly none) $0$’s from the string. What is the minimum number of $0$’s that you have to erase?

### Input

The first line contains one integer $t$ ($1≤t≤100$) — the number of test cases.

Then $t$ lines follow, each representing a test case. Each line contains one string $s$ ($1≤|s|≤100$); each character of $s$ is either $0$ or $1$.

### Output

Print $t$ integers, where the $i$-th integer is the answer to the $i$-th testcase (the minimum number of $0$’s that you have to erase from $s$).

3
010011
0
1111000

2
0
0

### Note

In the first test case you have to delete the third and forth symbols from string 010011 (it turns into $0111$).

### Code

#include <bits/stdc++.h>
using namespace std;

char s;

int main() {
// freopen("in.txt", "r", stdin);
int T; scanf("%d", &T);
for(int t=1; t<=T; t++) {
scanf("%s", s);
int n = strlen(s);
int left = -1, right = -1;
for(int i=0; i<n; i++) {
if(s[i] == '1') {
left = i;
break;
}
}
for(int i=n-1; i>=0; i--) {
if(s[i] == '1') {
right = i;
break;
}
}
if(left == -1 || right == -1) {
printf("0\n");
continue;
}
int ans = 0;
for(int i=left+1; i<right; i++) {
if(s[i] == '0') ans++;
}
printf("%d\n", ans);
}
return 0;
}

## B. National Project

• time limit per test: 2 seconds
• memory limit per test: 256 megabytes

Your company was appointed to lay new asphalt on the highway of length $n$. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing.

Skipping the repair is necessary because of the climate. The climate in your region is periodical: there are $g$ days when the weather is good and if you lay new asphalt these days it becomes high-quality pavement; after that, the weather during the next $b$ days is bad, and if you lay new asphalt these days it becomes low-quality pavement; again $g$ good days, $b$ bad days and so on.

You can be sure that you start repairing at the start of a good season, in other words, days $1,2,…,g$ are good.

You don’t really care about the quality of the highway, you just want to make sure that at least half of the highway will have high-quality pavement. For example, if the $n=5$ then at least $3$ units of the highway should have high quality; if $n=4$ then at least $2$ units should have high quality.

What is the minimum number of days is needed to finish the repair of the whole highway?

### Input

The first line contains a single integer $T$ ($1≤T≤10^4$) — the number of test cases.

Next $T$ lines contain test cases — one per line. Each line contains three integers $n$, $g$ and $b$ ($1≤n,g,b≤10^9$) — the length of the highway and the number of good and bad days respectively.

### Output

Print $T$ integers — one per test case. For each test case, print the minimum number of days required to repair the whole highway if at least half of it should have high quality.

### Example

#### input

3
5 1 1
8 10 10
1000000 1 1000000

5
8
499999500000

### Note

In the first test case, you can just lay new asphalt each day, since days 1,3,5 are good.

In the second test case, you can also lay new asphalt each day, since days 1-8 are good.

### Code

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

int main() {
// freopen("in.txt", "r", stdin);
int T; scanf("%d", &T);
for(int t=1; t<=T; t++) {
LL n, g, b; scanf("%lld %lld %lld", &n, &g, &b);
LL num = n / 2 + (n % 2);
LL ans = 0;
if(num / g == 0) ans = n;
else {
if(num % g == 0) ans = (num / g - 1) * (g + b) + g;
else ans = (num / g) * (g + b) + (num % g);
ans = max(ans, n);
}
printf("%lld\n", ans);
}
return 0;
}

## C. Perfect Keyboard

• time limit per test: 2 seconds
• memory limit per test: 256 megabytes
Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all $26$ lowercase Latin letters will be arranged in some order.

Polycarp uses the same password $s$ on all websites where he is registered (it is bad, but he doesn’t care). He wants to assemble a keyboard that will allow to type this password very easily. He doesn’t like to move his fingers while typing the password, so, for each pair of adjacent characters in $s$, they should be adjacent on the keyboard. For example, if the password is $abacaba$, then the layout $cabdefghi$… is perfect, since characters $a$ and $c$ are adjacent on the keyboard, and $a$ and $b$ are adjacent on the keyboard. It is guaranteed that there are no two adjacent equal characters in $s$, so, for example, the password cannot be password (two characters $s$ are adjacent).

Can you help Polycarp with choosing the perfect layout of the keyboard, if it is possible?

### Input

The first line contains one integer $T$ ($1≤T≤1000$) — the number of test cases.

Then $T$ lines follow, each containing one string $s$ ($1≤|s|≤200$) representing the test case. $s$ consists of lowercase Latin letters only. There are no two adjacent equal characters in $s$.

### Output

For each test case, do the following:

• if it is impossible to assemble a perfect keyboard, print NO (in upper case, it matters in this problem);
• otherwise, print YES (in upper case), and then a string consisting of $26$ lowercase Latin letters — the perfect layout. Each Latin letter should appear in this string exactly once. If there are multiple answers, print any of them.

### Example

#### input

5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza

#### output

YES
bacdefghijklmnopqrstuvwxyz
YES
edocabfghijklmnpqrstuvwxyz
NO
YES
xzytabcdefghijklmnopqrsuvw
NO

### Code

#include <bits/stdc++.h>
using namespace std;

char s;
char ans;
bool vis;

int main() {
// freopen("in.txt", "r", stdin);
int T; scanf("%d", &T);
for(int t=1; t<=T; t++) {
scanf("%s", s); int n = strlen(s);
memset(ans, '\0', sizeof(ans));
memset(vis, false, sizeof(vis));

int now = 50;
bool NO = false;
int mn = 200, mx = -1;
for(int i=0; i<n; i++) {
if(!vis[s[i]-'a']) {
if(ans[now-1] == '\0') ans[--now] = s[i];
else if(ans[now+1] == '\0') ans[++now] = s[i];
else {
NO = true;
break;
}
vis[s[i]-'a'] = true;
}
else {
if(ans[now-1] == s[i]) {
now--;
}
else if(ans[now+1] == s[i]){
now++;
}
else {
NO = true;
break;
}
}
mn = min(mn, now);
mx = max(mx, now);
}
if(NO) {
printf("NO\n");
continue;
}
printf("YES\n");
for(int i=mn; i<=mx; i++) printf("%c", ans[i]);
for(int i=0; i<26; i++) {
if(!vis[i]) printf("%c", i+'a');
}
printf("\n");
}
return 0;
}

## 发送评论编辑评论

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
（╯‵□′）╯︵┴─┴
￣﹃￣
(/ω＼)
∠( ᐛ 」∠)＿
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ｀)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ(￣∇￣o)
ヾ(´･ ･｀｡)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò｡)
Σ(っ °Д °;)っ
( ,,´･ω･)ﾉ"(´っω･｀｡)
╮(╯▽╰)╭
o(*////▽////*)q
＞﹏＜
( ๑´•ω•) "(ㆆᴗㆆ)

Emoji