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=str( input() ) ret=3 for i in range(1,n): if s[i] != s[i-1]: ret=ret+1 if ret < n : print (ret) else : print (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; const int maxn = 100100; int n, f[maxn][3]; string s; void test() { puts("[test]"); for (int i = 0; i < n; i++) { printf("%d: %6d%6d%6d\n", i, f[i][0], f[i][1], f[i][2]); } } int main() { cin >> n >> s; f[0][0] = f[0][1] = f[0][2] = 1; for (int i = 1; i < n;...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> char a[100003]; int n, i, l, l1, l2; int main() { scanf("%d\n", &n); gets(a); l = strlen(a); l1 = 1; for (i = 0; i + 1 <= l - 1; i++) { if (a[i] != a[i + 1]) l1++; } if (l == l1 || l1 == l - 1) printf("%d", l); else printf("%d", l1 + 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> uint64_t las(std::vector<int8_t> bits) { uint64_t n = bits.size(); uint64_t length = 1; uint64_t new_length = 1; for (uint64_t i = 1; i < n; i++) { if (bits.at(i - 1) != bits.at(i)) new_length++; else { length = new_length > length ? new_length : length; } } ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.*; import java.util.*; public class Main { FastScanner in; PrintWriter out; static final String FILE = ""; public void solve() { int n = in.nextInt(); String s = in.next(); int cnt = 1; for (int i = 1; i < s.length(); i++) { if (s.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
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433; const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; string s; cin >> s; long long ans = 1; for (long long i = 1; i < n; i++) { ans += (s[...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; vector<int> vp; int N; int u = 0; char str[100010]; int cnt = 0; inline void ReadInput(void) { scanf("%d", &N); cin >> str; int last; if (str[0] == '1') { vp.push_back(1); last = 1; cnt = 1; } else { vp.push_back(0); last = 0; cnt = 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; const int inf = 1e5 + 10; char s[inf]; int dp[inf][3][2]; int main() { int n; scanf("%d%s", &n, s); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 2; k++) { dp[i + 1][j][k] = dp[i][j][k]; } } for (int 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; int main() { int n; int tmp1 = 0, tmp2 = 0; cin >> n; string s; cin >> s; for (int i = 1; i <= s.length(); i++) { if (s[i] != s[i - 1]) { tmp1++; } else { tmp2++; } } cout << tmp1 + min(tmp2, 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; char c(char w) { if (w == '1') return '0'; return '1'; } int main() { long int n; scanf("%ld\n", &n); char s[n + 1]; scanf("%s", &s); bool b = 0; for (long int i = 1; i < n; i++) { if ((s[i] == s[i - 1])) { s[i] = c(s[i]); b = 1; } else 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, ans = 1, sum, cnt = 1; string test; string s; int main() { cin >> n; cin >> s; if (n <= 3) { cout << n; return 0; } test[0] = s[0]; for (int i = 1; i < n; i++) { if (s[i] != test[0]) { test = s[i]; ans++; if (cnt < 3) { ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.*; public class CF604C { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); char[] cc = br.readLine().toCharArray(); // a?[i][j] is length of longest subsequence of cc[0,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 sys def solve(n, x): ant = x[0] cont = 1 maximo = 1 maxi = 1 dos = 0 for i in range(1, n): if(ant != x[i]): cont += 1 ant = x[i] if(maximo >= 2): dos += 1 maximo = 1 else: maximo += 1...
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 100; int n; bool inp[MAXN]; int dp[MAXN][7]; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { char t; cin >> t; inp[i] = t - '0'; } if (inp[0]) { dp[0][0] = 0; dp[0][1] = 1; dp[0][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.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.io.Writer; impo...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 1000; int arr[MAXN]; int main() { int n; cin >> n; string s; cin >> s; int cnt = 0; for (int i = 0; i < n - 1; i++) if (s[i] != s[i + 1]) cnt++; cout << min(n, cnt + 3) << 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> int Min(int a, int b) { if (a > b) return b; else return a; } int main() { int n, ans = 0, counter = 0; char s[100001], tmp, ch = 'd'; scanf("%d", &n); getchar(); for (int i = 0; i < n; i++) { scanf("%c", &s[i]); if (i > 0 && tmp == s[i]) { if (ch != 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; long long a[100006], b1[100005], b2[100005], b3[100005], n, k, first, ans, mx; long long sum, l, r, ans1, ans2, ans3; bool f; string s, st; char ch; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; cin >> ch; a[1] = 0; if (ch == '1') a[1] = 1; ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; public class C334 { public static void main(String[] args) { Scanner qwe = new Scanner(System.in); int n = qwe.nextInt(); int[] bits = new int[n]; String str = qwe.next(); for (int i = 0; i < bits.length; i++) { bits[i] = str.charAt(i)-'0'; } int[][] ps = new 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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class C { static char[] c; static int[][][] dp; public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader( new 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.util.Scanner; public class Main { private static int[][] dp1; private static int[][] dp2; public static void main(String[] args) throws Exception { Scanner scan = new Scanner(System.in); int i , j , n = scan.nextInt() , ans = 0; String input = scan.next(); dp1 = new int[n][2]; dp2...
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 dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; const int mx[8] = {-1, -2, -2, -1, 1, 2, 2, 1}; const int my[8] = {-2, -1, 1, 2, 2, 1, -1, -2}; const double eps = 1e-6; const double PI = acos(-1.0); const int maxn = 1e5 + 5; const int inf = 0x3f3f3f3f; int 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 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.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Input...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n = map(int, input()) s = input() l = [] cnt = 1 for i in range( 1, len(s)): if s[i] != s[i-1]: l.append(cnt) cnt = 1 else: cnt += 1 l.append(cnt) result = len(l) max_pair = 0 max_count = 0 for i in range(len(l)): if l[i] == 2: max_pair += 1 max_count = max( max_count, l[i]) if max_pair >= 2 or max_count >=...
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, dp[N][2], su[N][2]; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> s; dp[1][s[0] - '0'] = 1; for (int i = 2; i <= n; i++) { int cur = s[i - 1] - '0'; dp[i][cur] = max(dp[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 sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') input = sys.stdin.readline t = 1 while t: t -= 1 n = int(input()) s = input() res = 1 for i in range(1, n): res += (1 if s[i] != s[i-1] else 0) print(min(n, 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
n=int(input()) a=input() f=a[0] if(n==1 or n==2): print(n) else: i=1 t1=1 while(i<n): if(a[i]!=f): f=a[i] t1+=1 i+=1 t3=0 t2=1 i=1 f1=0 f=a[0] q=0 while(i<n): if(a[i]==f): t2+=1 if(t2==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
//package codeforces; import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * Created by nitin.s on 14/03/16. */ public class AlternativeThinking { static class CustomPair<Character, Integer> { private Character first; //first member of pair private Integer second; //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; const int maxn = 2e5 + 10; int n, m; int dp[maxn][5]; char ss[maxn]; int main() { scanf("%d", &n); getchar(); scanf("%s", ss + 1); for (int i = 1; i <= n; i++) { if (ss[i] == '0') { dp[i][0] = dp[i - 1][1] + 1; dp[i][1] = dp[i - 1][1]; } else if ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
def main(): n, t, a = int(input()), 0, '*' for b in input(): if a == b: t += 1 else: a = b print(n - max(t - 2, 0)) if __name__ == '__main__': main()
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
# CodeForces Div-1 603-A # Greedy Approach n = int(raw_input()) seq = map(int, list(raw_input())) #print seq changed = False changedPos = -1 longest = 0 length = 1 start = seq[0] for i in xrange(1, n): if seq[i] != seq[i-1] : length += 1 else : if not changed or changedPos == i-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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class C { static int n; static char[] s; static int[][][] memo; static int dp(int lst, int flip,...
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.awt.*; import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); StringBuilder sb = new StringBuilder(); int n=sc.nextInt(); String s=sc.next(); int count=1; for(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
from sys import maxsize, stdout, stdin,stderr mod = int(1e9+7) import sys def I(): return int(stdin.readline()) def lint(): return [int(x) for x in stdin.readline().split()] def S(): return input().strip() def grid(r, c): return [lint() for i in range(r)] from collections import defaultdict, Counter, deque import math ...
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; string S; vector<int> occ; int main() { ios::sync_with_stdio(0); cin >> N >> S; char last = S[0]; int len = 1; for (int i = 1; i < N; i++) { if (S[i] == last) len++; else { occ.push_back(len); last = S[i]; len = 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.util.Scanner; /** * Created by Anton on 06/12/2015. */ public class altThinking { public static void main(String[] args){ Scanner sc = new Scanner(System.in); Integer altCounter = 1, strSize; String line; line = sc.nextLine(); strSize = Integer.parseInt(line)...
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[111111]; char ch[111111]; int main() { int n, k; while (~scanf("%d", &n)) { scanf("%s", ch + 1); for (int i = 1; i <= n; i++) a[i] = ch[i] - '0'; int ans = 1; int now = a[1]; for (int i = 2; i <= n; i++) { if (a[i] != now) ans++; no...
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 int N = 200005; const long long int mod = 1e9 + 7; long long int dp[200005][2][3]; long long int n; char s[200005]; long long int A[N], B[N]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> s; long long 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
#include <bits/stdc++.h> using namespace std; const int maxn = 1e9, mod = 14741; int main() { int n; cin >> n; string s; cin >> s; char x = s[0]; int p = 1; for (int i = 0; i < n; i++) { if (s[i] != x) { x = s[i]; p++; } } x = s[0]; int i = 0, ok1 = 0, ok2 = 0, p1 = 0, p2 = 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[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String x = sc.next(); sc.close(); int alternating = 1; for (int i = 1; i < n; i++) { if (x.c...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; import java.io.*; import java.math.*; public class Main { private static int max; static class FastScanner { BufferedReader s; StringTokenizer st; public FastScanner(InputStream InputStream) { st = new StringTokenizer(""); s = new BufferedReader(new InputStreamReader(InputStream)); ...
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.text.*; public class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String st[] = br.readLine().split(" "); int n=Integer.parseInt(st[0]); st=br.readLine(...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.Arrays; import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author hitarthk */ public class C_334_C { public static void main...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; import java.io.*; public class A { public static void main(String[] args) throws Exception { PrintWriter out = new PrintWriter(System.out); new A(new FastScanner(System.in), out); out.close(); } int N; int[] vs; Integer[][][] memo; int go(int last, int s, 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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; import java.util.StringTokenizer; public class A { Scanner scanner = new Scanner(System.in); BufferedReader cin = ...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; char a[2 * maxn + 5]; int main() { int n; cin >> n; cin >> a; int ans = 1; int p = a[0], c = 0; for (int i = 1; i < n; i++) { if (a[i] != a[i - 1]) ans++; else if (c < 2 && a[i] == a[i - 1]) { ans++; c++; } ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; void qread(int &x) { int neg = 1; x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') neg = -1; c = getchar(); } while (c >= '0' && c <= '9') x = 10 * x + c - '0', c = getchar(); x *= neg; } const int maxn = 10...
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 maxn = 2e5 + 8, inf = 1e18 + 9, mod = 1e9 + 7; char s[maxn]; long long n, m; void solve() { long long i, j, ans = 1; cin >> n >> (s + 1); for (i = 2; i <= n; i++) if (s[i] != s[i - 1]) ans++; cout << min(ans + 2, n) << endl; } signed main() { 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 count(char str[]) { int start = 0; char last; last = str[0]; start = 1; for (int i = 1; i < strlen(str); i++) { if (str[i] != last) { last = str[i]; start++; } } return start; } char flip(char a) { if (a == '1') return '0'; if (a ==...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.Scanner; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String s = sc.next(); int len = 1; for (int i = 1; i<n; i++) { if (s.charAt(i) != s.charAt(i - 1)) len++; } System.out.println(Math.min(n, 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; void cline() { cout << '\n'; } template <typename T, typename... V> void cline(T t, V... v) { cout << t; if (sizeof...(v)) cout << ' '; cline(v...); } void cspc() { cout << ' '; } template <typename T, typename... V> void cspc(T t, V... v) { cout << t; if (sizeof....
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() ans = 1 for i in range(1 , n): if s[i] != s[i-1] : ans += 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; string s; int main() { int n, l = 0; cin >> n >> s; for (int i = 1; i < n; i++) if (s[i] != s[i - 1]) l++; cout << min(n, l + 3); }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n,a=input(),raw_input() print min(a.count("01")+a.count("10")+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
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); int N, sol = 1; std::string S; std::cin >> N; std::cin >> S; for (int i = 0; i < N - 1; i++) sol += (S[i] != S[i + 1]); std::cout << std::min(N, sol + 2); return 0; }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.awt.Point; import java.awt.geom.Line2D; import java.io.BufferedReader; import java.io.File; import java.io.OutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.security.GuardedObject; import java.util.ArrayList; import java.util.Arrays; 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
import java.util.Random; import java.util.Scanner; public class main { public static void main (String[] args) throws java.lang.Exception { Scanner input = new Scanner(System.in); String in = input.nextLine(); int n = Integer.parseInt(in); in = input.nextLine(); String[] to...
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; string s; cin >> n >> s; int ans = 1; for (int i = 1; i < n; i++) if (s[i] != s[i - 1]) ans++; if (ans == n) ans = n; else if (ans == n - 1) ans = n; else ans += 2; 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> using namespace std; const long long inf = 1e17 + 10; const int N = 1e6 + 10; const long long mod = 1e9 + 7; const int base = 131; const double pi = acos(-1); map<string, int> ml; map<int, int> vi; long long b[N], c[N], num[N], a[N], n, m, k, x, y, z, vis[N]; long long ex, ey, cnt, ans, sum, fl...
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 dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1}; int dp[100005][3][3]; int nxtz[100005], nxto[100005], n; string s; int dpcall(int id, int lst, int ok) { if (id == n) return 0; int &ret...
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 oo = 0x3f3f3f3f; char s[100009]; int n; int main() { while (scanf("%d", &n) == 1) { scanf("%s", s); int c1 = 0, c2 = 0; for (int(i) = (0); (i) < (n - 1); ++(i)) if (s[i] != s[i + 1]) c1++; else c2++; printf("%d\n", 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.util.Scanner; // NibNalin solution public class JJ { static long dp[][][]; static int[] arr; public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = Integer.parseInt(in.nextLine()); String s = in.nextLine(); arr = new int[s.length()]; int id = 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() ans = 0 for i in range(1, n): if s[i] != s[i-1]: ans += 1 print(min(ans+3, 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.Scanner; /** * Created by tignatchenko on 15.10.2015. */ public class Z1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String s = sc.next(); char[] c = s.toCharArray(); int k = 0; int ...
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() count1=[] x=s[0] i=1 count=1 while i<N: if s[i]==s[i-1]: count+=1 else: count1.append(count) count=1 i+=1 count1.append(count) if any(i>2 for i in count1): print(len(count1)+2) elif count1.count(2)>1: print(len(count1)+2) elif count1.count(2)==1: ...
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n = int(input().strip()) a = input() count_pairs = 0; count_diff = 0; pred = a[0] for i in range(1,n): if a[i-1]==a[i]: count_pairs += 1 else: count_diff += 1 count_pairs = min(count_pairs,2) print(count_pairs+count_diff+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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; public class A { static void solve() throws IOException { int n = Integer.parseInt( in.readLine() ); char[] c = in.readLine().toCharArray(); in...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; char s[1000001]; int main() { int n; scanf("%d", &n); scanf("%s", s); int bf1 = 0, bf2 = 0, ans = 0, len = 1; for (int i = 1; i <= n; i++) { if (s[i] != s[i - 1]) { if (len >= 3) bf2 = 1; else if (len >= 2) bf1++; len = 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; double EPS = 1e-9; int conversion(string p) { int o; o = atoi(p.c_str()); return o; } string toString(int h) { stringstream ss; ss << h; return ss.str(); } long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long lcm(long long a...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> void solve() { int n; std::cin >> n; std::string s; std::cin >> s; int r = 0; for (int i = 1; i < n; ++i) { r += (s[i] != s[i - 1]); } r = std::min(r + 3, n); std::cout << r; } int main() { solve(); 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 unsigned long long M = 998244353; void solve() { long long n; cin >> n; string s; cin >> s; long long res = 1; long long ct = 1; for (long long i = 1; i < n; i++) { if (s[i - 1] == s[i]) ct++; else { res++; ct = 1; } } c...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; int cnt = 1; vector<int> v; for (int i = 1; i < n; i++) if (s[i] == s[i - 1]) cnt++; else v.push_back(cnt), cnt = 1; v.push...
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 test, i, j, xy, flag = 0, n, u, count, d, o1 = 0, o2 = 0, s, e, l, r, x, y, m, z, max1, x1, y1, k, x2, y2, z1, z2, sum, mi...
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 Solution { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); char prev = '-', last = '-'; int count = 0, res = 0, ans = 0, zero = 0, one = 0; for (char x:s.next().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
import java.util.*; import java.io.*; import java.math.*; public class test{ public static void main(String[] args) { // int x,y; FastReader scan=new FastReader(); OutputStream output=System.out; PrintWriter out=new PrintWriter(output); ...
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 = list(input()) # n = 86137 # s = '0' # for i in range(n-2): # s += '1' if s[-1] == '0' else '0' # s += s[-1] # s += s[-1] ans = len([s[i] for i in range(len(s)-1) if s[i] != s[i+1]])+1 for i in range(n-1): if s[i] == s[i+1]: ans += 1 break for j in range(n-1, 0, -1): i...
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 long long N = 1e6 + 10; long long cnt[N]; void solve() { string s; long long n, cc = 0; cin >> n >> s; for (long long i = 0; i < N; i++) cnt[i] = 0; cc = 1, cnt[cc] = 1; for (long long i = 1; i < n; i++) { cc += (s[i] != s[i - 1]); cnt[cc] += 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; const int MOD = 1e9 + 7; const long long MX = 1e9; const long long INF = 1e9; void print_a(vector<int> v) { if (v.size()) cout << v[0]; for (int i = 1; i < v.size(); ++i) cout << ' ' << v[i]; cout << '\n'; } vector<vector<int> > init_vvi(int n, int m, int val) { ret...
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; const int inf = 1e9 + 10; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, c = 1; string s; cin >> n; cin >> s; for (int i = 1; i <= n - 1; i++) { if (s[i] != s[i - 1]) c++; } cout << min(c + 2, n) << '\n'; 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, len, oo; char s[100003]; int main() { scanf("%d", &n); scanf("%s", s); len = 1; oo = 0; for (int i = 1; i < n; i++) { if (s[i] == s[i - 1]) oo++; else len++; } printf("%d\n", len + min(oo, 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
from math import * from Queue import * from sys import * from random import * n = int(raw_input()) s = raw_input() b = [] m = 0 i, j = 0, 0 while i < n: while (j+1 < n) and (s[j+1] == s[j]): j += 1 b.append(j-i+1) m = max(m, j-i+1) i = j+1 j = i if m == 1: print(len(b)) exit(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> auto thinking(const std::string& s) -> int64_t { if (s.size() == 0) return 0; int64_t count = 1; int last = s[0]; for (auto it = std::begin(s) + 1; it != std::end(s); it++) { if (*it != last) { count++; last = *it; } } return std::min((int64_t)s.size(), count + 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; char ch, ch2; int n, mx, res, cnt, cnt2, t; int main() { std::ios::sync_with_stdio(false); cin.tie(0); cin >> n; cin >> ch2; cnt = 1; cnt2 = 0; mx = t = 0; res = 0; for (int i = 2; i <= n; i++) { cin >> ch; if (ch == ch2) { cnt++; } else ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; inline long long getint() { long long _x = 0, _tmp = 1; char _tc = getchar(); while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar(); if (_tc == '-') _tc = getchar(), _tmp = -1; while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = 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; int n; char s[100005]; int a[100005]; int dp[100005][2][3]; int maxv[2][3]; int main() { scanf("%d", &n); scanf("%s", s + 1); for (int i = 1; i <= n; ++i) a[i] = s[i] - '0'; int ans = 0; for (int i = 1; i <= n; ++i) { dp[i][a[i]][0] = 1; dp[i][a[i]][0] = 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
import java.io.*; public class A603 { public static void main(String[] args)throws IOException{ BufferedReader inp = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int size = Integer.parseInt(inp.readLine...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.Scanner; public class AlternativeThinking { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); cin.nextLine(); String string = cin.nextLine(); int count = 1; boolean isChange = false; boolean...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; string s; int ted = 0, mx1, mx2, l = 0, n; void change() { if (mx1 <= ted) { mx2 = mx1; mx1 = ted; } else if (mx2 <= ted) mx2 = ted; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> s; ted = 1; mx1 = mx...
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
a=int(input()) s=input() ans=[] count=1 for i in range(1,len(s)): if(s[i]==s[i-1]): count+=1 else: ans.append(count) count=1 ans.append(count) if(len(ans)==1): if(len(s)==1): print(1) if(len(s)==2): print(2) if(len(s)>=3): print(3) exit() 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
from sys import stdin,stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) for _ in range(1):#nmbr()): n=nmbr() a=[int(ch) for ch in input()] n=len(a) dp=[[[0 for _ in range(2)]for _ in range(3)]for _ in range(n)] dp[0][0][a[0]]=1 dp[0][0][1^a[0]]=0 ...
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 0x3c3c3c3c; const ll INFL = 0x3c3c3c3c3c3c3c3c; const int MAX_N = 1e5 + 9; int n; string s; int dp[MAX_N][3][2]; int getAnswer(int curr, int type, int need) { if (curr == n) { return 0; } if (type >= 3) { return 0; } 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() arr = list(map(int, s)) cnt = 0 pcnt = 0 for i in range(n - 1): cnt += arr[i] != arr[i + 1] pcnt += arr[i] == arr[i + 1] cnt += min(pcnt, 2) print(cnt + 1)
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> char S[100007]; int main() { int i, n, res, m; char l; m = 0; scanf("%d", &n); scanf("%s", S); res = 1; l = S[0]; for (i = 1; i < n; i++) { if (l != S[i]) { res++; } else { if (i == 2 || i == n - 2) { m++; } } l = S[i]; } if (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
n = int(input()) s = input() repeat = 0 count = 0 for i in range (len(s)-1): if s[i] == s[i+1]: repeat += 1 else: count += 1 count += 1 if repeat == 1: count += 1 if repeat >= 2: count += 2 print(count)
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int n, cnt, f, max; char t, s[100009], c[100009]; int main() { cin >> n >> s; if (n == 2) { cout << 2; return 0; } t = s[0]; ++c[cnt]; for (int i = 1; i < n; i++) { if (t == s[i]) ++c[cnt], f++; else ++c[++cnt]; t = s[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; long long int M = 1e9 + 7; long long int n, k, m; long long int z, q, u, a1, l, r, ax, cx, ay, by, cy, ql, qr, d, x, y; vector<long long int> v[400000]; long long int vis[5000005]; long long int cd[5000005]; long long int a[400000]; unordered_map<long long int, long long 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
#include <bits/stdc++.h> int take() { int n; scanf("%d", &n); return n; } double ttake() { double n; scanf("%lf", &n); return n; } long long takes() { long long n; scanf("%lld", &n); return n; } int cas; using namespace std; bool approximatelyEqual(float a, float b, float epsilon) { return fabs(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
from sys import stdin,stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) for _ in range(1): 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 dp[0][...
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; import java.io.*; /** * Made by egor https://github.com/chermehdi/egor. * * @author Azuz * */ public class Main { int[][][] dp; char[] arr; int n; void solve(Scanner in, PrintWriter out) { int n = in.nextInt(); char[] arr = in.next().toCharArray(); char...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; import java.io.*; public class File { public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st ...
JAVA