Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; char S[MAXN]; int main(void) { int N; scanf("%d", &N); scanf("%s", S); int ans = 1; int curr = 0; static vector<int> vec; for (int i = 1; i < N; ++i) { if (S[i] != S[i - 1]) { vec.push_back(i - curr); curr = i; } ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int n, o = 0; char s[100000] = {}; int main() { ios::sync_with_stdio(false); cin >> n; cin >> s; for (int i = 0; i < (n - 1); ++i) { if (s[i] != s[i + 1]) ++o; } cout << min(n, o + 3); }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; char str[100010]; int main() { int n, i, fl = 0, tot = 0; scanf("%d ", &n); int ed = n; for (i = 0; i < n; i++) { scanf("%c", &str[i]); if (i) { if (fl && str[i] != str[i - 1]) ed = i; if (str[i] == str[i - 1]) { fl = 1; } if ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class Main { static MyScanner in; static PrintWriter out; // static Timer timer = new Timer(); public static void main(String[] args) throws IOException { in = new MyScanner(); ...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; long long int n, ar[100000], i, lp = 2, cnt = 1, x, y, ans; priority_queue<int> pq; string s; int main() { cin >> n >> s; for (i = 0; i < n; i++) { if (s[i] == lp) cnt++; else { ans++; pq.push(cnt); cnt = 1; } lp = s[i]; } pq....
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n=int(input()) s=[int(i) for i in input()] dp=[[0 for _ in range(2)]for _ in range(3)] for i in range(n): x=s[i] dp[2][x]=max(dp[2][x],max(dp[2][1^x],dp[1][1^x])+1) dp[1][1^x]=max(dp[1][1^x],max(dp[1][x],dp[0][x])+1) dp[0][x]=max(dp[0][x],dp[0][1^x]+1) print(max(dp[2][0],dp[2][1]))
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n = input() s = raw_input() cnt, parts, flag = 0, 0, False i = 0 while i < n: parts += 1 if i < n - 1 and s[i] == s[i+1]: cnt += 1 acc = 1 while i < n - 1 and s[i] == s[i+1]: i += 1 acc += 1 if acc >= 3: flag = True i += 1 if cnt == 1 and ...
PYTHON
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
###### ### ####### ####### ## # ##### ### ##### # # # # # # # # # # # # # ### # # # # # # # # # # # # # ### ###### ######### # # # # # # ...
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int check(int* arr, int n, int h) { vector<int> index, v2; int i = 0, last, ans = 0; while (i < n) { if (arr[i] == h) { last = h; index.push_back(i); ans = 1; i++; break; } else v2.push_back(i); i++; } while (i < n) ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; int ans = 3; cin >> n; string s; cin >> s; for (int i = 1; i < n; i++) { ans += s[i] != s[i - 1]; } cout << min(ans, n); return 0; }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; char str[100005]; int dp[100005][2][2]; int main() { int n; while (cin >> n) { cin >> str; memset(dp, -1, sizeof(dp)); dp[0][0][0] = 1; dp[0][0][1] = -1; dp[0][1][1] = 1; dp[0][1][0] = -1; for (int i = 1; i < n; i++) { if (str[i] == str...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author ankur */ public class Main...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int N, c[100001]; int main() { if (fopen("input.txt", "r")) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } scanf("%d", &N); int cnt1 = 0, cnt0 = 0, cur = -1, cnt12 = 0, cnt02 = 0, Cnt0 = 0, Cnt1 = 0; int cuu = 0, C = 0; for (in...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Pradyumn */ public class M...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, m; int dp[maxn][5]; char ss[maxn]; int main() { scanf("%d", &n); getchar(); scanf("%s", ss + 1); for (int i = 1; i <= n; i++) { if (ss[i] == '0') { dp[i][0] = dp[i - 1][1] + 1; dp[i][1] = dp[i - 1][1]; } else if ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
public class ProblemC { public static void main(String[] args) throws java.io.IOException { try (java.util.Scanner sc = new java.util.Scanner(System.in)) { sc.next(); char[] a = sc.next().toCharArray(); int c = 0; int btw = 1; for (int i = 1; i < a.length; i++) if (a[i] == a[...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; void init_cin() { ios_base::sync_with_stdio(false); cin.tie(0); } int d[111111][2][3]; int main() { init_cin(); int n; cin >> n; string s; cin >> s; for (int i = 1; i <= n; i++) { int c = s[i - 1] - '0'; d[i][c][0] = max(d[i - 1][c][0], d[i - 1][1 - ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000") #pragma warning(disable : 6031) #pragma warning(disable : 4244) #pragma warning(disable : 26451) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long mod = int(1e9) + 7; const int INF = 1e9; const ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string str; char* s; cin >> str; s = &str[0]; int pre = s[0] - '0'; int res = 1; for (int i = 1; i < n; i++) { if (pre != (s[i] - '0')) { res++; pre = s[i] - '0'; } } cout << min(n, res + 2); }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; int f = -1, l = n - 1; for (int i = 1; i < n; ++i) { if (s[i] == s[i - 1]) { if (f == -1) f = i; else l = i - 1; } } if (f == -1) f = 0; for (int i = f; i <= l; ++i) { if (s...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int INF = (int)1E9; int N, P; char str[100005]; pair<int, int> pr[100005]; int main() { cin >> N; scanf("%s", str); int cnt2 = 0, cnt3 = 0; for (int i = (0); i < (N); i++) { int j = i; while (j < N && str[j] == str[i]) j++; int cnt = j - i; pr[...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { InputStream is = System.in; OutputStrea...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; import java.lang.*; import java.io.*; public class feb20 { public static void main(String[] srgs) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); String[] scn = (br.readLine()).trim().split(" "); int n =...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
""" Codeforces Round #334 (Div. 2) Problem 604 C. @author yamaton @date 2015-12-01 """ import itertools as it import functools import operator import collections import math import sys def solve(s, n): if n == 1: return 1 alts = sum(a != b for (a, b) in zip(s, s[1:])) + 1 lens = [sum(1 for i in...
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n=int(input()) s=input().strip('\n') cur=s[0] l=1 for i in range(1,n): if s[i]!=cur: l+=1 cur=s[i] print(min(l+2,n))
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n = int(raw_input()) S = raw_input() k = 0 for i in xrange(n-1): if S[i] != S[i+1]: k += 1 if k >= n-2: print n else: print k+3
PYTHON
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 5; const long long INF = 1e18 + 5; const long long maxn = 5e6 + 5; long long nn = 1e9 + 7; string second[555555]; map<string, int> m, mm, mmm; int pos[1000005], dp[105][105][2]; int mod = 1e8; int main() { cin.tie(0); cout.tie(0); ios_base:...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int a[100005]; string s; int main() { int n; cin >> n; cin >> s; int ans = 1; for (int i = 1; i < n; i++) ans += (s[i] != s[i - 1]); cout << min(ans + 2, n); return 0; }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n = int(input()) s = input() def solve(n, s): if n <= 3: return n cum = 0 p = '2' count = 0 for i, v in enumerate(s): if v != p: cum += 1 else: count += 1 p = v if count == 0: return cum elif count == 1: return cum + 1 ...
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); int N, sol = 1; std::string S; std::cin >> N >> S; for (int i = 0; i < N - 1; i++) sol += (S[i] != S[i + 1]); std::cout << std::min(N, sol + 2); return 0; }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import javax.swing.text.MutableAttributeSet; import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner input = new Scanner(System.in); int x = input.nextInt(); input.nextLine(); StringBuilder str = ne...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
def solve(n,ar): #find alternating subsequence without flip res = 1 for i in range(n-1): if ar[i] != ar[i+1]: res += 1 print(min(res+2,n)) if __name__ == '__main__': n = int(input()) ar = list(input()) solve(n,ar)
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.Scanner; public class C334 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n; String s; n = in.nextInt(); s=in.next(); int ans=0; for(int i=0;i<n-1;i++){ if(s.charAt(i)!=s.charAt(i+1)){ ...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const long long N = 100010; long long n, arr[N], extra[N]; long long power_mod(long long x, long long y) { x %= 1000000007; long long res = 1; while (y) { if (y & 1) { res = (res * x) % 1000000007; } y /= 2; x = (x * x) % 1000000007; } return...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 4; int n; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; cin >> s; int b = 0; for (int i = 1; i < n; i++) if (s[i] != s[i - 1]) b++; b++; int tmp = 0; for (int i = 1; i < n; i++) if ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 100005, OO = 0x3f3f3f3f; long long x, c, n, a, n2; bitset<N> isprime; vector<int> v; string s; int mem[N][2][2][2]; int solve(int i, bool ch, bool ch2, bool pr) { if (i == n) return 0; int &ret = mem[i][ch][pr][ch2]; if (ret != -1) return ret; int op1 ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, i; char a[100000]; int dp[100000][3]; int nearest_same[100000]; int nearest_op[100000]; cin >> n; for (i = 0; i < n; ++i) cin >> a[i]; int ans = 0; nearest_op[n - 1] = nearest_same[n - 1] = -1; for (i = n - 2; i >= 0; --i) { if (a...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int prefix[200007], suffix[200007], maxi = 0; void precal(string s) { int cnt = 0; bool zero; if (s[0] == '0') zero = 1; else zero = 0; for (int i = 0; i < s.size(); ++i) { if (zero && s[i] == '0') { ++cnt; zero = 0; } else if (!zero &&...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.*; import java.math.BigInteger; import java.util.StringTokenizer; /** * Created by Leonti on 2015-12-04. */ public class C { public static void main(String[] args) { InputReader inputReader = new InputReader(System.in); PrintWriter printWriter = new PrintWriter(System.out, true...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int n, ans, tot; char s[111111]; int main() { scanf("%d%s", &n, s); ans = tot = 0; for (int i = 1; i < n; i++) if (s[i] != s[i - 1]) ans++; else tot++; printf("%d\n", ans + min(tot, 2) + 1); return 0; }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; public class altthink { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); char a[]=sc.next().toCharArray(); int i,j,f=0,count=0; for(i=1;i<n;i++) { if(a[i]!=a[i-1] ) count++; else if(a[i]==a[i-1] && i!=n-1 ) f=1; else if(f!...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; char haha[100005]; int main() { int n; scanf("%d%s", &n, haha); int ans = 1; for (int i = 1; i < n; i++) ans += (haha[i - 1] != haha[i]); printf("%d\n", min(ans + 2, n)); return 0; }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n = input() s = raw_input() ans = 1 pre = s[0] for i in s[1:]: if i == pre: continue ans += 1 pre = i if '111' in s: ans += 2 elif '000' in s: ans += 2 else: i = 0 cnt = 0 while i + 1 < n and cnt < 2: if s[i] == s[i + 1]: ans += 1 i += 2 ...
PYTHON
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class ProblemC { public static void main(String[] args) { InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.ou...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; import java.io.*; public class Alternative_Thinking { public static void main(String args[]) throws Exception { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); int runs=Integer.parseInt(f.readLine()); int[] arr=new int[runs]; String in=f.readLine(); boolean[] used=...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n = map(int, input()) s = input() l = [] cnt = 1 for i in range( 1, len(s)): if s[i] != s[i-1]: l.append(cnt) cnt = 1 else: cnt += 1 l.append(cnt) result = len(l) add = 0 if max(l) >= 3: add = 2 elif max(l) >= 2: add = 1 if len(l) > 1: for i in range( 1, len(l)): if l[i] >= 2 and l[i-1] >= 2: add = 2 ...
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import sys n = int(sys.stdin.readline()) bitarr = sys.stdin.readline().strip() alt = 0 last = -1 nr = 0 for ele in bitarr: if last == -1: alt = 1 last = ele elif last == ele: nr += 1 elif last != ele: last = ele alt += 1 print alt + min(2, nr)
PYTHON
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n, f[maxn][2][3]; char s[maxn]; void chk(int &x, int y) { if (x < y) x = y; } int main() { scanf("%d %s", &n, s + 1); memset(f, -0x3f, sizeof(f)); f[0][0][0] = f[0][1][0] = 0; for (int i = 1; i <= n; i++) { for (int j : {0, 1}) ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long r; while (b != 0) { r = a % b; a = b; b = r; } return a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } const int mod = (int)1e9 + 7; const int INF = (int)1e9; const long long L...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int INF = 2000000000; const double EPS = 1e-6; void solve() { int n; cin >> n; string a; cin >> a; int ans(1); for (int i = (1); i < (int)(n); i++) { if (a[i] != a[i - 1]) ans++; } cout << min(ans + 2, n); } int main(...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.*; import java.util.*; public class Main { static InputReader in = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); static int MOD = 1000000007; static int M = 505; static int oo = (int)1e9; public static void main(String[] args) throws IOException { ...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int size, index, counter; cin >> size; string input; cin >> input; counter = 1; for (index = 1; index < size; index++) { if (input[index] != input[index - 1]) counter++; } if (counter + 2 < size) cout << counter + 2 << endl; else c...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class C { int n; String s; void readInput() throws NumberFormatException, IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //Scanner sc = new Scanne...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; char s[N]; int n; int dp[N], cur = 0, id = 0; int main() { scanf("%d", &n); scanf("%s", s); for (int i = 1; i < n; i++) { if (s[i] != s[i - 1]) { dp[id++] = cur + 1; cur = 0; } else cur++; } dp[id++] = cur + 1; ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int n; string s; bool usedflip = false; int main() { cin >> n >> s; bool cur = !(s[0] - '0'); int ans = 0; int pos = 0; for (int i = 0; i < s.length(); i++) { if (cur && s[i] == '0') { ans++; cur = false; } else if (!cur && s[i] == '1') { ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.io.ObjectInputStream....
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; string s; cin >> s; long long int res = 1; for (long long int i = 0; i < n - 1; i++) if (s[i] != s[i + 1]) res++; cout << min(n, res + 2) << endl; return 0; }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; vector<int> a; int ans = 0; int main() { string s; int n; scanf("%d", &(n)); ; cin >> s; int cur = s[0] - '0'; int cnt = 1; for (int(i) = (1); (i) < (n); (i)++) { int now = s[i] - '0'; if (now == cur) cnt++; else {...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int N, res = 1; string S; cin >> N >> S; for (int i = 1; i < N; i++) { res += (S[i] != S[i - 1]); } cout << min(res + 2, N) << '\n'; }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
//package java_practise.cf_practise; /** * Created by rahul on 13/6/16. */ import java.io.*; public class alternate { public static void main(String []arg)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n; String str; n=Integer...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt = 0, len; string s; cin >> n >> s; len = s.length() - 1; for (int i = 0; i < len; i++) if (s[i] != s[i + 1]) cnt++; if ((s.find("111") != -1) || (s.find("000") != -1)) cnt += 2; else if ((s.find("00110") != -1) || (s.find("01100...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int arr[100005], dp[100005][2]; int main() { ios::sync_with_stdio(0); int i, j, k, n; cin >> n; string s; cin >> s; for (i = 0; i < n; i++) { if (s[i] == '1') arr[i] = 1; } if (arr[0] == 0) dp[0][0] = 1; else dp[0][1] = 1; for (i = 1; i < n; ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int ans = 0; string s; int n; cin >> n >> s; for (int i = 0; i < n;) { if (s[i] == '0') { ++ans; ++i; while (i < n && s[i] == '0') ++i; } if (i < n && s[i] == '1') { ++ans; ++i; while (i < n && s[i] == '...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.lang.*; public class P604C { //static long mod=1000000007; static int LAS(char c[],int n) { int ans=1; for(int i=1;i<n;i++) { if(c[i]!=c[i-1]) ...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int N; char buf[100010]; int dp[100010][2][10]; int main(void) { int i, j, k; cin >> N; scanf("%s", buf); for ((i) = 0; (i) < (int)(N + 1); (i)++) for ((j) = 0; (j) < (int)(2); (j)++) for ((k) = 0; (k) < (int)(3); (k)++) dp[i][j][k] = -(1 << 29); dp[0][0...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { InputReader in = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int prime[]=new int[1000001]; prime[0]=1; prime[1]=1; for(int i=2;i*i<1000001;i++) if(prime[i...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; import java.math.*; import java.io.*; import java.text.DecimalFormat; public class Main{ static int mod=1000000007 ; public static void main(String[] args) throws IOException { s.init(System.in); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStream...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.Scanner; public class Main{ public static void main(String[]args){ Scanner ss=new Scanner(System.in); int n=ss.nextInt(),count=0; ss.nextLine(); String in=ss.nextLine(); ss.close(); char c=in.charAt(0); if(c=='0') c='1'; else c='0'; count++; for(int i=1;i<n;i++){ if(in.cha...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; ...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class C334D1AAltThi { static int N; static String S; static int[][] F; public static void main(String[] args){ // prln("Hello World!"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; char str[N]; int n; int main() { ios ::sync_with_stdio(); cin >> n >> str + 1; int a = 0, b = 1; for (int i = 1; i < n; ++i) if (str[i] != str[i + 1]) ++b; else ++a; printf("%d\n", b + min(2, a)); }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; ; template <class T> bool io(T &res) { static char c = ' '; while (c == ' ' || c == '\n') c = getchar_unlocked(); if (c == -1) return 0; res = ((c) - '0'); while ((c = getchar_unlocked()) && c != ' ' && c != '\n' && c != -1) { res = (res << 3) + (res << 1) + (...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0, er = 0, san = 0, min = 0; char str[100005] = "4"; scanf("%d", &n); getchar(); for (int i = 1; i <= n + 1; i++) { if (i < n + 1) scanf("%c", &str[i]); if (str[i] != str[i - 1]) { if (c == 2) er++; else if (c >=...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
def non_standard(s): result = 1 for i in range(1, len(s)): result += (s[i] != s[i - 1]) return min(result + 2, len(s)) m = int(input()) t = input() print(non_standard(t))
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class Solution { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); String input = in.re...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
// package Dynamic; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class AlternativeThinking { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parse...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; import java.io.*; import java.math.*; public class Class{ public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, res = 1, cnt = 0; cin >> n; string s; cin >> s; for (int i = 0; i < n - 1; i++) { if (s[i] != s[i + 1]) res++; } for (int i = 0; i < n - 1; i++) { if (s[i] == s[i + 1]) cnt++; } cout << res + min(cnt, 2); return 0; }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int n; char bstr[MAXN]; int pretail[MAXN]; int suftail[MAXN]; int pre[MAXN]; int suf[MAXN]; int main() { scanf("%d\n", &n); scanf("%s", bstr); int cnt = 0; for (int ii = 0; ii < n; ii++) { if (bstr[ii] != bstr[ii + 1]) cnt++; } cou...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int inf = 1e9 + 7; void solve() { long long int n; cin >> n; string s; cin >> s; vector<vector<long long int> > left(n, vector<long long int>(2, 0)), right(n, vector<long long int>(2, 0)); left[0][s[0] - '0'] = 1; r...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n = int(input()) s = input().strip() count = 1 for i in range(1, n): if s[i - 1] != s[i]: count += 1 count = min(count + 2, n) print(count)
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; long long power(long long b, long long e, long long m) { if (e == 0) return 1; if (e & 1) return b * power(b * b % m, e / 2, m) % m; return power(b * b % m, e / 2, m); } long long power(long long b, long long e) { if (e == 0) return 1; if (e & 1) return b * power(...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; void solve() { long long n, ans = 1; string s; cin >> n >> s; for (long long i = 1; i < n; i++) { if (s[i] != s[i - 1]) ans++; } cout << min(n, ans + 2) << "\n"; } int32_t main() { { ios_base::sync_with_stdio(false); cin.tie(NULL); } long long ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; int ans = 1; for (int i = 1; i < n; i++) { if (s[i] != s[i - 1]) ans++; } cout << min(n, ans + 2); return 0; }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> using lim = numeric_limits<T>; int make(string s, char start) { int ans = 0; int changed = 0; while (not s.empty()) { if (s.back() != start and changed < 2) { start = not(start - '0') + '0'; changed++; } ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; import java.lang.*; import java.io.*; public class Main {static int sum=0; static char a[]=new char[5000]; static int n=0;static int a1;static int b; public static void main (String[] args) { Scanner s=new Scanner(System.in); n=s.nextInt(); a=new char[n]; s.nextLine(); a=s.n...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class third { public static void main( String[] args ) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s; s = br.readLine(); ...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; public class Solution { public static void main(String []args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); String s = sc.nextLine(); int zeros = 0, ones = 0; for(int i = 0 ; i < n - 1 ; i++) { ...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
//package okey; import java.util.Scanner; public class force344C { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); String s = scan.next(); int prev = 0; int size = 1; int now = 1-s.charAt(0)+'0'; int sum = 0; for(int i = 1;i<s.length();i++){ ...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 123; int N, ar[MAXN], dn[MAXN][2][2][2]; char s[MAXN]; int dfs(int w, int ever, int pre, int lt) { int &ret = dn[w][ever][pre][lt]; if (w == N + 1) return 0; if (ret != -1) return ret; if (ever && !pre) return ret = dfs(w + 1, ever, pre, (...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.*; import java.util.*; public class Codeforces { public static final long MOD = 1_000_000_007; public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); Pr...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, i, ans = 1; scanf("%d", &n); string s; cin >> s; for (i = 1; i < n; i++) { if (s[i] != s[i - 1]) { ans++; } } ans = min(ans + 2, n); printf("%d", ans); }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
from sys import stdin,stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) for _ in range(1):#nmbr()): n=nmbr() a=[int(ch) for ch in input()] n=len(a) dp=[[[0 for _ in range(2)]for _ in range(3)]for _ in range(n)] dp[0][0][a[0]]=1 dp[0][0][1^a[0]]=0 ...
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; inline int solve(string a) { if (a.length() < 4) return a.length(); int f2 = 0, f3 = 0; for (int i = 2; i < a.length(); i += 1) { if (a[i] == a[i - 1] and a[i - 1] == a[i - 2]) { f3 = 1; } else if (a[i] == a[i - 1]) { f2 += 1; } else { } ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string st; cin >> st; int count = 1; for (int i = 1; i < n; i++) { if (st[i] != st[i - 1]) { count++; } } cout << min(count + 2, n) << endl; return 0; }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> char s[100010]; int n, bf, T; int main() { scanf("%d", &n); scanf("%s", s + 1); char last = s[1]; int cnt = 1, m = 1; for (int i = 2; i <= n; i++) { if (s[i] == last) cnt++; else { m++; if (cnt > 2) bf = 1; else if (cnt == 2) T++; ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.io.Writer; impo...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000") long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long lcm(long long a, long long b) { return (1ll * (a / gcd(a, b)) * b); } long long phi(long long n) { long long result = n; for (long l...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; vector<string> vs; int main() { long long len, i; string s, st; char sem; cin >> len; cin >> s; sem = s[0]; st = s[0]; for (i = 1; i < len; ++i) { if (sem == '0') { if (s[i] == '1') { st += s[i]; sem = s[i]; } else { v...
CPP