Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int n; char S[100005]; int main() { scanf("%d", &n); scanf("%s", S + 1); int as = 1, bj = 0; for (int i = (2); i <= (n); ++i) { if (S[i] != S[i - 1]) ++as; else bj++; } printf("%d\n", as + min(bj, 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> const double PI = 3.141592653589793238460; using namespace std; long long pows(long long a, long long n, long long m) { long long res = 1; while (n) { if (n % 2 != 0) { res = (res * a) % m; n--; } else { a = (a * a) % m; n = n / 2; } } return res % 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
n = int(input()) s = input() b = [] k = 1 a0 = s[0] ma = 0 for i in range(1,n): if a0 == s[i] and i == n - 1: k += 1 ma = max(ma, k) b.append(k) elif a0 == s[i]: k += 1 elif a0 != s[i] and i == n - 1: ma = max(ma, k) b.append(k) b.append(1) 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
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; char curr = s[0]; int cnt = 1; for (int i = 0; i < s.length(); ++i) if (s[i] != curr) { ++cnt; curr = s[i]; } 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
//package DPContest; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class CodeForces_603A { public static void main(String[] args) throws IOException { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); bf.readLine(); String input=(bf....
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, dp[4][(int)(1e5 + 5)]; bitset<(int)(1e5 + 5)> A; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N; string s; cin >> s; for (int i = 0; i < N; i++) { A[i] = (s.at(i) == '1'); } for (int i = 0; i < 3; i++) { dp[i][1] = 1; } 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
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n; char a[N]; int G[N][2], P[N][2]; int main() { scanf("%d\n", &n); scanf("%s", a + 1); G[1][a[1] - '0'] = 1; for (int i = 2; i <= n; ++i) { if (a[i] == '0') { G[i][0] = max(G[i - 1][1] + 1, G[i - 1][0]); G[i][1] = G[i - 1][...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.Arrays; import java.util.Scanner; public class AlternativeThinking { static int n , memo[][][]; static String s; //0 --> not toggled //1 --> in the toggled //2 --> after toggling static int solve(int idx , int last , int state) { if(idx == n) return 1; if(memo[idx][last][state] != -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
n = int(input()) t = [int(i) for i in input()] ch = 0 sm = 0 for i in range(n-1): if t[i] == t[i+1]: sm+=1 else: ch+=1 print(ch + min(sm,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
#include <bits/stdc++.h> using namespace std; const int base = 100003; const long long MM = 1ll * 1000000007 * 1000000007; const int maxc = 2e9; string s; int n; void Solve() { cin >> n >> s; int ans = 1; s = " " + s; for (int i = 2; i <= n; ++i) ans += (s[i] != s[i - 1]); cout << min(n, ans + 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
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
N = input() store = raw_input() curletter = store[0] rep = 1 maxrep = 0 alter = 1 twicerep = 0 for letter in store[1:]: if letter == curletter: rep += 1 if rep >= 2: twicerep += 1 maxrep = max(rep,maxrep) else: alter += 1 curletter = letter if maxrep >= ...
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
#! /usr/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # # Copyright © 2016 missingdays <missingdays@missingdays> # # Distributed under terms of the MIT license. """ """ n = int(input()) s = input() res = 1 for i in range(1, n): if s[i] != s[i-1]: res += 1 print(min(res+2, n))
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n = int(input()) a = input() ans = min(n, 3 + a.count('01') + a.count('10')) print(ans)
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; char c[120001]; int n, i, kol, ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (i = 1; i <= n; i++) cin >> c[i]; c[n + 1] = '#'; for (i = 1; i <= n; i++) if (c[i] != c[i + 1]) ans++; else kol++; ans += min(kol, 2); co...
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 implements Runnable { static boolean use_n_tests = false; static int stack_size = 1 << 27; void solve(FastScanner in, PrintWriter out, int testNumber) { int n = in.nextInt(); char[] s = in.next().toCharArray(); int mx = 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
# -*- coding: utf-8 -*- """ Created on Tue Dec 1 16:12:23 2015 @author: matt """ bb = input() aa = input() seq = [int(aa[x]) for x in range(len(aa))] seq_rev = [(~x % 2) for x in seq] count = 0 switches = 0 current_seq = seq current_seq_state = True # true : original, False : alt state = seq_rev[0] for i in range(l...
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
from collections import Counter _ = input() s = input().strip() sequences = Counter() cur_seq_len = 1 for p, n in zip(s, s[1:] + '*'): if p == n: cur_seq_len += 1 else: if cur_seq_len > 3: cur_seq_len = 3 sequences[cur_seq_len] += 1 cur_seq_len = 1 basic = sum(seq...
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.math.*; import java.util.*; public class Main { static final long MOD = 998244353; //static final long MOD = 1000000007; static boolean[] visited; public static void main(String[] args) throws IOException { FastScanner sc = new FastScanner(); int N = sc.nextInt();...
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.lang.Math; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; public class Main implements Runnable { public static void main(String[] args) { new Thread(new Main()).start(); } @Override public ...
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 A { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String s = in.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, l...
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 n = int(sys.stdin.readline()) s = sys.stdin.readline() s = list(s) a = [] k=1 for i in range(n): if i == n-1: a.append(k) break if s[i]==s[i+1]: k+=1 else: a.append(k) k = 1 add_amount = 0 count = 0 for i in range(n-1): if s[i]==s[i+1]: 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
n = input() s = raw_input() ans = 1 for i in range(1, n): ans += 1 if s[i] != s[i-1] else 0 print min(ans+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
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n; cin >> n; string s; cin >> s; long long c = 0, j = 0; while (j < n) { long long i = j; while (i + 1 < n && s[i] == s[i + 1]) i++; j = i + 1; c++; } cout << min(n, c + 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> int main() { int n, result, count = 0, i; scanf("%d", &n); char arr[n]; for (i = 0; i < n; i++) { scanf("\n%c", &arr[i]); } i = 0; for (i = 0; i < n; i++) { if (arr[i] != arr[i - 1]) { count++; } } if (count + 2 < n) { result = count + 2; } if (count ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n=int(raw_input().strip()) arr=list(raw_input().strip()) dp=[1 for i in xrange(n)] last1,last0=-1,-1 for i in xrange(n): if arr[i]=='0': if last1!=-1: dp[i]=dp[last1]+1 last0=i else: if last0!=-1: dp[i]=dp[last0]+1 last1=i print min(max(dp)+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
#include <bits/stdc++.h> using namespace std; const int N = 1E5 + 5; int n, f1, f2, f[N], g[N], p[N], last, ans; char s[N]; int main() { scanf("%d\n%s", &n, s + 1); for (int i = 1; i <= n; i++) if (s[i] == '0') { f1 = f[i] = f2 + 1; } else f2 = f[i] = f1 + 1; f1 = f2 = 0; for (int 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
n = int(input()) s = raw_input() if (n == 1): print 1 elif (n == 2): print 2 else: 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 N = 2e5; const int INF = 1e9 + 9; int n; char a[N]; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); cin >> n; bool flag = 0; int cnt = 0; vector<int> v; for (int i = int(1); i <= int(n); ++i) { cin >> a[i]; if (a[i] != a[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
#include <bits/stdc++.h> using namespace std; const int MXN = 100100; const int inf = 1e9; const int mod = 1000000007; char s[MXN]; int main() { int n; scanf("%d", &n); scanf("%s", s); int cur = s[0] - '0'; int res = 1; int state = 0; for (int i = (1); i < (n); i++) { s[i] -= '0'; if (s[i] == 1 - ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
/** * Created by ProDota2 on 16.12.2015. **/ import java.util.*; import java.io.*; public class Main { public static void main(String argc[]){ Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); String s; int n; n = in.nextInt(); 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
import java.io.*; import java.net.Socket; import java.security.spec.ECField; import java.util.HashMap; import java.util.StringTokenizer; import static java.util.Arrays.sort; public class Main { static int a[]; static int l[]; static int ans[]; static HashMap<Integer, Boolean> map = new HashMap<>(); ...
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; cin >> N; string S; cin >> S; vector<vector<int>> dp(N, vector<int>(3)); dp[0][0] = 1; dp[0][1] = 1; dp[0][2] = 1; for (int i = 0; i < N - 1; i++) { if (S[i + 1] == S[i]) { dp[i + 1][0] = dp[i][0]; dp[i + 1][1] = max(dp[...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int n; char s[100004]; int main() { scanf("%d%s", &n, s + 1); int a = 3; for (int i = 2; i <= n; i++) a += (s[i] != s[i - 1]); printf("%d\n", (a > n) ? n : a); 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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author George Marcus */ public cl...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class C { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); char[] s = br.readLine()....
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStream; public class Main { public static void main(String[] args) { InputS...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int lf[100005], rt[100005], rsp, alf[100005], art[100005]; int main() { int n, i, cnt, cnt2; string s; scanf("%d", &n); cin >> s; rsp = 0; cnt = 0; cnt2 = 0; for (i = 0; i < n; i++) { if (i && s[i] == s[i - 1]) cnt2 = 1; else cnt2++; ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
from sys import stdin inp = stdin.readline t = int(inp().strip()) string = list(inp().strip()) longestSub = 1 prev = string[0] l = 0 d = 0 maxGap = -1 for i in range(1,t): if string[i] != prev: longestSub += 1 prev = string[i] print(min(len(string) , longestSub + 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() { ios_base::sync_with_stdio(0); int n, ans = 1, k = 1; string s, p; bool ok = false; cin >> n >> s; p = s; for (int i = 1; i < s.length() - 1; i++) { if (s[i - 1] == s[i] && s[i] == s[i + 1]) { ok = true; if (s[i] == '1') 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.util.Scanner; public class rus { public static void main(String args[]) { Scanner in = new Scanner(System.in); int n =in.nextInt(); String s = in.next(); int res =1; for(int i=1;i < n;i++){ if(s.charAt(i)==s.charAt(i-1)) res += 0; e...
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 ii(): return int(input()) def si(): return input() def mi(): return map(int,input().split()) def li(): return list(mi()) n=ii() s=si() if n==1: print(1) else: cnt=1 st=s[0] for i in range(1,n): if s[i]!=st: cnt+=1 st=s[i] 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
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); string s; int n; cin >> n >> s; int e0 = 0, e1 = 0; bool b0 = true, b1 = true; for (int i = 0; i < n; i++) { if ((b0 && s[i] == '0') || (!b0 && s[i] == '1')) { b0 = !b0; e0++; } if ((b1 && ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T t) { return t < 0 ? -t : t; } const long long modn = 1000000007; inline long long mod(long long x) { return x % modn; } int a[100009]; int main() { int i, j, n; char c; scanf("%d", &n); for (i = 0; i < n; i++) { scanf(" %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 OneD(int row, int col, int t_n_o_r) { return row * t_n_o_r + col; } long long int MOD(long long int a, long long int b) { return a >= 0 ? a % b : (b - abs(a % b)) % b; } void MN(long long int &a, long long int b) { if (a > b) a = b; } void MX(long long int &a, long ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; char c[200000]; int f[200000][2]; int b[200000][2]; int d[200000], mx[200000]; int main() { int N; scanf("%d", &N); scanf("%s", c); for (int Ni = 0; Ni < N; Ni++) { if (Ni != 0) f[Ni][0] = f[Ni - 1][0], f[Ni][1] = f[Ni - 1][1]; int bit = c[Ni] - '0'; f[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 doty[100010][2][2][2], sumy[100010], n; bool vis[100010][2][2][2]; char s[100010]; int solve(int pos, bool lf, bool f, bool fd) { if (pos > n) { if (fd || f) return 0; else return -1000000; } if (vis[pos][lf][f][fd]) { return doty[pos][lf][...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; using ll = long long; int solve() { int n, ans{0}, n_flip{0}; cin >> n; if (n <= 0) return ans; char a, b, c; cin >> a; --n; ++ans; if (n == 0) return ans; cin >> b; if (b != a) ++ans; else ++n_flip; --n; bool flip{true}; while (n--) { ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 110000; char s[MAXN]; int main() { int n; scanf("%d", &n); scanf("%s", s); char tmp = s[0]; int ans = 0; int cnt = 0; for (int i = 1; i < n; i++) { if (tmp != s[i]) { ans++; } else { cnt++; } tmp = s[i]; } if (c...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; char s[100100]; int n; int solve() { int rlt = 1; int a = 0; for (int i = 0; i < n - 1; i++) { if (s[i] == s[i + 1]) a++; if (s[i + 1] != s[i]) rlt++; } if (a > 2) a = 2; return rlt + a; } int main() { scanf("%d", &n); scanf("%s", s); printf("%d\n"...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; long long invmod(long long a, long long n, long long mod) { long long result = 1; while (n > 0) { if (n % 2 == 1) { result = (result * a) % mod; } a = (a * a) % mod; n = n / 2; } return result; } long long fact(long long a, long long mod) { 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(raw_input()) s=raw_input() ctr=1 for i in range(1,n): if(s[i]!=s[i-1]): ctr+=1 print min(n,ctr+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.util.*; import java.lang.*; public class Rextester{ public static void main(String[] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); char[] array = br.readLine().toCharA...
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() ans=1 s=raw_input() for i in xrange(1,n): if s[i]!=s[i-1]: ans+=1 print(min(n,ans+2))
PYTHON
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import sys def main(): n = int(input()) tab = sys.stdin.readline() s = 1 t = tab[0] e = 0 for i in range(1,len(tab)-1): if t != tab[i]: s+=1 t = tab[i] if tab[i] == tab[i-1] == '0' or tab[i] == tab[i-1] == '1': e+=1 e = min(e,2) print(s+e) 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
#include <bits/stdc++.h> using namespace std; template <class T> inline bool getmin(T *a, const T &b) { if (b < *a) { *a = b; return true; } return false; } template <class T> inline bool getmax(T *a, const T &b) { if (b > *a) { *a = b; return true; } return false; } template <class T> inlin...
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.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.LinkedList; public class a { public static void main(String[] args) throws IOException { //BufferedReader input = new BufferedReader(new 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
n, s, ans = int(input()), list(input()), 1 flag = 0 for i in range(1, n): if s[i] == s[i - 1]: s[i] = str(int(s[i]) ^ 1) flag = 1 elif flag: break # print(''.join(s)) last = s[0] for i in s[1:]: if i != last: last = i ans += 1 print(ans)
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const long long INF = 1000 * 1000 * 1000 + 7; const long long LINF = INF * (long long)INF; const int MOD = 1000 * 1000 * 1000 + 7; const int MAX = 1000 * 100 + 47; int A[MAX]; int C[MAX]; int sz = 0; string s; int solve(string s) { int cnt = ...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n = sc.nextInt(); String temp = sc.next(); int[] resultadosArray = new int[n]; for (int i = 0; i < n; i++) { resultadosArray[i] = temp.cha...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; void flash() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void solve() { long long n; cin >> n; string s; cin >> s; long long dp[n][2][2][2]; memset(dp, -1, sizeof(dp)); function<long long(long long, long long, long long, long lon...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; char s[maxn]; int main(void) { int n, x, y; cin >> n >> s; x = 0, y = 1; for (int i = 1; i < strlen(s); i++) { if (s[i] != s[i - 1]) y++; else x++; } cout << y + min(x, 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
n,line=int(input()),input() ans=1+sum(line[i]!=line[i-1] for i in range(1,n)) print(min(ans+2,n))
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; 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
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; long long int n; string s; int main() { cin >> n; cin >> s; long long int rs = 1; for (long long int i = 1; i <= n - 1; i++) { rs += (s[i] != s[i - 1]); } cout << min(rs + 2, n) << "\n"; return 0; }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n=int(raw_input()) s=raw_input() counter=1 for i in xrange(n-1): if s[i]!=s[i+1]: counter +=1 print min(n,counter+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; char str[100020]; int len[3] = {0}; int num[100020]; void zhuanhuan(int x) { if (x >= 3) { len[2]++; } else if (x == 2) { len[1]++; } else { len[0]++; } } int main() { int n, kuan = 1; scanf("%d", &n); scanf("%*c"); for (int i = 0; i < n; i = i +...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1500; const long long inf = 1e15 + 10; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); string s; int ans = 0, n; cin >> n >> s; for (int i = 0; i < n; i++) if (s[i] != s[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
import java.util.Scanner; public class AlternativeThinking { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input =new Scanner(System.in); int n = input.nextInt(); String s = input.next(); int total=1; for(int i=0; i<s.length()-1;i++){ i...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.util.*; import java.io.*; import java.math.*; public class Main { public static long mod= (long) (1e9 +7); public static void main(String args[]) { InputReader s= new InputReader(System.in); OutputStream outputStream= System.out; PrintWriter out= new PrintWriter(outputStream); int n= s.ne...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.util.Scanner; public class R334_3 { 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
#include <bits/stdc++.h> using namespace std; int dp[1 << 17][3][2]; int s[1 << 17]; void solve(int i, int state) { if (i == 0) return; int &z = dp[i][state][0], &o = dp[i][state][1]; if (z != -1) return; if (state == 0) { solve(i - 1, 0); if (s[i] == 1) { z = dp[i - 1][state][0]; o = max(dp...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, i, x, y; string s; cin >> n >> s; x = 1; for (i = 1; i < n; i++) { if (s[0] != s[i]) x++; s[0] = s[i]; } y = min(2, n - x); cout << x + y; }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
n=input() b=raw_input() a,v = 1,0 l = b[0] for i in range(1,n): if b[i] != l: l = b[i] a += 1 if b[i] == b[i-1]: v = 1 print min(a+v*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
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const long long INF = 1e9 + 19; int n; char s[N]; void read() { scanf("%d", &n); scanf("%s", s); int cnt = 0; int cntE = 0; for (int i = 0; i < n - 1; i++) { if (s[i] == s[i + 1]) cntE++; else cnt++; } cnt += min(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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; 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.util.List; import java.util.Map; import java.util.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 long long linf = 1000000000000000043; const int inf = 1000000043; void pause(bool a = true) {} template <class T> inline T prod(pair<T, T> a, pair<T, T> b, pair<T, T> c = make_pair(0, 0)) { return (a.first - c.first) * (b.second - c.second) - (a.second - 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 n, ans = 1; string s; int main() { cin >> n; cin >> s; for (int i = 1; i < s.size(); i++) if (s[i - 1] != s[i]) ans++; cout << min(ans + 2, n); }
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 10; const int INF = (int)1e9; const int mod = (int)1e9 + 7; const long long LLINF = (long long)1e18; int n; string s; int main() { cin >> n >> s; int len = 1; for (int i = 1; i < n; ++i) { if (s[i] == s[i - 1]) continue; ++len; } l...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
l, s = int(input()), input() x, y = 0, 1 for i in range(l-1): if s[i] == s[i+1]: x += 1 else: y += 1 print(y + min(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
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.io.ObjectInputStream....
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
def func(a): l=[] for i in a: l.append(int(i)) inc=1 dec=1 for i in range(1,len(l)): if l[i]>l[i-1]: inc=dec+1 if l[i]<l[i-1]: dec=inc+1 return max(inc,dec) n=int(input()) l=list(input()) if len(l)==2: print(2) else: ans=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.io.IOException; import java.util.InputMismatchException; public class AlternativeThinking { public static void main(String[] args) { FasterScanner sc = new FasterScanner(); int N = sc.nextInt(); char[] S = sc.nextLine().toCharArray(); int[] nf0 = 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
n = int(input()) s = input() + '2' ans = cur = 1 Max = j = 0 flag = False cnt2 = 0 for i in range(1, n + 1): if s[i] != s[j]: j = i if s[i] != '2': ans += 1 if cur >= 3: flag = True elif cur >= 2: cnt2 += 1 cur = 0 cur += 1 if flag or cnt2 >= 2: ans += 2 elif cnt2 == 1: a...
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.io.ObjectInputStream.GetField; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.H...
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 pv(vector<long long int> arr, long long int size) { for (long long int i = 0; i < size; i++) { cout << arr[i] << ' '; } } void gv(vector<long long int> &arr) { long long int size = arr.size(); for (long long int i = 0; i < size; i++) { cin >> arr[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 BinarySearch(int *p, int key, int size) { int l = 0, r = size - 1; if (p[(r - l) / 2] == key) return (r - l) / 2; else if (p[(r - l) / 2] > key) { r = (r - l) / 2 - 1; } else l = (r - l) / 2 + 1; } char change(char p) { if (p == '1') return '0'...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.IOException; import java.io.InputStream; import java.util.InputMismatchException; public class A { static int[] array; static int[] one; static int[] zero; static Integer[][] memo; public static void main(String[] args) { FinalScanner sc = new FinalScanner(); int N = sc.nextInt(); memo = ne...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
import java.io.*; import java.util.*; public class Solution { static void solve(InputReader in, OutputWriter out) { int n = in.nextInt(); String s = in.next(); int cnt = 0; char prev = '2'; for (int i = 0; i < n; i++) if (s.charAt(i) != prev) { ...
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
if __name__ == "__main__": n = int( input().strip() ) s = input().strip() segs = [] start = 0 i = 1 while i <= n: if i == n or s[i] != s[start]: segs.append( i - start ) start = i i = start + 1 else: i += 1 res = len(segs) ...
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.*; public class Alternative_Thinking { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int t=1; while(t-->0) { int n=Integer.parseInt(br...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, c, k = 0, l = 0, t; string s; vector<long long> v; cin >> n >> s; c = 1; for (i = 0; i < n - 1; i++) { if (s[i] != s[i + 1]) { v.push_back(c); c = 1; } else { c++; } } v.push_back(c); t = v.size();...
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.InputStream; import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.IOException; import java.util.InputMismatchException; import java.io.PrintWriter; import java.io.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
var input = readline().split(' ').map(Number), n = input[0]; var str = readline(); var counter = 0; for (var i = 1; i < str.length; i++) { if (str[i] != str[i-1]) counter++; } write(Math.min(counter + 3, 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
n=int(input()) a=input() p=[1]*4 for i in range(1,n): for j in range(2,-1,-1): p[j+1]=max(p[j+1],p[j]+(a[i-1]==a[i])) p[j]+=a[i-1]!=a[i] print(max(p[0:3]))
PYTHON3
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> int main() { int n, ans; char a[100000]; scanf("%d", &n); scanf("%s", a); ans = 1; char cur = a[0]; for (int i = 1; i < n; i++) if (a[i] != cur) { ans++; cur = a[i]; } 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
import java.io.*; //PrintWriter import java.math.*; //BigInteger, BigDecimal import java.util.*; //StringTokenizer, ArrayList public class R334_Div2_C { FastReader in; PrintWriter out; public static void main(String[] args) { new R334_Div2_C().run(); } void run() { in = new FastReader(System.in...
JAVA
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
#include <bits/stdc++.h> using namespace std; int ii[100005], in[100005], ni[100005], nn[100005]; char text[100005]; int arr[100005]; int main() { int n; cin >> n; cin >> text; for (int i = 0; i < n; i++) arr[i] = text[i] - '0'; ii[0] = 0; in[0] = 1; ni[0] = 0; nn[0] = 1; for (int i = 1; i < n; i++) {...
CPP
603_A. Alternative Thinking
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
2
7
# -*- coding: utf-8 -*- """ Created on Thu Sep 10 11:34:34 2020 @author: mahedi """ res=1 n=int(input()) s=input() for i in range(1,n): res=res+(s[i]!=s[i-1]) k=min(n,res+2) print(k)
PYTHON3