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
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 69; int n, m, a[maxn]; long long sum[maxn], res, cnt; void nhap() { for (int i = 1; i <= n; i++) cin >> a[i]; } void out() { for (int i = 1; i <= n + 1; i++) { if (a[i - 1] + 1 == a[i]) { if (i % 2) cnt++; continue; } if (i...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Scanner; public class VirtualContest { public static void main(String[] args) { // TODO Auto-generated method st...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
n,m=map(int,input().strip().split()) l=list(map(int,input().strip().split())) l.insert(0,0) l.append(m) lc=[] lo=[] on=0 off=0 lo.append([0,0]) for i in range(1,n+2): if (i%2==1): on=on+l[i]-l[i-1] else: off=off+l[i]-l[i-1] lo.append([on,off]) max1=on lc.append([on,off]) for i in range(1,n+2): if (i%2==1): on...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, n, m; cin >> n >> m; int a[n]; for (i = 0; i < n; i++) cin >> a[i]; vector<int> V; if (a[0] != 0) V.push_back(a[0]); for (i = 0; i < n - 1; i++) V.push_back(a[i + 1] - a[i]); if (a[n - 1] != m) { V.push_back(m - a[n - 1]); } ...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.io.*; import java.util.*; import java.text.*; import java.lang.*; import java.math.BigInteger; import java.util.regex.*; public class Myclass { public static ArrayList a[]=new ArrayList[100001]; public static boolean visited[]=new boolean [100001]; public static boolean visited1[]=new boolean [100001]...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
n,m=[int(x) for x in input().split()] s=[int(x) for x in input().split()] s.insert(0,0) l=[] if n==1: print(m-1) elif n%2==0: t=m-s[n] for i in range(n,0,-2): q=-t+s[i]-s[i-1] t=t-s[i]+2*s[i-1]-s[i-2] l.append(q) mega=max(l) origin=(t+m)//2 if mega>1: print(mega+o...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(mi()) n, M = mi() a = [0] + li() + [M] n = len(a) ans = 0 p = [0] * n q = [0] * n for i in range(1, n): p[i] = p[i - 1] q[i] = q[i - 1] if i % 2 == 0: p[i] += a[i] - a[i - 1] else: ...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
# -*- coding: utf-8 -*- """ Created on Tue Nov 3 14:16:56 2020 @author: 86133 """ n, m = map(int, input().split()) l = [[0 for i in range(4)] for j in range(10**5+5)] a = [int(i) for i in input().split()] l[0][0] = a[0] d = 1 for i in range(1, n): l[i][d] = a[i] - a[i-1] d = int(not d) l[n][d] = m-a[n-1] for...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> divisors; long long arr[100005], sumlon[100005], b[100005], sumloff[100005], sumron[100005], sumroff[100005]; int main() { int n; long long m; cin >> n >> m; int flag = 1; arr[0] = 0; b[0] = flag; for (int i = 1; i <= n; i++) { cin >> arr[i...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long n, m; cin >> n >> m; vector<long long> arr(n + 1); for (long long i = 0; i < n; i++) cin >> arr[i]; long long seg[n + 1]; seg[0] = arr[0]; for (long long i = 1; i < n; i++) seg[i] ...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; const int hashP = 239017; const int N = 1e5 + 10; const int MOD = 1e9 + 7; const int MOD2 = 998244353; const int INF = 1e9; const long long INF2 = 1e18; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> a; ...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
def main(): n, M = list(map(int, raw_input().split())) seq = [0] + list(map(int, raw_input().split())) + [M] seq = [seq[i + 1] - seq[i] for i in range(n + 1)] ret = [sum([seq[i] for i in range(n + 1) if i % 2 == 0])] seq = [seq[i] * ((-1) ** i) for i in range(n + 1)] s = 0 s0 = sum(seq) for i in range(n + 1): ...
PYTHON
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
n, M = map(int, input().split()) a = [0] + list(map(int, input().split())) + [M] b = [0] c = [0] s = 0 p = 0 for i in range(1, len(a)): if i % 2 == 0: s += a[i] - a[i - 1] b.append(s) else: p += a[i] - a[i - 1] c.append(p) m = len(b) s = 0 for i in range(1, len(a)): if i % 2 ...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; int a[100005]; int n; int M; int sum[100005][2]; int main() { scanf("%d%d", &n, &M); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); a[0] = 0, a[n + 1] = M; a[n + 2] = M; for (int i = 1; i <= n + 1; i++) { sum[i][1] = sum[i - 1][1]; sum[i][0] = sum[i - 1]...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Input...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.awt.Checkbox; import java.awt.Point; import java.io.*; import java.lang.reflect.Array; import java.math.*; import java.util.*; import java.util.Map.Entry; import javax.print.attribute.SetOfIntegerSyntax; import javax.swing.plaf.FontUIResource; pub...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu Nov 5 09:20:53 2020 @author: apple """ n,M=map(int,input().split(' ')) a=[0]+list(map(int,input().split(' ')))+[M] before=[0] after=[] op=1 be=0 af=0 out=[] ou=0 for h in range(0,n+1): ou-=(-1)**h*a[h] if n%2==0: ou+=M after.append(ou) out.app...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.io.*; import java.util.*; public class CFB { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; private static final long MOD = 1000L * 1000L * 1000L + 7; private static final int[] dx = {0, -1, 0, 1}; private static final int[] dy = {1, 0, -1, 0}; private...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String[] input = reader.readLine().split(" "); ...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; vector<long long int> v, w; int main() { long long int n, k; scanf("%lld%lld", &n, &k); v.push_back(0); for (long long int i = 0; i < n; i++) { long long int a; scanf("%lld", &a); v.push_back(a); } v.push_back(k); long long int sum = 0, sum2 = 0, m...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.io.*; import java.util.*; public class TaskB { public static void main(String[] args) { new TaskB(System.in, System.out); } static class Solver implements Runnable { int n, m; int[] arr; // BufferedReader in; InputReader in; PrintWriter out; void solve() throws IOException { n = in...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
n, m = map(int, input().split()) a = [0] + list(map(int, input().split())) + [m] b = [0] * (n + 2) for i in range(1, n + 2, 2): b[i] = a[i] - a[i - 1] for i in range(1, n + 2): b[i] += b[i - 1] ans = b[-1] for i in range(n + 2): if (i > 0 and a[i] > a[i - 1] + 1): x = b[i] + m - a[i] - (b[-1] - b[i]...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> const long long N = 1e6 + 100; const int D = 12541; const long long dd = 1e9 + 7; using namespace std; long long n, M, s1[N], s0[N], a[N], ans; int main() { cin >> n >> M; for (int i = 1; i <= n; i++) cin >> a[i]; a[n + 1] = M; for (int i = 1; i <= n + 1; i++) { if (i & 1) { s...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
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
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int num[2], sum[2]; bool v[maxn]; int a[maxn], s[maxn]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); s[i] = a[i] - a[i - 1]; v[i] = v[i - 1] ^ 1; sum[v[i]] += s[i]; } s[n ...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
n, m = list(map(int, input().split())) a = list(map(int, input().split())) a.insert(0, 0) a.append(m) n += 2 prev = [0]*n for i in range(1, n, 2): prev[i] = a[i] - a[i-1] # print(a) for i in range(1, n): prev[i] = prev[i-1] + prev[i] # print(prev) flip = [0]*n for i in range(1, n): j = n-1-i if (j%2 != 0...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
//package math_codet; import java.io.*; import java.util.*; public class lets_do { public static void main(String[] args) { InputReader in=new InputReader(System.in); StringBuffer str=new StringBuffer(); int n=in.nextInt(); long m=in.nextLong(); long[] arr=new long[n]; ...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = 1e5 + 10; int n, m, a[N]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9); cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; a[n + 1] = m; vector<int> pfs(n + 2, 0), pos(n +...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
n,M = map(int,input().split()) arr = list(map(int,input().split())) arr = [0] + arr + [M] l1 = [[0,0] for _ in range(n+2)] #on off flag = (n%2 > 0) val = 1 pos = -1 for i in range(n,-1,-1): l1[i][flag] += arr[i+1] - arr[i] + l1[i+1][flag] if flag == 0: flag = 1 else: flag = 0 l1[i][flag] = l1[i+1][flag] if(l...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-11; const double PI = 2 * acos(0.0); int main() { int n, M; int a[100007]; int f[2][100007]; cin >> n >> M; a[0] = 0; for (int i = 1; i <= n; i++) cin >> a[i]; a[n + 1] = M; memset(f, 0, sizeof f); for (int i = n; i >= 0; i--) { f...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; int ans, a[100012], b[100012], sum[100012]; int main() { int i, k = 0, n, m, flg = 1, ax = 0; scanf("%d %d", &n, &m); for (i = 1; i <= n; ++i) scanf("%d", &a[i]); a[0] = 0; a[++n] = m; for (i = 1; i <= n; ++i) { sum[i] = sum[i - 1] + flg * (a[i] - a[i - 1]);...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scan scan = new Scan(); int n = scan.scanInt(); long m = scan.scanLong(); long a[]=new long[n+2]...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
from itertools import* s=lambda:map(int,input().split()) n,m=s() a=[0,*s(),m,m] d=[x-y for x,y in zip(a[1:],a)] print(sum(d[::2])+max(1,*accumulate(d[i-1]-d[i]for i in range(n+n%2,0,-2)))-1)
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 1e5 + 10; using namespace std; int A[maxn]; int p[maxn]; int sum[2]; int bhd_sum[maxn]; int fot_sum[maxn]; int main() { int n, m; scanf("%d %d", &n, &m); A[0] = 0; int flag = 1; for (int i = 1; i <= n; i++) { sc...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.io.Writer; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author palayutm */ pub...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.util.*; public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); int n = console.nextInt();long m = console.nextLong(); List<Integer> a = new ArrayList<>(); a.add(0); for(int i = 0; i < n; i++) a.add(console.nextInt()); a.add((int)m); int f[][] =...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, M; cin >> n >> M; vector<long long> A(n + 1, 0); for (int i = 0; i < n; ++i) cin >> A[i + 1]; A.push_back(M); n += 2; vector<long long> S(n); for (int i = 0; i < n; ++i) { if (i % 2) ...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, m; cin >> n >> m; long long on[n + 2]; long long is[n + 1]; int inst[n + 2]; is[0] = 1; int pval = m; inst[0] = 0; for (int i(1); i <= n; i++) { cin >> inst[i]; if (is[i - ...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
n,m = map(int,input().split()) aprogram=[0]+list(map(int,input().split()))+[m] interval=[] total=0 a=0 sumbrightbefore=[0 for i in range(n+1)] sumdimafter=[0 for i in range(n+1)] for i in range(1,len(aprogram)): interval+=[aprogram[i]-aprogram[i-1]] for i in range(2,len(interval),2): sumbright...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.text.SimpleDateFormat; import java.util.*; import sun.java2d.pipe.SpanShapeRenderer.Simple; public class A_GENERAL { public static void main(String[] args) { MyScanner sc = new ...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
n,m = arr = map(int,raw_input().split()) arr = map(int,raw_input().split()) arr = [0] + arr + [m] summ = list() currState = n%2 prev = 0 curr = 0 minS = 9999999999 minInd = -1 i = n onTime =0 ofTime = 0 while(i>=0): if(currState): ofTime += (arr[i+1] - arr[i]); curr = prev + -1*(arr[i+1] - arr[i]) ...
PYTHON
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int N = (int)1e6 + 7, mod = 1000000007, M = 2e9; int n, s[N], r[N], a[N], v1, v2, m, mx; int clc(int i) { if ((i && a[i] - 1 != a[i - 1]) || (i <= n && a[i] + 1 != a[i + 1])) return s[i] + v2 - r[i] - 1; return 0; } int main() { c...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
n,m=map(int,raw_input().split()) li=map(int,raw_input().split()) ki=[li[0]] bad=0 good=li[0] for i in range(n-1): ki.append(li[i+1]-li[i]) if(i%2==0): bad+=li[i+1]-li[i] else: good+=li[i+1]-li[i] ki.append(m-li[n-1]) if(n%2!=0): bad+=m-li[n-1] else: good+=m-li[n-1] g=0 for i in range...
PYTHON
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.awt.Point; import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static int v,e; static ArrayList<Integer> adjList[]; static boolean[] vis; static int numv; public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Scanner sc = new...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#1000B. Light It Up #greedy, 1500, https://codeforces.com/problemset/problem/1000/B n, m = map(int, input().split()) l = [*map(int, '0 {} {}'.format(input(), m).split())] s = [l[i+1] - l[i] for i in range(len(l) - 1)] t = sum(s[1::2]) + s[0] - 1 r = max((sum(s[::2]), t)) for i in range(2, len(s), 2): t = t - s[i - 1...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
f=lambda:map(int,input().split()) n,m=f() a=list(f()) a=[0]+a+[m] time_int,light,dark=[],0,0 for i in range(len(a)-1): t=a[i+1]-a[i] time_int.append(t) if i % 2==0: light+=t else: dark+=t left_light=0 for i in range(len(time_int)): if i % 2 != 0: dark-=time_int[i] if le...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, -1}, {-1, 1}}; const int mod = 1e9 + 7, gakki = 5 + 2 + 1 + 19880611 + 1e9; const int MAXN = 2e5 + 5, MAXM = 2e5 + 5, N = 2e5 + 5; const int MAXQ = 100010; inline void re...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; long long arr[maxn]; bool state[maxn]; long long sum1[maxn] = {0}; long long sum2[maxn] = {0}; int main() { int f = 1; int n, m; cin >> n >> m; arr[0] = 0; for (int i = 1; i <= n; i++) { cin >> arr[i]; if (f == 1) { sum1[i] ...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.util.Scanner; public class B1000 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(), M = in.nextInt(), i, maxLit, rs, re; int[] a = new int[n + 2], litTime = new int[n + 2]; boolean on = true; for(i = 1; i <= n; i++) { a[i] = in.nextInt(...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m; int a[N], prf[N]; int res = 0; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; a[n + 1] = m; for (int i = 0; i <= n; ++i) { if (i) prf[i] = prf[i - 1];...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> a(n); vector<long long> f1; vector<long long> f2; long long sum1 = 0; long long sum2 = 0; long long mx = 0; f1.push_back(0); f2.push_back(0); ...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
n,M=map(int,input().split()) a=[0] a+=list(map(int,input().split())) a.append(M) intervals=[0] for i in range(1,len(a)): intervals.append(a[i]-a[i-1]) intervalsodd=[] intervalseven=[] for i in range(1,len(intervals)): if i%2==1: intervalsodd.append(intervals[i]) else: intervalseven.append(i...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Nov 7 23:46:23 2020 @author: adam_lyy """ n,M=map(int,input().split()) a=[0]+list(map(int,input().split()))+[M] t=0 for k in range(1,len(a),2): t+=a[k]-a[k-1] s=-t+a[1]-1+M t=max(s,t) for i in range(3,n+1,2): s=s+a[i-2]-2*a[i-1]+a[i] if a[...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.util.*; public class Main { long getSolution(int[] points, int m){ long[] cumSum = new long[points.length]; for(int i = cumSum.length - 1; i >= 0; i--){ if(i == cumSum.length - 1){ if(i % 2 == 1){ cumSum[i] = m - points[i]; ...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#include <bits/stdc++.h> using namespace std; const int maxN = 1e5 + 5; int n, m; int a[maxN]; int f[maxN]; void ReadInput() { cin >> n >> m; f[0] = a[0] = 0; a[n + 1] = m; for (int i = 1; i <= n + 1; i++) { if (i <= n) cin >> a[i]; f[i] = i % 2 == 0 ? f[i - 1] : f[i - 1] + a[i] - a[i - 1]; } } void S...
CPP
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.io.*; import java.util.*; /* * Heart beats fast * Colors and promises * How to be brave * How can I love when I am afraid... */ //read the question correctly (is y a vowel? what are the exact constraints?) //look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) //always declare multidime...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
#light it up n,m=map(int,input().split()) l=[int(x) for x in input().split()] j=0 b=[0]*(n+1) b[0]=l[0] for i in range(0,n-1): b[i+1]=b[i]+(-1+2*(i%2))*(l[i+1]-l[i]) b[-1]=b[n-1]+(1-2*(n%2))*(m-l[-1]) print(max((b[-1]+m)//2,(m+2*max(b)-b[-1]-1)//2))
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
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
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.util.*; import java.io.*; public class Main { static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader fileReader) { br = ...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { private static long[][] sum2 = new long[100010][10]; public static void main(String[] args) { Scanner scan = new Scanner(System.in); int i , j , n = scan.nextInt() , m = scan.nex...
JAVA
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
n,m=map(int,input().split()) a=[int(x) for x in input().split()] a.insert(0,0) def count(data): k=m*(1+(-1)**(len(data)+1))/2 for i in range(len(data)): k+=(-1)**(i%2+1)*data[i] return k b=[count(a)] a.insert(1,a[1]-1);k=count(a) if a[1]-1>1: b+=[k] del a[1] for i in range(n+n%2-1): if i%2==...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
n,M=map(int,input().split()) list=input().split() list=[int(x) for x in list] list.append(0) list.append(M) list.sort() onesum=[] anothersum=[] time=[] for i in range(1,n+2,2): onesum.append(list[i]-list[i-1])#a1-0,a3-a2... if i<n+1: anothersum.append(list[i+1]-list[i])#M-an,a(n-1)-a(n-2)... nochange=su...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
n, M = map(int, input().split()) A = [0] + list(map(int, input().split())) + [M] total_on = 0 for i, a in enumerate(A): if i%2: total_on += a - A[i-1] on = [[M-total_on]*(n+2), [total_on]*(n+2)] for i in range(1, n+2): sw = i%2 on[sw][i] = on[sw][i-1]-(A[i]-A[i-1]) on[1-sw][i] = on[1-sw][i-1]...
PYTHON3
1000_B. Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ...
2
8
import java.util.Arrays; import java.util.Scanner; public class B1000Light { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(), m = in.nextInt(); int[] nums = new int[n + 2]; nums[n + 1] = m; for (int i = 1; i <= n; i++) { ...
JAVA
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
import sys s = input() n = len(s) if n == 1: print(1) sys.exit(0) for i in range(n-1): if s[i] == s[i+1] and (s[n-1] != s[0]): x = s[:i+1] y = s[i+1:n] s = x[::-1] + y[::-1] ans = 1 mx = 1 for i in range(1, n): if s[i] != s[i-1]: mx += 1 else: ans = max(mx, ans) mx = 1 print(max(mx, ans))
PYTHON3
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; string s; int m = 0, l = 1; void rd(int &); void wrt(int); int main() { cin >> s; s += s; s += s[s.size() - 1]; for (int i = 1; i <= (s.size() - 1); ++i) if (s[i - 1] != s[i]) ++l; else m = max(m, l), l = 1; m = min(m, (int)s.size() / 2); cou...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
import java.util.*; public class prac { static Scanner sc=new Scanner(System.in); public static void main(String args[]) { StringBuffer s=new StringBuffer(sc.nextLine()); int j=s.length()-1; int len=s.length(); while(j>=1 && s.charAt(0)!=s.charAt(len-1)) { if(s.charAt...
JAVA
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class PlasticineZebra { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); int str...
JAVA
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
/* 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 ...
JAVA
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, i, j = 1, j1 = 1, j2 = 0, j3, k, h = 1; string s; cin >> s; for (i = 1; i < s.length(); ++i) { if (j1 < h) j1 = h; if (h == s.length()) break; if (s[i - 1] != s[i] && i !=...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
s = input() n = len(s) dp = [1] * n cur = s[-1] end = n - 1 for i in range(n-1): if s[i] == cur: end = i break cur = s[i] dp[n-1] = end + 1 res = dp[n-1] for i in range(n-2, -1, -1): if s[i] != s[i+1]: dp[i] = min(n, 1 + dp[i + 1]) res = max(dp[i], res) #print(i, s[i], dp...
PYTHON3
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; inline void upd(int &x, int y) { x < y && (x = y); } const int N = 150005; string s; int main() { cin >> s; int n = s.size(); if (n == 1) { cout << 1 << endl; return 0; } int res = 1, ans = 0; char last = s[0]; for (int i = 1; i < n; ++i) { if (las...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; int n; char a[200010]; int main(void) { int i, j, ans = 0; scanf("%s", a + 1); n = strlen(a + 1); for (i = 1; i <= n; i++) a[i + n] = a[i]; for (i = 1; i <= 2 * n; i = j) { for (j = i + 1; j <= 2 * n; j++) { if (a[j] == a[j - 1]) break; ans = max(a...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.length(); s += s; int ans = -1; int len = 1; for (int i = 1; i < 2 * n; i++) { if (s[i] != s[i - 1]) len++; else { if (len <= n) ans = max(len, ans); len = 1; } } if (len <= n) ans = ...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int mod = 1e9 + 7; const int inf = 0x3fffffff; int main() { std::ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int i, ans, t; string s; cin >> s; s += s; ans = t = 1; for (i = 1; i < s.size(); ++i) { if (s[i] == s...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
def cl(s): l = [s[0]] mx = [] c = 1 for i in s[1:]: #print(l) if(i!=l[-1]): c+=1 l.append(i) else: mx.append(c) c = 1 l = [i] mx.append(c) #print(mx) return max(mx) sl = [i for i in input()] ls = len(sl) if...
PYTHON3
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; import java.io.*; import java.lang.*; //import java.awt.Point; //import javafx.util.Pair; // Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail public class TestClass { public static voi...
JAVA
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
//package cf; import java.io.*; import java.util.*; public class Temp_Class { static int p=1000000007; public static void main(String[] args) throws Exception{ BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512); FastR...
JAVA
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; const int NMAX = 1e5 + 2; int n, utile[NMAX]; string s, sRev; int travail(string chaine) { bool d = true; int id = 0, maximum = -1, debut, fin, streak; while (n > id) { streak = 1; id++; while (n > id && chaine[id] != chaine[id - 1]) { streak++; ...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; long long vis[200005]; long long n, ans, dns; string s; long long dfs(int x) { long long ans = 1, r = (x + 1) % n, l = (x - 1 + n) % n; vis[x] = 1; if (!vis[r] && s[r] != s[x]) { ans += dfs(r); } if (!vis[l] && s[l] != s[x]) ans += dfs(l); return ans; } int ...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
import java.util.Scanner; public class C { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); System.out.println(maxlen(s)); } static int maxlen(String s) { int len = s.length(); int max = 0; int cur = 1; ...
JAVA
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 30; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); string s; cin >> s; int n = s.size(); int pref = 0, suf = n - 1; while (pref < n - 1 && s[pref] != s[pref + 1]) pref++; while (suf > 0 && s[suf] != s[suf - 1]) su...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
import java.util.Scanner; public class PlasticineZebra { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String k = scan.next(); int longest = k.length(); k += k; char[] q = k.toCharArray(); int max = 1; int j = 1; char...
JAVA
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
import java.io.*; import java.util.*; public class A { public static void main(String[] args) throws IOException { /*BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); StringTokenizer ...
JAVA
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; int f[555555]; int ans = 0; char s[555555]; int main() { int n, i; scanf("%s", s + 1); n = strlen(s + 1); for (i = n + 1; i <= 2 * n; i++) s[i] = s[i - n]; for (i = 1; i <= 2 * n; i++) { f[i] = 1; if (s[i] != s[i - 1]) f[i] += f[i - 1]; ans = max(ans, ...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; int main() { string sh; int n; int i; int ans = 0, num = 1; cin >> sh; n = sh.length(); sh = sh + sh; for (i = 1; i < 2 * n; i++) { if (sh[i] != sh[i - 1]) num++; else num = 1; ans = max(ans, num); } if (ans > n) ans = n; cout <...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
s=input() n=len(s) s=[s[i] for i in range(n)] s=s+s dp=[0]*(2*n) dp[0]=1 for i in range(1,2*n): if s[i]!=s[i-1]: dp[i]=dp[i-1]+1 else: dp[i]=1 print(min(n,max(dp)))
PYTHON3
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
import java.util.*; import java.io.*; public class File { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // If palindrome, cannot improve. String s = sc.next(); // Every split and reverse is just a shift of the string to the right. int N = s.length(); int in...
JAVA
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
s=input() s=s*2 l=[0]*len(s) l[0]=1 for i in range(1,len(s)): if s[i-1]!=s[i]: l[i]=l[i-1]+1 else: l[i]=1 print(min(max(l),int(len(s)/2)))
PYTHON3
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
z=list(input()) x=[] k=1 for i in range(len(z)-1): if z[i]!=z[i+1]: k+=1 else: x.append(k) k=1 if len(x)>0: if z[-1]!=z[0]: k+=x[0] x.append(k) else: x.append(k) else: x.append(k) print(max(x))
PYTHON3
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
import sys import math from collections import defaultdict,deque input = sys.stdin.readline def inar(): return [int(el) for el in input().split()] def toogle(char): if char=="b": return "w" else: return "b" def main(): string=input().strip() n=len(string) new=string+string a...
PYTHON3
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; const long long mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const double eps = 1e-9; char s[N]; int main() { scanf("%s", s); int l, r, ans, i; int len = strlen(s); for (l = 0; l <= len - 2; l++) { if (s[l] == s[l + 1]) break; } for (r =...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
N=list(input()) length=len(N) N=N+N+['x'] total=1 dummy=[] for i in range(1,len(N)): if N[i]!=N[i-1] and N[i]!='x': total+=1 else: dummy.append(total) total=1 for i in range(len(dummy)): if dummy[i]>length: dummy[i]=length print(max(dummy))
PYTHON3
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author iRawit */ public class Main { public static void main(String[] args) { InputStream in...
JAVA
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; template <typename T> inline void Int(T &n) { n = 0; int f = 1; register int ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0'; n = n * f; } template <typename T...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; const int mn = 2 * 1e5 + 123; int n; map<char, bool> was; string s; int pref[mn], suf...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int main() { string a; cin >> a; a = a + a; int n = a.length(); int ans = 1, cnt = 1; for (int i = 1; i < n; i++) { if (a[i] != a[i - 1]) { cnt++; } else { ans = max(ans, cnt); cnt = 1; } } ans = max(ans, ...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
# input_str = raw_input() # input_str_double = input_str+input_str # len_str_double = len(input_str_double) # ans =0 # j=0 # for i in range(1, len_str_double+1): # i = j # for j in range(i+1, len_str_double+1): # if input_str_double[j] == input_str_double[j-1]: # break # ans= max(ans, j-...
PYTHON
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
#include <bits/stdc++.h> using namespace std; int main() { string s = "0"; string x; cin >> x; s = s + x + x; int ans = 0; int temp = 0; for (int i = 1; i < s.size(); i++) { (s[i] != s[i - 1]) ? temp++ : temp = 1; ans = max(ans, temp); } int len = x.size(); cout << min(len, ans) << endl; r...
CPP
1025_C. Plasticine zebra
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
2
9
import java.io.*; import java.util.*; public class Main { FastReader scn; PrintWriter out; String INPUT = ""; void solve() { String str = scn.next(); int n = str.length(); str = str + str; int cnt = 1, ans = 1; for (int i = 1; i < str.length(); i++) { if (str.charAt(i) != str.charAt(i - 1)) { cnt...
JAVA