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>
int main() {
std::ios_base::sync_with_stdio(false);
int N, sol = 1;
std::string S;
std::cin >> N >> S;
for (int i = 0; i < N - 1; i++) sol += (S[i] != S[i + 1]);
std::cout << std::min(N, sol + 2);
return 0;
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 1, INF = 1e17, MOD = 1e9 + 7;
long long n, ans, cnt, t;
string s;
vector<long long> v;
long long ch(char a) { return (long long)a - 48; }
int32_t main() {
ios_base::sync_with_stdio(0);
cin >> n >> s;
if (s[0] == '0')
ans++, t++;
else... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | n=int(input())
s=[int(x) for x in list(input().strip())]
an=[s[0]]
c=0
cq=0
p=False
q=False
for i in range(1,n):
if s[i]^s[i-1]:
an.append(s[i])
if p==True:
if (i+1 )<n:
if s[i+1]==s[i]:
c+=1
p=False
else:
if p:
c+=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;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
char c[n + 1];
long long i, j;
for (i = 1; i <= n; i++) cin >> c[i];
long long a[n + 1], b[n + 1];
a[1] = 1;
for (i = 2; i <= n; i++) {
if (c[i] != c[i - 1])
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;
int main() {
long long int n;
cin >> n;
string s;
cin >> s;
vector<long long int> ind;
long long int t = 0;
ind.push_back(0);
for (long long int i = 1; i < n; i++) {
if (s[i] != s[ind[t]]) {
t++;
ind.push_back(i);
}
}
long long int f ... | 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.InputStreamReader;
import java.util.Arrays;
public class AlternativeThinking {
static int n;
static char[] s;
static int DP[][][] = new int[3][3][100003];
static int getMax(int curr, int alter, int prev) {
if (curr >= n)
return 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 | #!/usr/bin/python
import os
import sys
import itertools
def solve(f):
n = f.read_int()
s = f.read_str()
so = s[0]
c = 1
cflip = 0
cl = []
for si in s[1:]:
if so == si:
c += 1
else:
cflip += 1
cl.append(c)
c = 1
so = s... | 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 | input()
v=[0]*8
for x in raw_input():
t=v[:]
d=int(x)
for i in (0,1):
for j in (0,1,2):
y=v[j*2+i]
z=1-d if j%2 else d
if i==z:
u=(j+1)*2+(1-z)
t[u]=max(t[u],y+1)
u=j*2+z
t[u]=max(t[u],y)
else:
u=j*2+z
t[u]=max(t[u],y+1)
v=t
print max(v... | 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 MOD = 1e9 + 7;
int main() {
int n;
scanf("%d", &n);
string s;
cin >> s;
int len = 1;
for (int i = 1; i < s.length(); i++) {
if (s[i] == s[i - 1]) {
continue;
}
len++;
}
cout << min(len + 2, n) << endl;
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
template <typename... T>
void read(T&... args) {
((cin >> args), ...);
}
template <typename... T>
void write(T&&... args) {
((cout << args << " "), ...);
}
template <typename... T>
void writen(T&&... args) {
((cout << args << "\n"), ...);
}
long long bin(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 | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class AlternativeThinking {
InputStream is;
PrintWriter pw;
String INPUT = "";
long L_INF = (1L << 60L);
... | 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 = input()
s = raw_input()
doubles = 0
triples = 0
for i in range(n - 1):
if s[i] == s[i + 1]:
doubles += 1
for i in range(n - 2):
if s[i] == s[i + 1] and s[i + 1] == s[i + 2]:
triples += 1
seq_len = 1
for i in range(... | PYTHON |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n, dp[100001][2];
char s[1000001];
int main() {
int i, j;
scanf("%d", &n);
scanf("%s", s);
if (s[0] == '0')
dp[0][0] = 1;
else
dp[0][1] = 1;
for (i = 1; i < n; i++) {
if (s[i] == '1')
dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] + 1);
else... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
im... | 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 = 3e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;
char s[maxn];
int main() {
int n;
cin >> n;
scanf("%s", s + 1);
int res = 1;
for (int i = 2; i <= n; ++i) res += s[i] != s[i - 1];
int ans = res;
int cnt2 = 0, cnt3 = 0;
for (int i = 1, j = 1; i <= ... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.io.*;
import java.util.*;
public class Solution {
static Scanner sc=new Scanner(System.in);
static PrintWriter out=new PrintWriter(System.out);
//Main
public static void main(String args[]) {
int test=1;
//test=sc.nextInt();
while(test-->0) {
int n=sc.nextInt();sc.nextLine();
char s[]=sc.nex... | 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 static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import java.math.BigInteger;
public class Main {
static int [][][] dp;
static int [] A;
static int n,INF =... | 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 B {
static FastReader sc=null;
public static void main(String[] args) {
sc=new FastReader();
int n=sc.nextInt();
char line[]=sc.next().toCharArray();
int dp[][]=new int[n+1][3];
int recentOne=0,recentZero=0;
for(int i=1;i<=n;i++) {
if(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 | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
long long A[1000005];
long long B[1000005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
... | 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 n;
int blocos;
int duplas;
char s[100010];
int main() {
scanf("%d", &n);
blocos = 1;
scanf("%s", &s);
for (int i = 1; i <= n - 1; i++) {
if (s[i] != s[i - 1]) {
blocos++;
} else
duplas++;
}
if (duplas > 2) duplas = 2;
printf("%d\n", blocos + duplas);
retu... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | n = input()
s = raw_input()
cnt = 0
pre = ''
for i in s:
if i != pre:
cnt += 1
pre = i
if "111" in s or "000" in s:
cnt += 2
else:
flag = 0
i = 0
while i < n and flag < 2:
if i + 1 < n and s[i] == s[i + 1]:
flag += 1
i = i + 1
i += 1
cnt +=... | PYTHON |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 |
import java.io.*;
import java.util.Scanner;
import java.util.jar.Pack200;
public class Main {
public static void main (String[] args) throws IOException {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
String line = in.nextLine();
int count = 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 |
import java.util.*;
import java.io.*;
/**
*
* @author umang
*/
public class A603 {
public static int mod = (int) (1e9+7);
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int n=in.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 | #include <bits/stdc++.h>
const int mod = (int)1e9 + 7;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
string s;
cin >> n >> s;
char c = s[0];
int ans = 1;
for (int i = 1; i < n; i++) {
if (s[i] != c) {
c = s[i];
ans++;
}
... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 1, d = 0, y = 0;
cin >> n;
string a;
cin >> a;
for (int i = 0; i <= n - 2; i++) {
if (a[i] != a[i + 1]) sum++;
}
if (sum == n || sum == (n - 1))
cout << n;
else {
for (int i = 1; i <= n - 3; i++) {
if (a[i] == a[i ... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int inf_int = 2e9;
long long inf_ll = 2e18;
const double pi = 3.1415926535898;
template <typename T>
void prin(vector<T>& a) {
for (int i = 0; i < a.size(); i++) {
cout << a[i] << " ";
}
}
template <typename T>
void prin_new_line(vector<T>& a) {
for (int i = 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 | #include <bits/stdc++.h>
using namespace std;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const ui... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.util.*;
import java.io.*;
public class A
{
public static void main(String ar[]) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
char c[]=br.readLine().toCharArray();
... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #!/usr/bin/env python3
# 604C_thinking.py - Codeforces.com/problemset/problem/604/C by Sergey 2015
import unittest
import sys
###############################################################################
# Thinking Class (Main Program)
###############################################################################
... | 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>
const long long MOD = 1e9 + 7;
const int MAX_N = 100000 + 100;
const long long INF = 1e18;
const long long delta = 10957;
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int n;
cin >> n;
string s;
cin >> s;
if (n == 1) return cout << 1, 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.ArrayList;
import java.util.Scanner;
import java.lang.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String s = in.next();
if(n == 1)
System.out.println(1);
els... | 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.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 | __author__ = 'MoonBall'
import sys
# sys.stdin = open('data/C.in', 'r')
T = 1
def process():
input()
s = input()
if len(s) == 1:
print(1)
return
b = []
for x in s:
if (not b) or b[-1][0] != x:
b.append((x, 1))
else:
b[-1] = (b[-1][0], b[-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 + 3;
char s[MAXN];
int main() {
int n;
scanf("%d", &n);
scanf("%s", s + 1);
int c = 0;
int p = 0;
char previ = 'a';
int ans = 0;
for (int i = 1; i <= n; i++) {
if (s[i] != previ)
p = 1, ans++;
else {
p++;
if (p ... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | n = int(input())
s = input()
dl = 1
now = s[0]
k = 0
for i in range(1, n):
if now != s[i]:
now = s[i]
dl += 1
for i in range(n - 1):
if s[i] == s[i + 1] == '0' or s[i] == s[i + 1] == '1':
k += 1
if k >= 2:
print(dl + 2)
elif k == 1:
print(dl + 1)
else:
print(dl)
| PYTHON3 |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | def main():
input()
l, a = [0, 0], '*'
for b in input():
l[a == b] += 1
a = b
print(l[0] + min(l[1], 2))
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 |
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;
public class P603A {
//static long mod=1000000007;
public static int LAS(char a[],int n)
{
int ans=1;
for(int i=0;i<n-1;i++)
{
if(a[i]!=a[i+1])
... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | __author__ = 'trunghieu11'
def solve(n, s):
answer = 1
cur = s[0]
same = 0
for i in range(1, n):
answer += s[i] != cur
cur = s[i]
same += s[i] == s[i - 1]
return answer + min(2, same)
if __name__ == '__main__':
n = int(raw_input())
s = raw_input()
print solve... | 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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.ArrayList;
... | 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 INF = 1000000000;
const long double PI = 3.14159265358979323846264338327;
void solution() {
int n;
cin >> n;
string s;
cin >> s;
char lastDigit = s[0];
vector<int> indexes;
indexes.push_back(0);
for (int i = 1; i < n; i++) {
if (s[i] != lastDig... | 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 n, i, k = 0;
char a[100000];
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
if (i != 0 && a[i] == a[i - 1]) k++;
}
if (k == 1) {
cout << n;
return 0;
}
if (k >= 2) {
cout << n - k + 2;
return 0;
}
cout << 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 long long int N = 1e5 + 1000;
long long int dp[N], n, ans, cnt = 1, mx;
string s;
int main() {
cin >> n >> s;
dp[0] = 1;
for (int i = 1; i < n; i++) {
dp[i] = dp[i - 1];
dp[i] += (s[i] != s[i - 1]);
if (s[i] == s[i - 1]) {
cnt++;
if (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 | n = int(input())
a = list(input())
sum = 0
pr = '2'
for i in range(n):
if a[i] != pr:
sum += 1
pr = a[i]
eo = 0
for i in range(n - 1):
if a[i] == a[i + 1]:
eo += 1
if eo >= 2:
print(min(n, sum + 2))
elif eo == 1 or len(a) == 2:
print(min(sum + 1, n))
else:
print(sum)
| 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.cf3xx.cf334.div1;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
/**
* Created by hama_du on 2016/08/17.
*/
public class Main {
public static void main(String[] args) {
InputReade... | 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.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
public class Main {
public static void main(Str... | 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().split())
a = input()
prev,cur = ('0','0')
t = 1
flag = 0
x = 1
if ( len(a) > 1 ):
for i in range(len(a)):
cur = a[i]
if ( i > 0 ):
if ( prev == cur ):
x = x + 1
else:
x = 1
t += 1
if ( x >= 2 ):
flag += 1
prev = cur
#print ( "%d %d" % ( t, flag))
if ... | 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 s[100100];
int main() {
int n, now = 1, add = 0;
scanf("%d", &n);
scanf("%s", s);
for (int i = 1; i < n; i++) {
if (s[i] != s[i - 1])
now++;
else
add++;
}
printf("%d\n", now + min(add, 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 | n = int(input())
s = input()
print(min(n,sum(s[i]!=s[i-1] for i in range(1,n))+3)) | PYTHON3 |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
int main() {
ios_base::sync_with_stdio(false);
int n, cnt = 1;
string str;
cin >> n >> str;
for (int i = 1; i <= n - 1; i++) {
if (str[i] != str[i - 1]) cnt++;
}
int ans = min(cnt + 2, n);
cout << ans;... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
char str[N];
int f[N][2];
void updata(int &x, int y) { x = max(x, y); }
int main() {
int n;
scanf("%d", &n);
scanf("%s", str + 1);
n = strlen(str + 1);
memset(f, -1, sizeof(f));
f[0][0] = f[0][1] = 0;
for (int i = 0; i < n; ++i)
for ... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | 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.util.ArrayList;
import java.io.InputStream;
/**
* Built using CHel... | 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;
string s;
int main() {
int n, dem = 0;
cin >> n;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] != s[i + 1]) dem++;
}
if (dem == n)
cout << dem;
else if (dem + 2 < n)
cout << dem + 2;
else if (dem < n && dem + 2 >= n)
cout << n;
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main
{
void solve() throws Exception
{
int n = nextInt();
char[] a = nextToke... | 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, m, f, g, te = 0, num = 0;
bool pls = 0;
string s;
cin >> n;
cin >> s;
char cur = '4';
for (int i = 0; i < s.size(); i++) {
if (s[i] != cur) {
cur = s[i];
te++;
}
if (i >= 2) {
string t = s.substr(i - 2, 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 | /* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Sc... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 |
n = int(raw_input())
results = [int(x) for x in raw_input()]
dp = []
for i in xrange(n):
dp.append([])
for j in xrange(3):
dp[i].append([])
for k in xrange(2):
dp[i][j].append(0)
dp[0][2][0] = 0
dp[0][2][1] = 0
if results[0] == 0:
dp[0][1][0] = 0
dp[0][1][1] = 1
dp[... | 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;
long long n, i, t = 3;
string s;
int main() {
cin >> n >> s;
for (i = 1; i < n; i++)
if (s[i] != s[i - 1]) t++;
cout << min(t, n);
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.lang.*;
import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
public class Solution implements Runnable {
void solve() throws Exception {
int n = sc.nextInt();
String s = sc.nextToken();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = 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 | n = int(input())
s= list(input())
lis=[0]*n
bb=[]
p=s[0];lis[0]=1;kk=0
for i in range(1,len(s)):
if s[i]!=p:
lis[i]=1
p=s[i]
for i in range(1,len(s)):
# print(s[i],s[i-1])
if s[i]==s[i-1]:
kk+=1
else:
bb.append(kk);kk=0
bb.append(kk)
ans=c=0
#print(lis... | 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, res = 1;
string in;
cin >> n >> in;
for (int i = 1; i < n; i++) {
res += (in[i] != in[i - 1]);
}
cout << min(res + 2, n);
return 0;
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
char s[101000];
int b[101000];
int n, m, ans;
int main() {
cin >> n;
scanf("%s", s + 1);
int now = 0;
for (int i = 1; i <= n; i++) {
if (s[now] != s[i]) ans++, now = i;
if (s[i] == s[i - 1]) m++;
}
ans += min(2, m);
cout << ans << endl;
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | input()
s=input()
t,r=int(s[0]),0
for i in s:
if int(i)==t:r+=1;t=1-t
print(min(r+2,len(s))) | PYTHON3 |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int MAX = 100001;
char s[MAX];
int n;
int mem[MAX][3][3];
int dp(int index, int prev, int flip) {
if (index >= n) return 0;
int cur = s[index] - '0';
int &ans = mem[index][cur][flip];
if (ans != -1) return ans;
int choice1 = 0;
int f = flip;
if (f == 1) ... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
public class AlternativeThinking {
private static Reader in;
private static PrintWriter out;
public static void main(String[] args) throws IOException {
in = new Reader();
... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | """
Codeforces Round #334 (Div. 2)
Problem 604 C. Alternative Thinking
@author yamaton
@date 2015-12-01
"""
import itertools as it
import functools
import operator
import collections
import math
import sys
def solve(s, n):
lens = [sum(1 for i in iterable) for (_, iterable) in it.groupby(s)]
maxlen = max(le... | 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 OO = 0x3f3f3f3f;
const int _OO = -1 * OO;
const double EPS = (1e-9);
const double pi = 3.14159265;
using namespace std;
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int dx8[8] ... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | # Author : nitish420 --------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
# mod=10**9+7
# sys.setrecursionlimit(10**6)
# from functools import lru_cache
def main():
n=int(input())
s=list(map(int,input()))
ans=1
for i in range(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;
string b;
long long int a[100005];
int main() {
long long int n, i;
cin >> n >> b;
for (i = 0; i < b.length(); i++) a[i] = b[i] - 48;
long long int count = 1;
for (i = 1; i < n; i++) count += (a[i] != a[i - 1]);
cout << min(count + 2, n) << endl;
return 0;
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
string str;
int maxSub(int i, int j, bool ee) {
int ans = 0;
int last = str[i] - '0';
for (int k = i; k <= j; k++) {
int c = str[k] - '0';
if (c == last) {
last = 1 - last;
ans++;
}
}
return min(ans + 2, j - i + 1);
}
int main() {
int n;
... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long n, i, maxx = -1e17, ans = 1;
string s;
cin >> n;
cin >> s;
for (i = 1; i < n; i++) {
if (s[i] != s[i - 1]) ++ans;
}
cout << min(ans + 2, n);
return 0;
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(nam... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt(),cnt = 1;
char arr[] = sc.nextLine().toCharArray();
for(int i = 1; i < n; i++) {
if(... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import sys
import math
MAXNUM = math.inf
MINNUM = -1 * math.inf
ASCIILOWER = 97
ASCIIUPPER = 65
def getInt():
return int(sys.stdin.readline().rstrip())
def getInts():
return map(int, sys.stdin.readline().rstrip().split(" "))
def getString():
return sys.stdin.readline().rstrip()
def printOutput(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>
int n, i = 1, a = 3;
char s[100001];
int main() {
scanf("%d%s", &n, s);
for (; i < n; i++) a += (s[i] != s[i - 1]);
if (a > n) a = n;
printf("%d", 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>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\t";
err(++it, args...);
}
template <typename T1, typenam... | 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.*;
/**
* Created by peacefrog on 11/4/15.
* Time : 10:24 PM
*/
public class Task_C {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
PrintWriter out;
long timeBegin, timeEnd;
public void runIO() throws IOException {
timeBegin = System.currentTimeMi... | 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.StringTokenizer;
import static java.lang.Math.min;
public class Code_603A_AlternativeThinking{
public static void main(String[] args) throws IOException{
BufferedReader br=new B... | 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 dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int xChange[] = {0, 1, 0, -1};
int yChange[] = {1, 0, -1, 0};
const int N = 100001;
string s;
int n, dp[N][2][3];
int solve(int idx, int last, int flag) {
if (idx == n) return 0;
if (dp[idx]... | 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 | ans = 1
n = int(input())
s = input()
for i in range(1, n):
ans += int(s[i]!=s[i-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 | import java.util.*;
import java.io.*;
/* Mighty Cohadar */
public class Alfa {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
assert 1 <= n && n <= 1e5 : "out of range, n: " + n;
scanner.nextLine();
char[] A = scanner.nextLine().toCharArray();
... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | n=input()
b = raw_input().strip()
def solve(n,b):
if n==1:
return 1
if n==2:
return 2
pre=0
v = 2
bb = []
nn=0
for i in b:
if i != v:
pre += 1
bb.append(nn)
nn=0
v=i
nn+=1
bb.append(nn)
bb=bb[1:]
if pre==... | 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 | s1=int(input())
s2=input()
d=1
et=s2[0]
p=0
tp="2"
for i in range(1,s1):
if s2[i]!=et:
d=d+1
et=s2[i]
if s2[i]==s2[i-1] and tp!=s2[i]:
p=p+1
#tp=s2[i]
#if s2[i]!=tp:
# tp=2
if p==0:
print(d)
elif p==1:
print (d+1)
else:
print (d+2)
| PYTHON3 |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n;
string cad;
int mem[5][111111][5];
int go(int prev, int pos, int ch) {
if (pos == n) return 0;
int &r = mem[prev][pos][ch];
if (r != -1) return r;
r = go(prev, pos + 1, ch);
int curr = cad[pos] - '0';
if (ch == 1) curr = 1 - curr;
r = max(r, go(curr, po... | 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 cf {
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(b... | 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;
int result = 1;
for (int i = 1; i < n; i++) {
if (s[i] != s[i - 1]) result++;
}
cout << min(n, result + 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;
long long n, m, k, i, j;
string s;
int main() {
cin >> n;
cin >> s;
for (i = 1; i <= n; i++) {
if (s[i - 1] != s[i]) k++;
}
cout << min(k + 2, n);
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int startidx = 0, endidx = 0, count = 0, flag = 0, flag2 = 0;
while (startidx < n) {
while (s[endidx] == s[startidx]) {
endidx++;
}
if (endidx - startidx >= 3) {
flag = 1;
}
if (en... | 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())
x = input()
q = []
for y in x:
q.append(int(y))
# checking the actual score
def get_score(x, y):
# O(n)
score = 1
f = q[x]
for i in range(x + 1, y):
if q[i] != f:
score += 1
f = 1 - f
return score
flip = 1
for i in range(1, n):
if flip =... | 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() {
long long n, count = 1, flag = 0, i;
cin >> n;
string a;
cin >> a;
for (i = 1; i < a.size(); i++)
if (a[i] != a[i - 1]) count++;
cout << min(count + 2, n);
return 0;
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int MAX = 100001;
const int mod = 1e9 + 7;
vector<int> g[MAX];
int par[MAX];
bool vis[MAX];
long long powr(long long a, long long n, long long m) {
long long res = 1;
a = a % m;
while (n) {
if (n & 1) {
res = (res * a) % m;
}
a = (a * a) % 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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;
/**
* Created by yujiahao on 3/17/16.
*/
public class cf_334_c {
private FastScanner in;
private PrintWriter out;
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 | #include <bits/stdc++.h>
using namespace std;
int n, i, j = 0, k = 0, arr[100001] = {0}, l;
void solve() {
char str[100001];
cin >> n;
cin >> str;
l = str[0];
for (i = 0; i < n; i++) {
if (str[i] != l) {
if (j == 0) {
j = 2;
arr[i] = arr[0] = 1;
} else {
j++;
ar... | 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 Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
char[] a = in.next().toCharArray();
int[][] r = new int[n][3];
int[] lastpos = new int[2];
Arrays.fill(lastpos, -1);
int res = 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 | #include <bits/stdc++.h>
using namespace std;
bool isprime(long long int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
vector<long long int> prime;
... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int maxN(1e5 + 10);
typedef int i_N[maxN];
int N, Gx[maxN][2], Fx[maxN][2][2];
i_N A;
string S;
int main() {
scanf("%d\n", &N);
getline(cin, S);
for (int i = 0; i < (int)S.size(); i++) A[i + 1] = S[i] == '1';
A[0] = A[N + 1] = -1;
for (int 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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
public class CFTest80 {
static BufferedReader br;
static LinkedList<String> tokList;
static {
br = new BufferedReader(new InputStreamReader(System.in));
tokList = n... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CODEFORCES604A {
static class R... | 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 = int(input()), input()
ans = 1
for i in range (1,n):
ans += (s[i] != s[i-1])
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;
int n;
char T[100000 + 1];
int main() {
ios::sync_with_stdio(0);
cin >> n >> T;
for (int a = 0; a < n; ++a) T[a] -= '0';
int ret1 = 0, ret2 = 0, i1 = 0, i2 = 1;
for (int a = 0; a < n; ++a) {
if (T[a] == i1) {
++ret1;
i1 = !i1;
}
if (T[a] ==... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int inv = 1;
char c[100005];
scanf("%d", &n);
scanf("%s", c);
if (n == 1) {
printf("1");
return 0;
}
int p = 0;
for (int i = 0; i < n - 1; i++) {
inv += (c[i] != c[i + 1]);
p += (c[i] == c[i + 1]);
}
inv += max(2 * (... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.