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
n = int(input()) s = input() print(min(n,s.count("01")+s.count("10")+3))
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; int main() { int n; cin >> n; string s; cin >> s; int c = s[0] - '0'; int ans = 1; int flag = 0; for (int i = 1; i < n; i++) { if (c != s[i] - '0') { c = !c; ans++; } } if (n == ans) { cout << n << endl; return 0; } 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 a; cin >> a; string s; cin >> s; int dp[a]; int count = 1; int toy = 0; dp[0] = 1; map<int, int> m; for (int x = 1; x < a; x++) { if (s[x] != s[x - 1]) { dp[x] = dp[x - 1] + 1; } else { dp[x] = dp[x - 1]; count+...
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, x, y; string s; int main() { cin >> n >> s; for (int i = 1; i < n; ++i) { x += s[i] != s[i - 1]; y += s[i] == s[i - 1]; } cout << min(x + 3, 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
import java.util.Scanner; public class AlternativeThinking { public static void main(String asd[])throws Exception { Scanner in=new Scanner(System.in); int n=Integer.parseInt(in.nextLine()); String s=in.nextLine(); int r=1; for(int i=1;i<n;i++) { if(...
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; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; string s; cin >> s; long long res = 1; for (long long 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
n=int(input()) s=input() c=1 seg=[] for i in range(1,n): if s[i]==s[i-1]: c+=1 else: seg.append(c) c=1 seg.append(c) f=0 for i in range(len(seg)): if seg[i]>=3: f=max(f,2) if seg[0]==1 and seg[len(seg)-1]==2 or seg[0]==2 and seg[len(seg)-1]==1: f=max(1,f) if seg[0]==seg[l...
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; public class AlternativeThinking { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(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
#include <bits/stdc++.h> using namespace std; const int N = int(3e5); int n; char second[N]; int a[N]; int b[N], c[N], d[N]; int q[N], p[N]; int sol(int i) { int res = 0; if (second[i] == '1') { res += a[i - 1]; int j = i + p[i]; res += p[i]; if (second[j] == '1') res += c[j]; else 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
#include <bits/stdc++.h> using namespace std; int n; string s; int dp[100010]; int cnt; int main() { cin >> n; cin >> s; s = ' ' + s; dp[0] = 0; for (int i = 1; i <= n; i++) if (s[i] != s[i - 1]) dp[i] = dp[i - 1] + 1; else dp[i] = dp[i - 1]; cnt = 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; struct mon { long long a, b; }; long long min3(long long a, long long b, long long c) { vector<long long> d = {a, b, c}; sort(d.begin(), d.end()); return d[0]; } long long clip(long long a, long long b) { if (a > b) return a; else return b; } long long 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; cin >> n; string s; cin >> s; int p = s.length(); int a = s[0] - 48; int ctr = 1; int maxum = 0; int ct = 1; int l = 0; for (int i = 1; i < n; i++) { if (s[i] - 48 == 1 - a) { maxum = max(maxum, ct); if (ct == 2) 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
import java.util.Scanner; public class AlternativeThinking { private static int maxAlternative(String s) { int result = 1; if (s.length() <= 1) { return s.length(); } char lastCharacter = s.charAt(0); for (int i = 1; i < s.length(); ++i) { if (s.ch...
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> const long long MOD = 1000 * 1000 * 1000 + 7; const long long MOD1 = 998244353; const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; using namespace std; long long power(unsigned long long x, unsigned long long y) { unsigned long long res = 1; while (y > 0) { if (y &...
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()) seq = input() prev = -1 ans = 0 for e in seq: if e != prev: ans += 1 prev = e print(min(n, ans + 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
n = input() ars = raw_input() ar = list(ars) cnt = 1 now = ar[0] for i in xrange(1,n): if ar[i]!=now: now = ar[i] cnt += 1 cnt += 2 if cnt>n: print n else: print cnt
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 N = 1e5 + 5; int n; char s[N]; void solve() { int l = 1; bool last = s[0] == '1'; for (int i = 1; i < n; ++i) { bool t = s[i] == '1'; if (t == !last) { last ^= true; l++; } } bool find = false; last = s[0] == '1'; for (int 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
n=int(input()) a=list(input()) start=0 end=0 if(n==1): print(1) exit(0) for i in range(n-1): if(a[i]==a[i+1]): break if(i==n-2): print(n) exit(0) else: ans=0 for i in range(n-1): if(a[i]!=a[i+1]): ans+=1 #print(ans) print(min(n,ans+3))
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() { int i, j, k = 1, l; int n; char s[100005]; scanf("%d", &n); scanf("%s", s); if (n == 1) printf("1"); else if (n == 2) printf("2"); else { for (i = 0; i < n - 1; i++) { if (s[i] != s[i + 1]) k++; } if (k + 2 < n) printf("%d", k + 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 b[100005], pos; char a; int main() { int n, flag = 0, cnt = 1, f = 0, c = 0; scanf("%d", &n); getchar(); char t; scanf("%c\n", &t); if (n == 1) { printf("1\n"); return 0; } for (int i = 0; i < n; i++) { scanf("%c", &a); if (a != 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
#include <bits/stdc++.h> using namespace std; string s; int n, ans; int main() { cin >> n >> s; for (int i = 1; i < s.size(); ++i) if (s[i] != s[i - 1]) ++ans; cout << min(ans + 3, 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class AlternativeThinking { public static void main(String[] args) { InReader sc = new InReader(System.in); int n = sc.nextInt(); String olymp = sc.next(); ...
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 = raw_input() s = raw_input().split()[0] a = [] num = 1 for i in xrange(1,len(s)): if s[i] == s[i-1]: num += 1 else: a.append(num) num = 1 a.append(num) add = 0 sum2 = 0 for i in xrange(len(a)): if a[i] == 2: add = 1 sum2 += 1 if sum2 >= 2: add = 2 for i in ...
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> int main() { std::ios::sync_with_stdio(false); int n, res = 3; std::cin >> n; char ch[100005]; std::cin >> ch; for (size_t i = 1; i != n; ++i) { res += (ch[i] != ch[i - 1]); } res = res > n ? n : res; std::cout << res << std::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; vector<int> v; int main() { int n, zz = 0, oo = 0; string s; cin >> n >> s; int cnt = 1, c = 0; bool b = 0; for (int i = 1; i < n; i++) { if (s[i] == s[i - 1]) { cnt++; if (s[i] == '1') { oo++; } else { zz++; } } e...
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; char x; cin >> n; char prev = 'x'; int scorea = 0, scoreb = 0; int c = 1; cin >> prev; char f; for (int i = 1; i < n; i++) { cin >> x; if (abs(x - prev) == 1) { c++; } if (x - prev == 0 && prev == '0' && scorea < 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
n = int(raw_input()) s = raw_input() two = 0 num = 1 count = 0 last = None for c in s: if last is not None: if c == last: count += 1 two += 1 else: count = 0 num += 1 last = c # print num if two == 0: print num elif two == 1: print num +...
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; int main() { int n, sum = 1; string s; cin >> n >> s; char last = s[0]; for (int i = 1; i < n; i++) { if (last != s[i]) { sum++; last = s[i]; } } if (sum >= n - 1) cout << n << endl; else cout << sum + 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 LEN = 1e5 + 10; int a[LEN]; int main() { int n; string s; scanf("%d", &n); cin >> s; for (int i = 0; i < n; ++i) { if (s[i] == '0') a[i] = 0; else a[i] = 1; } int cnt = 1, ans = 1, n2 = 0; bool f2 = 0, f3 = 0, p2 = 0; for (int...
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.io.*; public class A { public static void main(String ar[]) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); char c[]=br.readLine().toCharArray(); ...
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=int(input()) s=input() a,j=0,0 for i in range(len(s)): if j%2 and s[i]=="1": a+=1 j+=1 elif j%2==0 and s[i]=="0": a+=1 j+=1 b,j=0,0 for i in range(len(s)): if j%2 and s[i]=="0": b+=1 j+=1 elif j%2==0 and s[i]=="1": b+=1 j+=1 count=max...
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 Task { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String next = in.next(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(String.val...
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 = int(input()) s = input() res = 1 for i in range(0, n - 1): if s[i] != s[i + 1]: res += 1 print(min(res + 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
#include <bits/stdc++.h> using namespace std; char a[100005]; int b[100005] = {0}; int main() { int n, ans = 0, t = 0; scanf("%d", &n); scanf("%s", a); ans = 1; for (int i = 1; i < n; i++) { if (a[i] != a[i - 1]) { ans++; } } if (ans + 2 < n) ans += 2; else ans = n; printf("%d\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; const int IINF = INT_MAX; int n; string s; inline char rev(char c) { return (c == '0') ? '1' : '0'; } void compute() { vector<int> seq; for (int i = 0; i < (int)s.size(); i++) { int cnt = 0; char c = s[i]; int sp = i; while (i < (int)s.size() && 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
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long long maxn = 1e5 + 10, inf = 4e18, mod = 1e9 + 7; const long double pi = 3.14159265359, eps = 1e-9; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, tn = 0; cin >> n; string s; cin >> 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
import java.util.Scanner; public class Codeforces603A_Alternative_Thinking { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); String s = scanner.next(); int count = 1; for (int i = 1; i < n; i++) { if(...
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=int(raw_input()) seq=(raw_input()) currfreq=1 maxfreq=1 lastchar=seq[0] for i in range(1,n): if seq[i] == lastchar: currfreq+=1 else: currfreq=1 lastchar=seq[i] if maxfreq<currfreq: maxfreq=currfreq if maxfreq<currfreq: maxfreq=currfreq alternating=1 lastchar=seq[0] for i in range(1,n): if seq[i]!=lastch...
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; int f[200500][10][10], n, a[200500], ans; char s[200500]; long long read() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); ...
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 dp[1000000][4]; int main() { long long n, i; string s; cin >> n; cin >> s; dp[0][0] = 1; dp[0][1] = 1; dp[0][2] = 1; for (i = 1; i < n; i++) { dp[i][0] = dp[i - 1][0] + (s[i] != s[i - 1]); dp[i][1] = max(dp[i - 1][0] + (s[i] == 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.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; import java.math.BigInteger; import java.uti...
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 readInt() { bool minus = false; long long result = 0; char ch; ch = getchar(); while (true) { if (ch == '-') break; if (ch >= '0' && ch <= '9') break; ch = getchar(); } if (ch == '-') minus = true; else result = ch - '0'; whil...
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.math.*; public class A implements Runnable { private static BufferedReader in; private static PrintWriter out; private static StringTokenizer st; private static Random rnd; private void solve() throws IOException { int stringLength = nextInt(); String letters...
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; import java.io.PrintWriter; import java.util.*; public class C { BufferedReader reader; StringTokenizer tokenizer; PrintWriter out; public void solve() throws IOException { int N = nextInt(); char[] S ...
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 lf[100005], rt[100005], rsp, alf[100005], art[100005]; int main() { int n, i, cnt, cnt2; string s; scanf("%d", &n); cin >> s; rsp = 0; cnt = 0; cnt2 = 0; for (i = 0; i < n; i++) { if (i && s[i] == s[i - 1]) cnt2 = 1; else cnt2++; ...
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
/* Author LAVLESH */ import java.util.*; import java.io.*; public class solution{ static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st=new StringTokenizer(""); static public String next() { while (st == null || !st.hasMoreTokens()) { try ...
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 l, x, res; scanf("%d", &l); ; string s; cin >> s; for (x = 1; x < l; x++) res += (s[x] != s[x - 1]); printf("%d", min(res + 2, 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
n = int(raw_input()) seq = map(lambda x : True if x == "1" else False, list(raw_input().strip())) res = [[-1] * n for i in [0,1,2]] res[0][0] = res[1][0] = res[2][0] = 1 for i in range(1, n): res[0][i] = res[0][i - 1] + (seq[i - 1] != seq[i]) res[1][i] = max(res[0][i - 1] + (seq[i - 1] == seq[i]), ...
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
n,s=int(input()),input() print(min(n,s.count('01')+s.count('10')+3))
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()) consec= 1 changes = 0 oppo = 0 rep = False cons = False s = input().strip() prev = s[0] for x in s[1:]: if prev != x: changes += 1 consec = 1 rep = False else: consec += 1 if not rep: rep = True oppo += 1 if consec == 3: ...
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; int main() { int n; string s; cin >> n >> s; vector<int> arr(n); int zero = 0, one = 0; for (int i = n - 1; i > -1; i--) { if (s[i] == '0') { arr[i] = one + 1; zero = arr[i]; } else { arr[i] = zero + 1; one = arr[i]; } } 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
n = input() s = raw_input() ans = [1]*n prev1, prev0 = -1, -1 for i in range(n): if s[i] == '0': prev0 = i if prev1 == -1: ans[i] = 1 else: ans[i] = ans[prev1] + 1 else: prev1 = i if prev0 == -1: ans[i] = 1 else: ans...
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.util.*; public class C { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); char[] str = s.next().toCharArray(); for(int i=1; i<str.length; i++) { if(str[i] == str[i-1]) { do { str[i] = (str[i]=='1'?'0':'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 int N = 142123; const int md = 1e9 + 7; char ch; int n, s[N][2], a[N], d[N][2], ans; int f[N][2]; void g(int first) { ans = max(ans, first); } int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> ch, a[i] = ch - '0'; for (int i = 1; i <= n; ++i) { d[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 sys input = sys.stdin.readline n = int(input()) S = input()[:-1] zero, one = 0, 0 for Si in S: if Si=='0': zero = one+1 else: one = zero+1 ans = max(zero, one) s = set() for i in range(n-1): if S[i]==S[i+1]: s.add(i) if len(s)>=2: ans += 2 elif len(s)==1: ans ...
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; const int N = 2e5 + 7; const int mod = 1e9 + 7; int n, a[N], d[N][2][2][2], u[N][2][2][2]; int calc(int p, int v, int k1, int k2) { if (p == n) return 0; if (u[p][v][k1][k2]) return d[p][v][k1][k2]; u[p][v][k1][k2] = 1; int res = INT_MIN; if (k1 == 0 && k2 == 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 cc; void read(int &x) { cc = getchar(); for (; cc < '0' || cc > '9'; cc = getchar()) ; for (x = 0; cc >= '0' && cc <= '9'; cc = getchar()) x = x * 10 + cc - '0'; } int n; char s[111111]; int main() { scanf("%d", &n); scanf(" "); gets(s + 1); int cnt =...
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.Scanner; public class AlternativeThinking { public static void main(String[] args){ // System.out.println("input something"); Scanner kb = new Scanner(System.in); int n = kb.nextInt(); String a = kb.next(); int m10,m11,m20,m21,m30,m31,ans; m10=m11=m20...
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.*; // This is easier than it looks. Just count the number of alternates and add 2, because we can always flip so we get two more alternating bits. public class CF604C { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(Sy...
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 A[100005]; int cnt[100005] = {0}; int main() { char ch; int n, maxm = 0, i, j = 0, k = 0; cin >> n; getchar(); cin >> ch; A[0] = ch - '0'; cnt[0] = 1; for (i = 1; i < n; ++i) { cin >> ch; if (ch - '0' == A[j]) cnt[j]++; else { 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
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 main() { int ar[100000], ar1[100000]; char s; long long n, i, m; cin >> n; for (i = 0; i < n; i++) { cin >> s; if (s == '0') ar[i] = 0; else ar[i] = 1; } ar1[0] = 1; for (i = 1; i < n; i++) { ar1[i] = (ar1[i - 1] + abs(ar[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; const int MAXN = 100010; char s[MAXN]; int main() { int n; scanf("%d%s", &n, s); int ans = 1, ins = 0; for (int i = 1; i < n; i++) { if (s[i] != s[i - 1]) ans++; else ins++; } printf("%d\n", ans + min(ins, 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; int main() { ios::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; vector<int> seq(n, 0); transform(s.begin(), s.end(), seq.begin(), [](const char& c) { return int(c - '0'); }); int score = 0; int cur = -1; int count = 0; bool p...
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 A { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String s = in.next(); int res = 1; for (int i = 1; i < s.length(); i++) { if (s.charAt(i-1) != s.charAt(i)) { res++; } } System.out.println(Math.min(res + 2, 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.*; import java.util.*; import java.math.*; public class Div2_334_C_DP { static final int MIN = 0; public static void main(String[] args) throws IOException { BufferedInputStream bis = new BufferedInputStream(System.in); BufferedReader br = new BufferedReader(new InputStreamReader...
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 javax.print.DocFlavor; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.nio.file.Paths; import java.util.*; public class Main extends PrintWriter { static BufferedReader s = 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
import java.io.*; import java.util.*; public class Template implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException { try { in = new BufferedReader(new FileReader("input.txt")); o...
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> int main() { int n, ans = 1, gas = 0; char s[100100]; scanf("%d %s", &n, s); for (int i = 1; i < n; i++) { if (s[i] != s[i - 1]) ans++; else gas++; } if (gas >= 2) ans += 2; else ans += gas; printf("%d\n", ans); 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[100007]; int main() { int n, i, j; while (scanf("%d", &n) != EOF) { scanf("%s", s); int cnt1 = 0; int cnt = 0; int maxx = 0; for (i = 0; i < n; i++) { if (i == 0 || s[i] == s[i - 1]) cnt1++; else maxx += cnt1 - 1, cnt++, cnt1 = 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
n = input() s = raw_input() ans = 1 for i in xrange(1,n): if(s[i]!=s[i-1]): ans +=1 print min(n,ans+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
from math import * from collections import * from random import * from decimal import Decimal from bisect import * import sys #input=sys.stdin.readline def lis(): return list(map(int,input().split())) def ma(): return map(int,input().split()) def inp(): return int(input()) def st(): return input().rstri...
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; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...
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> const int dx[] = {0, -1, 0, 1, 1, 1, -1, -1}; const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; const int OO = 0x3f3f3f3f, N = 1000000 + 5, mod = 1e8; using namespace std; void run() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int dp[100005][2][3]; string s; int n; int sol...
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; string v; int main() { int n; cin >> n; cin >> v; for (int i = 0; i < n; i++) cin >> v[i]; int c = 0; int d = 1; for (int i = 1; i < n; i++) { c += v[i] == v[i - 1]; d += v[i] != v[i - 1]; } cout << d + min(2, c) << endl; }
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; string v; int dp[2][3][100010], n; int main() { ios::sync_with_stdio(false); while (cin >> n >> v) { for (int a = (0); a < (2); a++) for (int j = (0); j < (3); j++) dp[a][j][n] = 0; for (int i = n - 1; i >= 0; i--) { for (int j = (0); j < (3); j++) {...
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 INF = 4000000000000000000LL; int main() { int n; scanf("%d", &n); string s; cin >> s; vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(3, vector<int>(2))); for (int i = 0; i <= 2; i++) { dp[0][i][0] = dp[0][i][1] = 0; } for (int ...
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() b=raw_input() if n <= 3: print n else: ans = 0 has_2 = 0 has_3 = 0 for i in range(0,n): if i == 0: ans += 1 last = b[i] else: if b[i] != last: last = b[i] ans += 1 if not has_2 and i>0 and b[i] == b...
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; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t, n; string s; t = 1; while (t--) { cin >> n >> s; long long int ans = 0; for (int i = 0; i < s.length(); i++) { if (s[i] != s[i + 1]) { 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
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt = 1; string s; cin >> n >> s; for (int i = 0; i < n - 1; i++) { if (s[i] != s[i + 1]) { cnt++; } } cout << min(cnt + 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
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n; char s[maxn]; int dp[maxn][3]; int main() { int zero, one; int n; scanf("%d", &n); scanf("%s", s + 1); zero = 0; one = 0; dp[0][0] = 0; dp[0][1] = -n - 10; dp[0][2] = -n - 10; int ans = 0; for (int i = 1; i <= n; 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 main() { int n; cin >> n; string s; cin >> s; int res = 0; int cnt = 0; for (int i = 1; i < n; ++i) { if (s[i] != s[i - 1]) res++; else cnt++; } res++; if (cnt >= 2) res += 2; else if (cnt == 1) res += 1; cout << res; ...
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; string s; int n; int pd[100010][2][3]; int solve(int pos, int last, int flag) { if (pos >= n) return 0; if (pd[pos][last][flag] != -1) return pd[pos][last][flag]; int cur = s[pos] - '0'; if (flag == 1) cur = 1 - cur; pd[pos][last][flag] = solve(pos + 1, last, flag...
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:64000000") using namespace std; int n; string s; int a[100010]; int calc(int st) { int res = 0; for (int i = 0; i < n; i++) { if (a[i] == st) { res++; st ^= 1; } } return res; } int trivia() { pair<int, int> p; int res = 0; for (...
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 mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string str; cin >> str; int ans = 1; for (int i = 0; i < n - 1; i++) { if (str[i] != str[i + 1]) { ans++; } } cout << min(ans + 2, 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; constexpr int INF = 2e9; int dp[100010][3][2]; int main() { int n; string s; cin >> n >> s; for (int i = 0; i < n; i++) { int d = s[i] - '0'; for (int j = 0; j < 3; j++) { int next = (j != 1 ? d : d ^ 1); int now = (j != 1 ? d ^ 1 : d); dp[...
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, cnt = 1; cin >> n; string s; cin >> s; for (int i = 1; i < n; i++) { if (s[i] != s[i - 1]) { cnt++; } } cout << min(cnt + 2, 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; const int64_t mod = 1000000007; int64_t A[2001]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int64_t n, ans = 1; string str; cin >> n >> str; for (int64_t i = 1; i < n; i++) ans += (str[i] != str[i - 1]); cout << min(ans + 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
n = int(raw_input()) s = raw_input() o = [] k = s[0] for i in s[1:]: if i==k[0]: k+=i else: o.append(len(k)) k=i o.append(len(k)) ans = len(o) if max(o)>=3: ans+=2 elif o.count(2)>=2: ans+=2 elif o.count(2)==1: ans+=1 print(ans)
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; int main() { int n; cin >> n; string s; cin >> s; int ans = 1; char c = s[0]; for (int i = 1; i < n; i++) { if (s[i] != c) { ans++; c = s[i]; } } int x = 0; for (int i = 0; i < n; i++) { if (s[i] == s[i + 1]) { x++; } ...
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.math.*; public class cb { InputStream is; PrintWriter out; static int mod=(int)(1e9+7); public static int raina(char ch[],int n) { char last=ch[0];int ctr=0; for(int i=1;i<n;i++) { if(ch[i]!=last){ ctr++; last=ch[i]; } } return ct...
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 sys input_file = sys.stdin #input_file = open("in.txt") input_file.readline() bits = list(input_file.readline().rstrip()) num_alt = 1 last_char = bits[0] if len(bits)<=3: print(len(bits)) exit() for i, char in enumerate(bits): if bits[i] != last_char: last_char = bits[i] num_alt+=1 if num_alt...
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; int main() { int n, i, r = 0, j, f = 0, g = 0; scanf("%d", &n); char c[100010]; scanf("%s", c); for (i = 0; i < n;) { r++; char v = c[i]; j = i; while (i < n && c[i] == v) ++i; if (i - j >= 3) g = 2; else if (g < 2 && i - j == 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; const int maxn = 1e5 + 5; int dp[maxn][3][2]; int main() { int n; cin >> n; string s; cin >> s; int x = s[0] - '0'; dp[0][2][x] = dp[0][1][x] = dp[0][0][x] = 1; dp[0][2][x ^ 1] = dp[0][1][x ^ 1] = dp[0][0][x ^ 1] = 0; for (int i = 1; i < n; i++) { x = 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
import java.io.*; public class kevin { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); int arr[]=new int[n+1]; String s[]=br.readLine().trim().split(""); ...
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; import java.io.Reader; import java.util.BitSet; import java.util.StringTokenizer; public class C { public static void main(String[] args) { // Scanner sc = new Scanner(System.in); FastScanner sc = new FastSc...
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 round334; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class A { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(); 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
#include <bits/stdc++.h> using namespace std; int n, m, k; int dp[100010][3][2]; string s; int main() { scanf("%d", &n); cin >> s; int ans = 0; for (int i = 0; i < n; i++) { int k = s[i] - '0'; dp[i + 1][2][k] = max(dp[i][2][k], max(dp[i][2][k ^ 1] + 1, dp[i][1][k ^ 1] + 1)); dp[i + 1][1][k ...
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 str[100010]; int n, dp[100010][3][3]; bool visited[100010][3][3]; int F(int i, int l, int flag) { if (i == n) return 0; if (visited[i][l][flag]) return dp[i][l][flag]; int r, res = 0, x = str[i] - 48; if (flag == 0) { res = ((res) > (F(i, l, 1)) ? (res) : (F(i, l, 1))); res...
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