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
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { static int solve(int idx,int flip,int stop,String s,char prev,int dp[][][][]){ if(idx==s.len...
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; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") bool prime[100005]; void Sieve(long long int n) { memset(prime, true, sizeof(prime)); for (long long int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (long long int i = p * p; 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; char s[100005]; int main() { int a = 0, b = 0, n; scanf("%d", &n); scanf("%s", s); for (int i = 0; i < n; i++) { if (s[i] == '1') a = max(a, b + 1); else b = max(b, a + 1); } printf("%d\n", min(n, max(a, b) + 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 MN = 100005, inf = 1000000005, mod = 1000000007; const long long INF = 1000000000000000005LL; int dp[MN][2][3]; char opis[MN]; int main() { int n; scanf("%d", &n); scanf("%s", opis); for (int i = 1; i <= n; ++i) { int cur = opis[i - 1] - '0'; dp[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 argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int n; cin >> n; string s; cin >> s; vector<vector<int>> dp(n, vector<int>(2)); dp[0][(s[0] - '0') % 2] = 1; for (int i = 1; i < n; i++) { dp[i][(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.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
import java.util.Scanner; public class something { public static void main(String[]args) { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); String a=scan.next(); int smae=0,diff=0; for(int i=1;i<n;i++) { if(a.charAt(i)==a.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 int oo = 0x3f3f3f3f; long long fastpower(long long b, long long p) { long long ans = 1; while (p) { if (p % 2) { ans = (ans * b); } b = (b * b); p /= 2; } return ans; } string makeitstring(long long n) { string ans; while (n) { lo...
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 Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); boolean[] str = new boolean[n]; String string = s.next(); for (int i = 0; i < n; i++) { char c = string.charAt(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.io.File; import java.util.Scanner; import java.util.StringTokenizer; public class p008 { public static void main(String args[]) throws Exception { StringTokenizer stok = new StringTokenizer(new Scanner(System.in).useDelimiter("\\A").next()); StringBuilder sb = new StringBuilder(); int n = Integer.pa...
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.*; /** * * @author sarthak */ public class rnd334_C { static int[] a; public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); s.nextLine(); String ip=s.nextLine(); a = new 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class C { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new Print...
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; while (scanf("%d", &n) != EOF) { string s; cin >> s; int res1 = 1; for (int i = 1; i < s.size(); i++) { if (s[i] != s[i - 1]) res1++; } int res2 = 1; int r = 1; for (int i = 1; i < s.size(); i++) { if (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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.stream.IntStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Writer; import java.io.Outpu...
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.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
n = int(input()) A = list(map(int, ' '.join(input()).split())) res = 1 for i in range(1, len(A)): if A[i] != A[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 ll = long long; using ld = long double; using ull = unsigned long long; using namespace std; const int Sz = 1e5 + 3; const ll MOD = 1e9 + 7; const int oo = 1e9; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; int n; cin >> n; cin >> s; int ans = 3; 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
#! /bin/python n = int(input()) tab = str(input()) d = 1 tmp = 1 changes = 1 for i in range(1, n): if tab[i] != tab[i - 1]: changes += 1 print(min(changes + 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> int max(int a, int b) { return a > b ? a : b; } char s[101000]; int a[101000], g[101000][2], f[101000][2], F[101000][2]; int main() { int n; scanf("%d", &n); scanf("%s", s); for (int i = 0; i < n; i++) a[i] = s[i] - '0'; g[0][1 - a[0]] = 1; f[0][0] = 1; f[0][1] = 1; F[0][a[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 Calcul(string s) { char e; int r = 1; e = s[0]; for (int i = 1; i < s.size(); i++) { if (e != s[i]) { r++; } e = s[i]; } return r; } int main() { int n, a; cin >> n; string s; cin >> s; if (n == 1) { cout << 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
n = int(input()) s = input() li = [s[0]] for i in range(1, n): if s[i] != li[-1]: li.append(s[i]) print(min(n, len(li) + 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
#include <bits/stdc++.h> using namespace std; int n, a = 1; char t, l; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); scanf("%d", &n); scanf("%c", &t); scanf("%c", &l); for (int i = 1; i < n; i++) { scanf("%c", &t); a += (t != l); l = t; } printf("%d", min(a + 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() s+='*' count=0 for i in range(0,n): if(s[i]!=s[i+1]): count+=1 #print count if(("000" in s) or ("111" in s) or ("1100" in s) or ("0011" in s)): count+=2 elif(s.count("11")>1 or s.count("00")>1): count+=2 elif(s=="1101" or s=="0010" or s=="1011" or s=="0100"): count+=1 eli...
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, ans = 1; string s; cin >> n >> s; for (int i = 1; i < n; i++) if (s[i] != s[i - 1]) ans++; cout << min(n, 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
#include <bits/stdc++.h> using namespace std; inline int read() { int s = 0, t = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') t = -1; c = getchar(); } while (isdigit(c)) s = s * 10 + c - 48, c = getchar(); return s * t; } const int N = 1e5 + 5; int n, now, pre, c1, c2, c3, ans, f; char...
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() res = 1 for i in range(n-1): if s[i] != s[i+1]: res += 1 if res == n: print(res) elif res == n-1: print(res+1) else: print(res + 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 java.awt.*; import java.io.*; import java.math.BigInteger; import java.util.*; public class Abc { public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); int n=sc.nextInt(); String s=sc.next(); int zero=0;int one=0; int max=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 main() { int n, L = 0, R = 0; string s; cin >> n >> s; for (int i = 0; i < n; i++) (s[i] != s[i - 1]) ? ++L : ++R; cout << L + min(2, 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(raw_input()) s = raw_input() length = len(s) cnt = 0 for i in range(0 , length - 1): if(s[i] == s[i+1]): cnt += 1 print min(n , n - cnt + 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.*; import java.lang.reflect.Array; import java.util.*; public class icpc { public static void main(String[] args) throws IOException { // Reader in = new Reader(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.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
n=input() r=map(int,list(raw_input())) dp0=0 dp1=0 for i in r: if i: dp1=dp0+1 else: dp0=dp1+1 ans=max(dp0,dp1) 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
n = int(raw_input()) s = raw_input().strip() p = '.' k = c = 0 for x in s: k += p != x c += p == x p = x if c > 2: c = 2 print k + c
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.*; import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.math.MathContext; import java.text.DecimalFormat; import java.text.Format; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.util.Collections.*; import java.awt.List; p...
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; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; string s; cin >> s; char prev = s[0]; long long cnt = 1; for (long long i = 1; i < n; i++) { if (s[i] != prev) { cnt++; } prev = 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.*; public class test1 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String res=sc.next(); int score=1,c=0,k=0; for(int i=0;i<n-1;i++){ if(res.charAt(i)!=res.charAt(i+1)){ score++; if(c>=2){ score+=2; c=0; k++; }...
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 = 100005; const long long MOD = 1e9 + 7; const double eps = 1e-9; int n; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; cin >> s; int ans = 0; for (int i = 1; i < n; i++) ans += (s[i] != s[i - 1]); cout << min(n, 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
import sys #FUCK n = int(input()) s = input() p = s[0] ans = 1 for i in range(1,n): if s[i] != p: ans += 1 p = s[i] if (0 <= s.find("00") < s.rfind("00")) or (0 <= s.find("11") < s.rfind("11")) or (0 <= s.find("11") < s.rfind("00")) or (0 <= s.find("00") < s.rfind("11")): ans += 2 elif s.fin...
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 com.sun.org.apache.xpath.internal.operations.String; import java.io.*; import java.util.*; public class scratch_25 { //static long count=0; static class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** * call this method to initialize rea...
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; using ll = long long; int solve() { int n, altern{0}, consec{0}; cin >> n; string votes; cin >> votes; for (int i = 0; i < n - 1; ++i) { if (votes[i] != votes[i + 1]) ++altern; else ++consec; } return 1 + altern + min(consec, 2); } 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
#include <bits/stdc++.h> using namespace std; int n; string s; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> s; int ans = 1, boz = 0, now = 1, cnt = 0; for (int i = 1; i < s.length(); i++) if (s[i] != s[i - 1]) ans++, boz = max(boz, now), now = 1; else 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> #pragma GCC optimize("O3") using namespace std; string s = ""; long long arr[1000005] = {0}; long long solve(string st) { long long sz = st.size(); long long t = 1; long long x = st[0] - '0'; for (int i = 1; i < sz; i++) { if (st[i] == 1 - x + '0') { t++; x = 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
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int t = 1; for (int i = 1; i < n; i++) { if (s[i] != s[i - 1]) t += 1; } cout << min(t + 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; int main() { long long int n, m, i, j, c = 0, d = 0, ans = 0; string s; cin >> n; cin >> s; c = 0; for (i = 0; i < n; i++) { if (s[i] == '1' && c % 2 == 0) { c++; } if (s[i] == '0' && c % 2 == 1) c++; } for (i = 0; i < n; i++) { if (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> using namespace std; int main() { string str; int n; cin >> n >> str; int a[n]; for (int i = 0; i < n; ++i) { a[i] = str[i] - '0'; } int f[2][2][3]; memset(f, 0, sizeof(f)); auto update = [](int &a, int b) -> void { if (a < b) a = b; }; int u = 0, v = 1; 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 = int(input()) s = [int(x) for x in list(input())] dp = [0,0] dp[s[0]]=1 for i in range(1,n): j = s[i] if j==0: x = max(dp[1]+1, dp[0]) y = dp[1] else: x = dp[0] y = max(dp[0]+1, dp[1]) #print(x,y) dp[0],dp[1] = x,y ans = max(dp[0],dp[1]) 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
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cin.ignore(); string s; cin >> s; int las = 1; for (int i = 1; i < n; i++) { las += s[i] != s[i - 1]; } int ans = min(n, las + 2); cout << ans << 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.io.*; import java.util.*; import java.math.*; public class Div2_334_C { public static int getLongestConsec(char [] c) { int curr = 1; int max = 0; for(int i = 1;i < c.length;i++) { if(c[i] == c[i-1]) { curr++; max++; } else...
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; using ll = long long; using llu = unsigned long long; using ld = long double; const double PI = acos(-1.0), g = 9.80665; const ll inf = 1e18 + 505; ll i, j, k, n, m, cnt; bool is; void solve(void) { cin >> n; string s; cin >> s; ll len = 1; for (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 N, res = 1; string S; int main() { 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
#include <bits/stdc++.h> using namespace std; int n, r = 1; string s; int main() { cin >> n >> s; for (int i = 1; i < n; i++) { r += s[i] != s[i - 1]; } cout << min(r + 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
n= int(raw_input()) x = raw_input() f = 0 last = x[0] ans = 1 for i in x[1:]: if last!=i: ans+=1 last=i else: f=min(f+1,2) ans = f+ans 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
import sys def answer(n, s): ctr = 0 cstates = 1 for i in range(1, n): if s[i] == s[i-1]: ctr += 1 else: cstates += 1 if ctr >= 2: cstates += 2 elif ctr == 1: cstates += 1 return cstates def main(): n = int(sys.stdin.readline()) s...
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, a = input(), raw_input() print min(a.count("10") + a.count("01") + 3, n)
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.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util...
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()) l=input() cnt ='' i=0 from itertools import groupby for k,g in groupby(l): cnt+=k cnt=len(cnt) print(min(cnt+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().strip() l = [] for i in range(len(s)): l.append(0) l[0]=1 for i in range(1,len(s)): if s[i]==s[i-1]: l[i]=l[i-1] else: l[i] = l[i-1] + 1 print min(l[-1]+2,n)
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
/* Keep solving problems. */ import java.util.*; import java.io.*; public class CFA { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; final long MOD = 1000L * 1000L * 1000L + 7; int[] dx = {0, -1, 0, 1}; int[] dy = {1, 0, -1, 0}; void solve() 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
x = int(input()) y = input() if x <= 3: print(x) quit() num1 = 0 num0 = 0 for i in y: if i == '1': num1 = max(num1, num0+1) else: num0 = max(num0, num1+1) maxx = max(num1, num0) if '11' not in y and '00' not in y: print(maxx) quit() print(min(maxx+2, x))
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; template <typename T> inline void checkMax(T &a, T b) { a = a > b ? a : b; } template <typename T> inline void checkMin(T &a, T b) { a = a < b ? a : b; } const double PI = acos(-1.0); const double eps = 1e-8; int n; char str[100005]; int from[100005][2], to[100005][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(input()) s = input() k1, k2, k1l, k2l = 0, 0, '0', '1' for i in s: if k1l != i: k1 += 1 k1l = i if k2l != i: k2 += 1 k2l = i print(min(len(s), max(k1, k2) + 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
#include <bits/stdc++.h> using namespace std; int dp[3][100003]; int main() { int n; cin >> n; string s; cin >> s; dp[0][0] = dp[1][0] = 1; for (int i = 1; i < n; i++) { if (s[i] == s[i - 1]) { dp[0][i] = dp[0][i - 1]; dp[1][i] = max(dp[0][i - 1] + 1, dp[1][i - 1]); dp[2][i] = max(dp[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
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.Writer; import java.io.BufferedReader; import java.io.FileReader; 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 N = 2e5 + 15; const long long int inf = 1e18; void solve() { long long int n; cin >> n; string s; long long int ans = 1; cin >> s; for (long long int i = 1; i < n; i++) ans += (s[i] != s[i - 1]); cout << min(n, ans + 2); } void debug(long long int tt...
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() cnt = 1 intervals = [1] for i in range(1, n): if s[i] != s[i - 1]: intervals.append(1) else: intervals[-1] += 1 has_three = False for interval in intervals: if interval >= 3: has_three = True break if has_three: print(len(intervals) + 2) else:...
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
def answer(n,A): count=1 for i in range(1,n): if A[i]!=A[i-1]: count+=1 return min(count+2,n) n=int(input()) s=input() print(answer(n,s))
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.*; import java.util.*; public class A { InputStream is; int __t__ = 1; int __f__ = 0; int __FILE_DEBUG_FLAG__ = __f__; String __DEBUG_FILE_NAME__ = "src/T"; FastScanner in; PrintWriter out; public void solve() { int n = in.nextInt(); char[] s = in.next().toCharArray(); int sum1 = 0;...
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() mem=s[0] streak=1 amount=0 res=0 score=1 for l in range(1,n): if s[l]==mem: streak+=1 else: mem=s[l] streak=1 score+=1 if streak>2: res=2 elif streak==2: amount+=1 if amount>1: res=2 if amount+max(res-1,0)==1: res=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
import java.util.Scanner; public class main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); scan.nextLine(); String line = scan.nextLine(); int l = line.charAt(0) - '0'; int count = 1; boolean[] arr =...
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 s[100005]; int main() { scanf("%d %s", &n, s); int ans = 1; for (int i = 1; i < n; i++) { if (s[i] != s[i - 1]) ans++; } printf("%d\n", 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
'''input 56 10101011010101010101010101010101010101011010101010101010 ''' from sys import stdin def get_count(c): count = 0 flag = False i = 1 while i < n + 2: if arr[i] == arr[i -1] and arr[i] == c: if i == n + 1 or i == n: flag = True count += 1 i += 2 continue i += 1 return count, flag # m...
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()) ch = str(input()) if n == 1: print(1) else: B = [0 for _ in range(n)] B[0] = 1 c = ch[0] for k in range(1,n): if ch[k] == c: B[k] = B[k-1] else: B[k] = B[k-1] + 1 c = ch[k] T = [0 for _ in range(n)] F = [0 for _ in r...
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 = raw_input() res = 1 for r in range(n-1): if (s[r] != s[r+1]): res += 1 if (res == n): print res elif (res == n-1): print res+1 else: print res + 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
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int n, len, dp0, dp1; char a[maxn]; int main() { cin >> n; scanf("%s", a); len = strlen(a); int ans = 0; if (a[0] == '0') dp0 = 1; else dp1 = 1; for (int i = 1; i < len; i++) { if (a[i] == '0') dp0 = dp1 + 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.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; import java.util.StringTokenizer; public class A { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(Syst...
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
ans=0 z=0 a=raw_input() b=raw_input() for i in range(1,int(a)): if b[i]==b[i-1] and z<2: ans+=1 z+=1 if b[i]!=b[i-1]: ans+=1 print ans+1
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() { int i, n, df = 0, eq = 0; char s[100000 + 1]; scanf("%d\n", &n); gets(s); for (i = 1; i < n; i++) s[i] == s[i - 1] ? eq++ : df++; df++; if (eq > 1) df += 2; else if (eq == 1) df++; printf("%d", df); 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; const int INF = 1e9; int n, a[MAXN], dp[MAXN][3], last0 = -1, last1 = -1; string s; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> s; dp[0][0] = 1; dp[0][1] = 1; dp[0][2] = 1; if (s[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.util.*; import java.io.*; public class B { FastScanner in; PrintWriter out; public void solve() throws IOException { int n = in.nextInt(); String s = in.next(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = s.charAt(i) - '0'; } ...
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, tab, changes = int(input()), str(input()), 1 for i in range(1, n): changes += 1 if tab[i] != tab[i - 1] else 0 print(min(changes + 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
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String str=sc.next(); int[][] dp=new int[n][3]; for(int i=0;i<n;i++){ if(i==0){ dp[i][0]=dp[i][1]=dp[i][2]=1; continue; } if(str.charAt(i)==str.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
def solve(compStr, compLen): # print len(compStr) # print compLen ret = len(compStr) for v in compLen: if v >= 3: return ret + 2 cnt = 0 for i in range(len(compLen)): if compLen[i] >= 2: cnt += 1 if cnt >= 2: return ret + 2 elif cnt == 1: return ret + 1 else: re...
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.IOException; import java.util.Arrays; import java.util.Scanner; public class SetNumbers { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String s = sc.next(); int res=1; for (int 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> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") const double Pi = acos(-1); using namespace std; int debug = 01; int leader[110][110]; int find_leader(int c, int i) { if (leader[c][i] == i) 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
n = int(input()) s = input() cur, arr = 1, [] for i in range(1, n): if s[i] == s[i - 1]: cur += 1 else: arr.append(cur) cur = 1 arr.append(cur) cur = 0 ans = len(arr) for i in arr: if i > 2: exit(print(ans + 2)) if i == 2: cur += 1 print(ans + min(2, cur))
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 MOD = 1000 * 1000 * 1000 + 7; const double PI = 2 * acos(0); char A[100002]; int main() { int N; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } int ans = 1; for (int i = 1; i < N; i++) { ans += (A[i] != A[i - 1]); } cout << min(N, 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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /** * Created by Kamil Khadiev on 11.08.2015. */ public class khadiev_345_c { public static void main(String[] args) throws IOException { BufferedRead...
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 inp[100005]; int f1[100005][2]; int f2[100005][2]; int flip[100005][2]; int main() { int n; int ans = 0; scanf("%d", &n); scanf("%s", inp); memset(f1, 0, sizeof f1); memset(f2, 0, sizeof f2); memset(flip, 0, sizeof flip); if (inp[0] == '0') f1[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
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string a; cin >> a; if (a.size() == 1) { return cout << 1, 0; } char f = a[0], s = !(a[0] - '0') + '0'; bool b = true, find = false; int c = 1; for (int i = 1; i < n; i++) { if (a[i] != a[i - 1]) c++; } cout << m...
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 s[110000]; int n, f[110000], num[110000]; int bit1[110000], bit2[110000]; int query1(int x) { int ans = 0; while (x) { ans = max(ans, bit1[x]); x -= ((x) & (-(x))); } return ans; } void update1(int x, int newv) { while (x <= n) { bit1[x] = max(bit...
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()) str=raw_input() v=(0,0) v_changing=(0,0) v_changed=(0,0) best=0 for ch in str: nv= (v[1]+1, v[1]) if ch=='0' else (v[0], v[0]+1) if ch=='0': nv_changing=(0, max(v[0], v_changing[0])+1) else: nv_changing=(max(v[1], v_changing[1])+1, 0) if ch=='0': ...
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 double pi = acos(-1); int n; string s; int main() { cin >> n; cin >> s; int ans = 1; for (int i = 1; i < n; ++i) ans += s[i] != s[i - 1]; ans = min(n, ans + 2); cout << ans << 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[100100]; int n, ans = 1, tmp; int main() { scanf("%d %s", &n, s); for (int i = 1; i < n; i++) if (s[i] != s[i - 1]) ans++; else tmp++; if (tmp) ans++; if (tmp > 1) ans++; 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
def main(): n = int(raw_input()) S = list(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 if __name__ == "__main__": main()
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 OO = 1e8; const double EPS = (1e-7); int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; } int n; string s; int dp[100009][2][3]; int solveDP(int i, int prev, int op) { if (i == n) return op == 3; int& ret = dp[i][prev][op]; ...
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() dp = [1]*n for i in range(1,n): if s[i]!=s[i-1]: dp[i] = max(dp[i], dp[i-1] + 1) else: dp[i] = dp[i-1] print(min(n, max(dp)+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
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int cnt = 1; for (int i = 0; i < n - 1; i++) { if (s[i] != s[i + 1]) cnt++; } cout << min(n, 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; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long N, ans = 1; cin >> N; string S; cin >> S; for (long long i = 1; i < N; i++) ans += (S[i] != S[i - 1]); 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; char s[100005]; int dp[100005][3]; int main() { int n; scanf("%d", &n); scanf("%s", s); int a[2], b[2], c[2]; a[0] = a[1] = b[0] = b[1] = c[0] = c[1] = 0; for (int i = 1; i <= n; i++) { int x = s[i - 1] - '0'; dp[i][2] = max(dp[i][2], c[1 - x] + 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, a[100010], f[100010], i, dx, ans, t; char c; int main() { scanf("%d", &n); dx = 0; ans = 0; f[1] = 1; t = 0; for (i = 1; i <= n; i++) { scanf(" %c", &c); if (c == '1') a[i] = 1; else a[i] = 0; if (i > 1) { if (a[i] == a[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()) s = input().strip() ret = 1 nb2 = 0 for i in range(1,n): if s[i-1] != s[i]: ret += 1 else: nb2 += 1 if nb2 >= 2: ret += 2 else: ret += nb2 print(ret)
PYTHON3