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 | import java.util.*;
import static java.lang.Math.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
public class A {
static class pair implements Comparable<pair> {
int x;
int y;
public pair(int d, int k) {
x = d;
y = k;
}
@Override
publi... | 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() {
ios_base::sync_with_stdio(false);
int n;
string s;
cin >> n;
cin >> s;
int count = 1;
for (int i = 1; i < n; i++) {
if (s[i] != s[i - 1]) count++;
}
cout << min(n, count + 2) << 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 | import java.io.*;
import java.util.*;
public class alternativethinking {
private static InputReader in;
private static PrintWriter out;
public static void main(String[] args) throws IOException {
in = new InputReader(System.in);
out = new PrintWriter(System.out, true);
int n = in.nextInt();
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 | n = int(input())
s = input()
cnt = 1
last = s[0]
for i in range(1, len(s)):
if s[i] != last:
cnt += 1
last = s[i]
if s.count('111') or s.count('000') or s.count('00')+s.count('11') > 1:
print(cnt+2)
elif s.count('11')+s.count('00'):
print(cnt+1)
else:
print(cnt) | 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;
long long n, prv[100005][2];
bool a[100005];
long long dp[100005][3];
long long solve(long long i, long long flip) {
if (i == -1) return 0;
if (dp[i][flip] == -1) {
long long ans = 0;
long long prev_op = prv[i][!a[i]], prev_same = prv[i][a[i]];
if (flip == 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 | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package codeforces334;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @auth... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
int n;
char d[100001];
int main() {
int i, r;
scanf("%d%s", &n, d);
r = 1;
for (i = 0; i + 1 < n; i++) {
if (d[i] != d[i + 1]) r++;
}
if (r == n) {
} else if (r == n - 1) {
r++;
} else {
r += 2;
}
printf("%d", r);
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 int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double EPS = 1e-8;
using namespace std;
const int N = 100005;
char bin[N];
int dp[N][2][2];
int max(int a, int b, int c) { return max(a, max(b, c)); }
int main() {
int n;
while (cin >> n) {
scanf("%s", &bin);
dp[0][0][0... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 |
import java.io.*;
import java.util.*;
public class contest {
static HashMap<String,Integer> map = new HashMap<>();
static int gcd(int a,int b){
if(a==0){
return b;
}
return gcd(b%a,a);
}
public static void main(String[] args) {
FastReader sc = new FastReader... | 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 mod = 1e9 + 7;
const int inf = 1e9 + 10;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, c = 1;
string s;
cin >> n;
cin >> s;
for (int i = 1; i <= n - 1; i++) {
if (s[i] != s[i - 1]) c++;
}
if (c + 2 <= n)
cout << c + 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 | # -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll
n = int(raw_input())
s = raw_input()
two = {"0":0, "1":0}
three = False
cur = s[0]
cnt = 1
ans = 1
for si in s[1:]:
if si == cur:
cnt += 1
if cnt == 2:
two[si] += 1
if cn... | 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;
char digits[100002];
int lasBeforeChangeWithZero[100002];
int lasBeforeChangeWithOne[100002];
int lasDuringChangeWithZero[100002];
int lasDuringChangeWithOne[100002];
int lasAfterChangeWithZero[100002];
int lasAfterChangeWithOne[100002];
int main() {
scanf("%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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
InputReader in = new InputReader(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;
const long long md = 1e9 + 7;
long long movesx[8] = {-1, 0, 1};
long long movesy[8] = {-1, 0, 1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long 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 | import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int n =in.nextInt();
String resultados = in.next();
int res =1;
for(int i=1;i < n;i++){
if(resultados.charAt(i)==resultados.charAt(i-1))
... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char a[100005];
cin >> n;
scanf("%s", a);
int num = 1;
for (int t = 1; t < n; t++) {
if (a[t] != a[t - 1]) {
num++;
}
}
if (num + 2 < n) {
printf("%d\n", num + 2);
} else {
printf("%d\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=input()
a=raw_input()
c=1
s=0
for i in range(1,n):
if a[i]!=a[i-1]:
c+=1
print min(n,c+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;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
string s;
cin >> s;
long long len = 1;
for (long long i = 1; i < n; i++)
if (s[i] != s[i - 1]) len++;
cout << min(len + 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;
long long inf = 1e18;
long long mod = 1e9 + 7;
long long delta = 10289;
const long long M = 320;
long long dp[M * M][M];
long long a[M * M];
int main() {
long long n;
cin >> n;
char c, v;
cin >> v;
long long a = 0, b = 0;
for (long long i = 1; i < n; i++) {
... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int N;
string s;
int main() {
scanf("%d\n", &N);
cin >> s;
if (N == 1) {
cout << 1 << endl;
return 0;
}
if (N == 2) {
cout << 2 << endl;
return 0;
}
int ans = 1;
for (int i = 1; i < N; i++)
if (s[i] != s[i - 1]) ans++;
if (ans == 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 | //package alternativethinking;
import java.util.*;
import java.io.*;
public class alternativethinking {
public static void main(String[] args) throws IOException {
//was thinking that we first remove the longest subsequence of alternating 1s and 0s.
BufferedReader fin = new BufferedReader(new InputStreamRe... | 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 ans = 0;
int l = s.length();
int res = 0;
for (int i = 0; i < l - 1; i++) {
if (s[i] != s[i + 1]) {
res++;
}
}
for (int i = 0; i < l - 1; i++) {
if (s[i] == s[i + 1]) {
ans = 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;
typedef pair<long long, long long> ll;
typedef vector<long long> vl;
typedef vector<ll> vll;
typedef vector<vl> vvl;
template <typename T>
ostream &operator<<(ostream &o, vector<T> v) {
if (v.size() > 0) o << v[0];
for (unsigned i = 1; i < v.size(); i++) o << " " << v[i... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
char s[100005];
int f[100005][2][3];
int main() {
int n;
scanf("%d", &n);
scanf("%s", s + 1);
for (int i = 1; i <= n; ++i) {
int t = s[i] - 48;
f[i][t][0] = f[i - 1][t ^ 1][0] + 1;
f[i][t ^ 1][0] = f[i - 1][t ^ 1][0];
f[i][t][1] = max(f[i - 1][t ^ 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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class... | 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 CF334C{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int n = sc.nextInt();
sc.nextLine();
... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
int ans = 1;
for (int i = 1; i < n; i++)
if (s[i] != s[i - 1]) ans++;
int count = 0;
for (int i = 1; i < n; i++)
if (s[i] == s[i - 1]) count++;
cout << ans + min(2, count);
return 0;
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.io.*;
import java.util.*;
public class Mohammad {
public static void Mohammad_AboHasan() throws IOException{
FastScanner fs = new FastScanner();
int n = fs.nextInt(), c = 1;
String s = fs.next();
for (int i = 0; i < n-1; i++) {
c += s.charAt(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 | #include <bits/stdc++.h>
using namespace std;
const long long int N = 200005;
const long long int mod = 1e9 + 7;
long long int dp[200005][2][3];
long long int n;
char s[200005];
long long int A[N], B[N];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
long long int i... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | 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;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<pair<int, int> > v;
int nu = s[0] - '0';
int c = 0;
for (int i = 0; i < n; i++) {
if (nu == (s[i] - '0'))
c++;
else {
v.push_back({nu, c});
c = 1;
nu = s[i] - '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 flip(std::string const& seq) {
int count = 1, check = 0;
for (int i = 1; i < seq.size(); i++) {
if (seq[i] != seq[check]) {
count++;
check = i;
}
}
if (count == seq.size()) {
return count;
} else if (count <= seq.size() - 2) {
return count += 2;
} els... | 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;
char a[n + 10];
scanf("%s", a);
if (n == 2) {
cout << 2;
return 0;
}
if (n == 3) {
cout << 3;
return 0;
}
if (n == 5 && a[0] == '0' && a[1] == '0' && a[2] == '1' && a[3] == '0' &&
a[4] == '0') {
cout ... | 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 | n = int(raw_input())
s = str(raw_input())
point1 = None
point2 = None
score = 1
c = s[0]
for i in xrange(1, n):
if s[i] != c:
score += 1
c = s[i]
for i in xrange(1, n):
if s[i-1] == s[i]:
if point1 is None:
point1 = i
else:
point2 = i
break
... | 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;
string s;
int main() {
int n;
cin >> n;
int i;
cin >> s;
int net = 1;
for (i = 0; i < n - 1; i++) {
if (s[i] != s[i + 1]) {
net++;
}
}
net = min(net + 2, n);
cout << net << 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 | def getinput():
return map(int, raw_input().split())
def func(n, binstr):
t = binstr[0]
ans = 1
maxp = 1
p = 1
flag = [0, 0]
for i in xrange(1, n):
if t == binstr[i]:
flag[int(t)] = 1
p += 1
maxp = max(maxp, p)
else:
ans += 1
... | PYTHON |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
impo... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | 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 = int(input())
s = input()
print(min(n, 3 + s.count('01') + s.count('10'))) | 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 | __author__ = 'Utena'
n=input()
s=input()
t=[]
def alt(a):
b=''
b+=a[0]
for i in a[1:len(a)]:
if i!=b[-1]:
b+=i
return b
m=len(alt(s))
judge=0
for i in range(len(s)-1):
if s[i+1]==s[i]:
judge=1
if i<len(s)-2:
for j in range(i+1,len(s)-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() {
int n;
string s;
cin >> n >> s;
int cnt = 1;
char curr = s[0];
for (int i = 1; i < n; i++)
if (s[i] != curr) curr = s[i], cnt++;
cout << min(n, cnt + 2);
return 0;
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 |
import java.io.*;
import java.util.*;
import java.math.*;
public class Main implements Runnable {
public InputReader in;
public PrintWriter out;
public void solve() throws Exception {
// solution goes here
int N = in.nextInt();
char[] chars = in.nextChars();
N = chars.leng... | 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.PrintStream;
import java.util.Arrays;
import java.util.StringTokenizer;
import static java.lang.Math.max;
/**
* 603A
*
* @author artyom
*/
public class AlternativeThinking implements Runnable {
private ... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
string s;
int n;
int main() {
cin >> n >> s;
for (int i = 1; i <= n; ++i) a[i] = s[i - 1] - '0';
int ans = 1;
int pre = a[1];
for (int i = 2; i <= n; ++i) {
if (a[i] != pre) {
pre = a[i];
ans++;
}
}
printf(... | 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.*;
/**
* Made by egor https://github.com/chermehdi/egor.
*
* @author Azuz
*
*/
public class Main {
int[][][] dp;
char[] arr;
int n;
void solve(Scanner in, PrintWriter out) {
n = in.nextInt();
arr = in.next().toCharArray();
dp = new int[n]... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | n=int(input())
s=input()
k=0
i=0
r=int(s[0])
while(i<n):
if(int(s[i])==r):
r=1-r
k+=1
i+=1
print(min(k+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 | // created by 我不知道我是谁
import java.io.*;
import java.util.*;
public class scratch_18{
static class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamRead... | 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.math.BigInteger;
import java.util.*;
public class Main {
public static InputReader in;
public static PrintWriter pw;
public static void main(String args[]) {
new Thread(null, new Runnable() {
public void run() {
try{
solv... | 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())
string=str(raw_input())
ans=1
prev=string[0]
for j in range(1,n):
if(string[j]!=prev):
ans+=1
prev=string[j]
temp=0
for j in range(1,n):
if(string[j]==string[j-1]):
temp+=1
for k in range(j+1,n):
if(string[k]==string[k-1]):
temp+=1
... | PYTHON |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.io.*;
import java.util.*;
public class alternativethinking {
private static InputReader in;
private static PrintWriter out;
public static void main(String[] args) throws IOException {
in = new InputReader(System.in);
out = new PrintWriter(System.out, true);
int n = in.nextInt();
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>
#pragma GCC optimize(2)
using namespace std;
const int maxn = 1e6;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const double eps = 1e-7;
const double Pi = acos(-1.0);
inline int read_int() {
char c;
int ret = 0, sgn = 1;
do {
c = getchar();
} while ((c < '0' || c > '9') && 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.io.*;
import java.util.ArrayList;
import java.util.InputMismatchException;
/**
* Created by Shreyans Sheth [bholagabbar] on 12/8/2015 at 3:01 PM using IntelliJ IDEA (Fast IO Template)
*/
public class AlternativeThinking_604_C
{
public static void main(String[] args) throws Exception
{
//... | 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, res;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
res = 1;
for (int i = 1; i < n; ++i) {
if (s[i] != s[i - 1]) ++res;
}
cout << min(n, res + 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;
template <typename T>
T in() {
char ch;
T n = 0;
bool ng = false;
while (1) {
ch = getchar();
if (ch == '-') {
ng = true;
ch = getchar();
break;
}
if (ch >= '0' && ch <= '9') break;
}
while (1) {
n = n * 10 + (ch - '0');
... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
void run() throws Exception {
//// sample program begins here
// int a, b;
// a = nextInt();
// b = nextInt();
// out.println(a + b);
int n = nextInt();
String str = next();
int len ... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.io.*;
import java.util.*;
public class AlternateThink{
public static void main(String[]args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new St... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | from sys import stdin
length = int(stdin.readline().rstrip())
scores = stdin.readline().rstrip()
doubles_found = 0
score = 1
for i in range(length-1):
if scores[i] != scores[i+1]:
score += 1
else:
if doubles_found < 2:
score += 1
doubles_found +=1
print(score)
| 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 | n = int(input())
s = input()
num = 1
for i in range(1,n):
if s[i] != s[i-1]:
num += 1
print(min(n,num+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;
struct IO {
IO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
} _;
int n, m, len, k, t, a, b;
int main() {
string s;
cin >> n >> s;
char prev = s[0];
int a = 0, b = 1;
for (int i = 1; i <= n - 1; i++) {
if (s[i] == s[i - 1]) a++;
... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.util.*;
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
BufferedReader br = new BufferedReader(new InputStrea... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
vector<int> nums;
char last = s[0];
int numk = 0;
for (int i = 0; i < n; i++) {
if (last == s[i])
numk++;
else {
nums.push_back(numk);
last = s[i];
numk = 1;
}
}
nums.push_bac... | 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;
int n, f[N], len;
char s[N];
int main() {
cin >> n >> s + 1;
int cnt = 1;
for (int i = 2; i <= n; i++) {
if (s[i] == s[i - 1])
cnt++;
else {
len++;
cnt = 1;
}
}
len++;
cout << min(len + 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 | import sys
n = int(input())
s = input()
p = s[0]
ans = 1
for i in range(1,n):
if s[i] != p:
ans += 1
p = s[i]
if (0 <= s.find("00") < s.rfind("00")) or (0 <= s.find("11") < s.rfind("11")) or (0 <= s.find("11") < s.rfind("00")) or (0 <= s.find("00") < s.rfind("11")):
ans += 2
elif s.find("00"... | 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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
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;
const int maxn = 2e6 + 5;
int n;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
string s;
cin >> s;
int ans = 0;
stack<int> st;
int id = 0;
for (int i = 0; i < n; i++) {
if (st.size() == 0 || st.top() != s[i]) {
st.push(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 | # cook your dish here
n=int(input())
s=list(input())
l=[]
c=1
for i in range(1,n):
if s[i]==s[i-1]:
c=c+1
else:
if c>=2:
l.append(c)
c=1
if c>=2:
l.append(c)
inc=0
if len(l)>1:
inc=2
elif len(l)==1:
if l[0]>=3:
inc=2
elif l[0]==2:
inc=1
a1,a2=0... | PYTHON3 |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n;
char in[100005];
int main() {
scanf("%d %s", &n, in);
for (int i = 1; i < n; i++) {
if (in[i] == in[i - 1]) {
for (int j = i;; j++) {
in[j] = 1 - (in[j] - '0') + '0';
if (in[j + 1] != in[j]) break;
}
break;
}
}
char p... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class C {
public static void main(String[] args) throws Exception {
new C().run();
out.close();
}
void run() throws Exception {
int ... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
void solve();
signed main() {
int t = 1;
while (t--) solve();
return 0;
}
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
char t;
cin >> t;
a[i] = t - '0';
}
int l = 1;
int prev = a[0];
int mx = 1;
for (int... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n, x, y;
string s;
int main() {
cin >> n >> s;
for (int i = 1; i < n; ++i) {
x += s[i] != s[i - 1];
y += s[i] == s[i - 1];
}
cout << x + min(y, 2) + 1 << endl;
return 0;
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.util.Scanner;
public class App
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
String s=sc.nextLine();
int answer=0;
for(int i=0;i<s.length()-1;i++)
{
if(s.charAt(i)!=s.charAt(i+1))
answer+=1;
}
answer++;
System... | 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() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, ans = 1, i;
cin >> n;
string s;
cin >> s;
for (i = 0; i < s.length() - 1; i++) {
if (s[i] != s[i + 1]) ans++;
}
ans = min(n, ans + 2);
cout << ans << "\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;
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
long long i, j, n, m;
cin >> n;
string s;
cin >> s;
long long dp[n + 1][2];
memset(dp, 0, sizeof(dp));
for (i = 1; i <= n; i++) {
if (s[i - 1] == '0') {
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | n = int(input())
s = input()
x = 0
y = 1
for i in range (n - 1):
if s[i] == s[i + 1]:
x += 1
if s[i] != s[i + 1]:
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N = 0;
cin >> N;
string results;
cin >> results;
N = results.size();
auto prec = results.at(0);
int changes = 0, equals = 0;
for (int i = 1; i < N; i++) {
auto next = results.at(i);
if (next != prec) {
changes++;
} else {
... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
signed main() {
long long n, i, x = 0, c = 1;
cin >> n;
string s;
cin >> s;
for (i = 1; i < s.size(); i++) {
if (s[i - 1] != s[i]) c++;
}
cout << min(c + 2, n);
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | n=int(input())
s=input()
print(min(n,3+s.count("01")+s.count("10"))) | 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;
struct __s {
__s() {
if (1) {
ios_base::Init i;
cin.sync_with_stdio(0);
cin.tie(0);
}
}
~__s() {
if (!1)
fprintf(stderr, "Execution time: %.3lf s.\n",
(double)clock() / CLOCKS_PER_SEC);
long long n;
cin >> 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.util.*;
import java.io.*;
public class CodeForces {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
int n = Reader.nextInt();
String s = Reader.next();
arr = new int[n];
dp = new int[n][3][3];
for (int i = 0; ... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
char x, y;
int ctr = 0;
int eq = 0;
cin >> x;
for (int i = 1; i < n; i++) {
cin >> y;
if (x != y)
ctr++;
else
eq++;
x = y;
}
if (eq >... | 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 | """
Code of Ayush Tiwari
Codeforces: servermonk
Codechef: ayush572000
"""
# import sys
# input = sys.stdin.buffer.readline
def solution():
n=int(input())
s=input()
ans=1
for i in range(1,n):
if s[i]!=s[i-1]:
ans+=1
print(min(n,ans+2))
solution() | 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;
map<int, int> mp;
int main() {
int n, ad = 0, ans = 0;
string s;
cin >> n;
cin >> s;
for (int i = 0; i < n; i++) {
if (i == 0) {
ans = 1;
continue;
}
if (s[i] != s[i - 1])
ans++;
else
ad++;
}
ad = min(ad, 2);
cout << 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;
char a[222222];
int main() {
int n, b = 0, s = 0;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
if (a[i] == a[i + 1])
b++;
else
s++;
}
cout << s + min(2, b) << 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;
int n, a[100010], l[100010], r[100010], ans, f1[100010][2], f2[100010][2];
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
char x;
cin >> x;
if (x == '0')
a[i] = 0;
else
a[i] = 1;
}
l[1] = 1;
f1[1][a[1]] = 1;
for (int i = 2; i <... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
long long int n;
void solve() {
cin >> n;
string s;
cin >> s;
int ccnt = 1;
vector<long long int> seg;
for (int i = 1; i < n; i++) {
if (s[i] == s[i - 1])
ccnt++;
else {
seg.push_back(ccnt);
ccnt = 1;
}
}
seg.push_back(ccnt);
... | 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.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.ObjectInputStream.GetField;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.In... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.StringTokenizer;
import static java.lang.Math.max;
/**
* 603A
*
* @author artyom
*/
public class AlternativeThinking implements Runnable {
private ... | 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 PC {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Communication S=new Communication();
int n=S.i();
char[] c=S.cs();
int[] l=new int[c.length];
for(int i=0;i<n;i++){
if(c[i]=='0'){
l[i]=0;
... | JAVA |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
char str[101000];
int arr[101000];
int n;
int memo[101000][4][4];
int base[101000][4][4];
int solve(int idx, int d, int k) {
int i, j;
if (idx == n) {
return 0;
}
if (base[idx][d][k] == 1) return memo[idx][d][k];
base[idx][d][k] = 1;
i = idx;
while (i < n ... | CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n;
cin >> s;
int prev;
int ans = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] != prev || i == 0) ans++, prev = s[i];
}
ans = min(n, ans + 2);
cout << ans << "\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 long long int MAX = 1e7 + 7;
const long long int MOD = 1000000007;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
void read(long long int n, vector<long long int> &v) {
for (long long int i = 0; i < n; i++) cin >> v[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.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
public static void main(String[] args) {
// Test.testing();
ConsoleIO io = new ConsoleIO();
new Main(io).solve();
io.flush();
}
ConsoleIO io;
... | 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 c {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();int ans = 1;
String line = scan.next();
char bit = line.charAt(0);
for (int i=1;i<N;i++)
if (line.charAt(i)!=bit){
bit=(bit=='0')?'1':'0';
ans++;
}
... | 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
#sys.stdin = open('in')
n = int(raw_input())
s= raw_input()
p1 = 0
p0 = 0
lp1 = 0
lp0 = 0
res = 1
i = 1
while i < len(s):
if s[i] != s[i-1]:
res += 1
i += 1
else:
if s[i] == '0':
p0 += 1
l = 1
while i < len(s) and s[i] == s[i-1]:
... | PYTHON |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | n=int(input())
s=input()
ans=0
a=0
b=0
if s[0]=='0':
flag='0'
else:
flag='1'
for i in range(n):
if i>0 and s[i]==s[i-1]:
a+=1
if s[i]==flag:
ans+=1
if flag=='0':
flag='1'
else:
flag='0'
ans+=min(a+b,2)
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 s[100010];
int n, ans, k;
int main() {
scanf("%d%s", &n, s);
ans = 1;
k = 0;
for (int i = 1; i < n; i++)
if (s[i] != s[i - 1])
ans++;
else
k++;
ans += min(k, 2);
printf("%d\n", ans);
return 0;
}
| CPP |
603_A. Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int s = 1, n = 0;
string a;
cin >> n >> a;
for (int i = 1; i <= n - 1; i++)
if (a[i] != a[i - 1]) s++;
s = min(s + 2, n);
cout << s;
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.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
public class CC {
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;
if (DP[alter][... | JAVA |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.