Codeforces Round #779 (Div. 2) : Problem - A. Marin and Photoshoot 본문
Codeforce
Codeforces Round #779 (Div. 2) : Problem - A. Marin and Photoshoot
00rigin 2022. 3. 28. 01:46

참... 문제가... 이해하기 어려워서 한참 걸렸다...
010 이 있으면, "01","10"은 남여 수가 같으므로 패스, "010"은 남자가 적으므로 문제에 위반 된다.
이 경우 0110으로 만들어주어야 한다.
처음엔 브루트 포스를 써야 하나 했지만 그럴 경우 무조건 runtime에 잡힌다.
따라서 규칙을 좀 찾아보면,
1. 00 이 나올 경우 사이에 11을 넣어주어야 한다.
2. 010 이 나올 경우 사이에 1을 넣어주어야 한다.
위 두 규칙만 지키면 되므로, 입력의 앞쪽 부터 위 두개의 갯수를 찾으면 된다.
<소스코드>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stack>
#include<vector>
#include<cmath>
#include<bitset>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T;
cin>>T;
for(int t = 0; t<T; t++){
int n;
int ans = 0;
cin>>n;
string s;
cin>>s;
for(int i = 0; i<s.size(); i++){
if(s[i] == '0' && s[i+1] == '0')
ans +=2;
else if(s[i] == '0' && s[i+1] == '1' && s[i+2] == '0')
ans+=1;
}
cout<<ans<<endl;
}
}
|
cs |
<문제>
https://codeforces.com/contest/1658/problem/A
Problem - A - Codeforces
codeforces.com
'Codeforce' 카테고리의 다른 글
Codeforces Round #779 (Div. 2) Problem B. Marin and Anti-coprime Permutation (0) | 2022.03.28 |
---|