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
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
def solution(): n = int(input()) c0 = 0 c1 = 0 l = list(map(int,input().split())) for i in range(n): a = l[i] if a == 0: c0 += 1 else: c1 += 1 if c0 >= c1 : print(c0) for i in range(c0): print(0,end = " ") elif c0 < ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for i in range(int(input())): n = int(input()) data = sum([int(x) for x in input().split()]) if data <= n // 2: print(n - data) print('0 ' * (n - data)) else: print((data // 2) * 2) print('1 ' * ((data // 2) * 2))
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
from collections import defaultdict import sys t = int(input()) for _ in range(t): n = int(input()) a = list(map(int,input().split())) cnt = [0,0] for x in a: cnt[x] += 1 if cnt[0] >= (n//2): print(cnt[0]) print("0 " * cnt[0]) else: print(cnt[1] - cnt[1] % 2) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
# Problem A t = int(input()) for test in range(t): n = int(input()) a = list(map(int, input().split())) count_1 = a.count(1) if count_1 <= n/2: a_ = [num for num in a if num == 0] else: a_ = [num for num in a if num == 1] if len(a_) % 2 != 0: del a_[0] print(l...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
# Author : Pratyaydeep↯Ghanta import io,os inp=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline inar=lambda: list(map(int,inp().split())) inin=lambda: int(inp()) inst=lambda: inp().decode().rstrip('\n\r') # Am I debugging, check if I'm using same variable name in two places _T_=inin() for _t_ in range(_T_): n=i...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t=int(input()) while t>0: n=int(input()) a=list(map(int,input().split())) one=0 zero=0 for i in range(n): if a[i]==0: zero+=1 else: one+=1 if zero>=one: print(n//2) for i in range(n//2): print("0",end=" ") print("") ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys input = sys.stdin.buffer.readline for _ in range(int(input())): N = int(input()) a = list(map(int, input().split())) x = a.count(0) y = N - x if x >= N // 2: print(x) print(*[0] * x) else: if y % 2: print(y - (y % 2)) print(*[1] * (y - (y % 2))) else: print(y) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; vector<long long int> g[100009]; long long int vis[100009]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int _; cin >> _; while (_--) { long long int n; cin >> n; long long int i; long long int a[n]; long long int ...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
class Read: @staticmethod def string(): return input() @staticmethod def int(): return int(input()) @staticmethod def list(delimiter=' '): return input().split(delimiter) @staticmethod def list_int(delimiter=' '): return list(map(int, input().split...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
test = int(input()) for q in range(test): n = int(input()) x = list(map(int,input().split())) y = [] if n==2: if x[0]!=x[1]: y.append(0) else: y.append(x[0]) y.append(x[0]) else: i = 0 while i<n: if i<n-1 and x[i]==x[i+1...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys input = sys.stdin.readline Q = int(input()) for _ in range(Q): N = int(input()) K = N//2 A = list(map(int, input().split())) ans = [] if A.count(0) >= K: ans = [0] * K else: if K%2 == 0: ans = [1] * K else: ans = [1] * (K+1) print(l...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import io import os import sys import math # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') fileno = sys.stdin.fileno() input = io.BytesIO( os.read(fileno, os.fstat(fileno).st_size) ).readline T = int(input()) for i in range(T): N = int(input()) A = list(map(int, input().split())) one...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) res = [] for i in range(n // 2): if a[i * 2] == 1 and a[i * 2 + 1] == 1: res.append(1) res.append(1) elif a[i * 2] == 0 and a[i * 2 + 1] == 0: res.append(0) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; long long pw(int a, int b) { int ret = 1; int mul = a; while (b > 0) { if (b & 1) ret *= mul; mul *= mul; b /= 2; } return ret; } int to_int(string s) { long long ret = 0; for (int i = 0; i < (s.size()); i++) { ret += pw(10, s.size() - i - 1) *...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t = int(input()) while t > 0: n = int(input()) li = list(map(int,input().split())) s = sum(li) if s==n or s == 0: print(n) for item in li: print(item, end=' ') pass print() elif s<=(n/2) : print(n-s) i = 0 while i<s: ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t=int(input()) for i in range(0,t): m=int(input()) arr=list(map(int,input().strip().split())) zc=arr.count(0) oc=arr.count(1) l1=[] if(zc>=oc): for j in range(0,zc): l1.append(0) else: if(oc%2==0): for j in range(0,oc): l1.append(1) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
# It's never too late to start! from bisect import bisect_left import os import sys from io import BytesIO, IOBase from collections import Counter, defaultdict from collections import deque from functools import cmp_to_key import math import heapq def sin(): return input() def ain(): return list(map(int, sin()...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10; const long long INF = 1e18 + 20; long long n, x, y, cnt; long long a[1010]; void solve() { cnt = 0; cin >> n; for (long long i = 1; i <= n; i++) { cin >> a[i]; if (a[i]) cnt++; } if (cnt <= n / 2) { cout << n - cnt << endl...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for t in range(int(input())): n = int(input()) a = list(map(int, input().split())) r = list() c = 0 for i in range(n): if a[i]: c += 1 if c <= n//2: print(n-c) print("0 "*(n-c) ) else: if c%2: print(c-1) print("1 "*(c-1)) else: print(c) print("1 "*(c))
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.util.*; public class S { public static void main(String [] args) { Scanner obj = new Scanner(System.in); int t = obj.nextInt(); while(t-->0){ int c0=0,c1=0; int n=obj.nextInt(); int [] a = new int[n]; for(int i = 0;i<n;i++){ a[i]=obj.nextInt(); if(a[i]...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) ar=list(map(int,input().split())) one=0 zero=0 for i in ar: if(i==0): zero+=1 else: one+=1 if(n==2): if(zero==one): print(1) print(0) e...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; void solve(); int main() { srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; } const long long maxN = 1e5 + 10, maxE = 5200, maxK = 1e4 + 10, inf = 1e15 + 10, mod = 1e9 + 7, base = 223; const double eps = 0.0000...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t = int(input()) for case in range(t): n = int(input()) a = [int(s) for s in input().split(' ')] if a.count(0) >= n // 2: print(n // 2) print(' '.join(['0'] * (n // 2))) else: print((n // 2) + (n // 2) % 2) print(' '.join(['1'] * (n // 2 + (n // 2) % 2)))
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
from sys import stdin, stdout import math,sys from itertools import permutations, combinations from collections import defaultdict,deque,OrderedDict,Counter from os import path import bisect as bi import heapq def yes():print('YES') def no():print('NO') if (path.exists('input.txt')): #------------------Sublime---...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.io.*; import java.util.*; public class d2669 implements Runnable { private boolean console=false; public void solve() { int i; int n=in.ni(); int a[]=new int[n]; int z=0,o=0; ArrayList<Integer> ans=new ArrayList(); for(i=0;i<n;i++) { a[i]=in.ni(); if(a[i]==1) o++; else ...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t=int(input()) for i2 in range(t): n=int(input()) dem=n d=0 d2=0 a=[int(i) for i in input().split()] for i in a: if i==0:d+=1 else:d2+=1 if d>=n//2: print(d) for i in range(d): print(0,end=' ') else: if d2%2==1:d2-=1 print(d2) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys if sys.subversion[0] == "PyPy": import io, atexit sys.stdout = io.BytesIO() atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue())) sys.stdin = io.BytesIO(sys.stdin.read()) input = lambda: sys.stdin.readline().rstrip() RS = raw_input RI = lambda x=int: map(x,RS().split(...
PYTHON
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; void dbg_out() { cerr << "\b\b]\n"; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ", "; dbg_out(T...); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; ...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 5; const long long INF = 1e9 + 7; void solve() { int n, x; cin >> n; vector<int> a; int s1 = 0, s2 = 0; for (int i = 0; i < (int)n; i++) { cin >> x; a.push_back(x); if (x == 1) i % 2 == 0 ? s2++ : s1++; } vector<int> v; in...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.util.*; import java.io.*; import java.math.*; public class Euler { public static void main(String[] args){ FastReader in = new FastReader(); PrintWriter o = new PrintWriter(System.out); int t = in.nextInt(); while (t-- > 0) { int n = in.nex...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n=int(input()) a=[int(x) for x in input().split()] zero=a.count(0) one=a.count(1) if(zero>= n//2): print(zero) for _ in range (zero): print("0",end=" ") elif(one>=(n//2)): if(((n//2)%2)!=0): ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
# Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a1βˆ’a2+a3βˆ’a4+…=0). In other words, Alexandra wants sum of all eleme...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) count=0 for i in a: if i==0: count+=1 if count>=n//2: print(count) print(*[0]*count) else: if (n-count)%2==0: print(n - count) print(*[1]*(n-cou...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
def main(): t=int(input()) while(t>0): n=int(input()) li2=[] li=list(map(int,input().split())) i=0 cnt=0 if(n==2): if(li[0]==li[1]): li2.append(li[0]) li2.append(li[1]) else: li2.append(0) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
def solve(): n = int(input()) l = list(map(int, input().split())) z,o = 0,0 for i in l: if(i==0): z+=1 else: o+=1 if(z == n or o == n): return l if(z==o): return [0]*z if(z>o): if(z%2==0): return [0]...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; int a; int n, m; int sum; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> m; sum = 0; for (int j = 0; j < m; j++) { cin >> a; sum += a; } if (2 * sum > m) { int length = sum - (sum % 2); cout << length << endl; ...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
def solve(): N=int(input()) a=list(map(int,input().split())) z,o=a.count(0),a.count(1) if z>=o: d=N//2 return [0]*d else: d=N//2 if d%2: d+=1 return [1]*d t=int(input()) for _ in range(t): ans=solve() print(len(ans)) print(*ans)
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
def problemA(arr,n): count0 = 0 for i in range(n): if(arr[i]==0): count0 +=1 count1 = n-count0 if(count0>=count1): return n//2,[0]*(n//2) else: if((n//2)%2==0): return n//2,[1]*(n//2) else: return (n//2)+1,[1]*((n//2)+1) if __name...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
def tc(): n = int(input()) a = list(map(int, input().split())) ones, zeros = 0, 0 for x in a: if x: ones += 1 else: zeros += 1 if zeros >= n // 2: print(n // 2) print(' '.join(['0'] * ((n // 2)))) else: if ones % 2 == 1: ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
n = int(input()) i = 0 while i < n: q = int(input()) mas = input() if mas.count('0') < mas.count('1'): mas = mas.replace(' 0', '') mas = mas.replace('0 ', '') if mas.count('1') % 2 == 1: mas = mas[2:] else: mas = mas.replace(' 1', '') mas = mas.replac...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n=int(input()) o,z=0,0 for i in input().split(): t=int(i) if(t==0): z+=1 if(t==1): o+=1 ans=[0]*z if(z>=o) else [1]*o #print(ans,z,0) if(ans[0]==1 and len(ans)%2==1): ans.pop() print(len(ans)) print(*ans)
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
def main(): t = int(input()) for case in range(t): n = int(input()) ar = [int(x) for x in input().split()] i_start = -1 lis = [] for i in range(n): if ar[i] == 1: # print(i_start, ar[i], i) if i_start == -1: ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
def sum(a, pos): s = 0 b = a.copy() if pos != -1: b.pop(pos) for i in range(0, len(b)): if i % 2 == 0: s += b[i] else: s -= b[i] return s for _ in range(int(input())): n = int(input()) a = list(map(int, in...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
# Author : raj1307 - Raj Singh # Date : 08.09.2020 from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): return int(input())...
PYTHON
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; public class ahahahahaha { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedRead...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import java.util.*; import java.io.*; public class Q2 { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for (int z = 0; z < t; z++) { int n = Integer.p...
JAVA
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n = int(input()) a = list(map(int,input().split())) no = a.count(1) nz = a.count(0) if(nz>=no): print(nz) print(*([0]*nz)) else: if(no%2==0): print(no) print(*([1]*no)) else: print(no-1) ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) c0=a.count(0) c1=a.count(1) if c1>c0: if c1%2==1: c1-=1 print(c1) print('1 '*c1) else: print(c0) print('0 '*c0)
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n = int(input()) ar = list(map(int , input().split())) c0 = 0 c1 = 0 for i in range(n): if ar[i] == 1: if i % 2 == 1: c1 += 1 else: c0 += 1 if c1 + c0 <= n//2: print(n//2) for i in range...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys from math import ceil from collections import deque # input = sys.stdin.buffer.readline # def print(val): # sys.stdout.write(str(val) + '\n') for _ in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] ans = [] for i in range(0, n, 2): if a[i]==0 or a[i+1]==0: ans.append(...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#!/usr/bin/env pypy3 def alt_sum(A): a = 0 b = 0 for i in range(len(A)): if i % 2 == 0: a += A[i] else: b += A[i] return (a, b) def ans(A): n = len(A) while True: (a, b) = alt_sum(A) if a == b: assert(len(A) >= n // 2) print(len(A)) print(*A) return if a > b: aa = 0 bb = 0 ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys t = int(sys.stdin.readline().strip()) for i in range(t): n = int(sys.stdin.readline()) arr = list(map(int, sys.stdin.readline().split())) x = arr.count(0) y = arr.count(1) if x >= n/2: print (x) for j in range(x): print ('0', end = ' ') print ('') e...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
# from math import factorial # ans= 0 # for x in range(1,5): # for y in range(1,5-x+1): # # print(x,y,5-x-y) # ans += pow(12,x)*pow(33,y)*pow(52,5-x-y)*factorial(5)//(factorial(x)*factorial(y)*factorial(5-x-y)) # print(ans*52) for _ in range(int(input())): n = int(input()) arr = list(map(int,input().split()))...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#!/usr/bin/env python3 import re def _sum(seq): if not seq: return 0 else: return sum(seq) def is_ok(numbers): return _sum(numbers[::2]) == _sum(numbers[1::2]) def solve_numbers(numbers, idx, initial_len): # print("solving ", numbers, idx) if len(numbers) < initial_len // 2: ...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in " "*int(input()): a=int(input()) z=list(map(int,input().split())) s=z.count(0);k=a//2 s1=z.count(1) if s>=s1:print(k);print('0 '*k) else:print(k+k%2);print('1 '*(k+k%2))
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
import sys,math try:sys.stdin,sys.stdout=open('input.txt','r'),open('out.txt','w') except:pass from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt,log ii1=lambda:int(stdin.readline().strip()) is1=lambda:stdin.readlin...
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
t = int(input()) for i in range(t): n = int(input()) ai = list(map(int,input().split())) ans = [] for i in range(n//2): if ai[i*2] == ai[i*2+1]: ans += [ai[i*2],ai[i*2]] else: ans += [0] print(len(ans)) print(" ".join(map(str,ans)))
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; vector<long long int> a(n); for (long long int i = 0; i < n; i++) { cin >> a[i]; } long long int c = 0; for (long long int i = 0; i < n - 1; i++) { ...
CPP
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for _ in range(int(input())): n=int(input()) ar=list(map(int,input().split())) count0=ar.count(0);count1=ar.count(1) if count0>=count1: print(count0) print('0 '*count0) else: print((count1//2)*2) print('1 '*(count1//2)*2)
PYTHON3
1407_A. Ahahahahahahahaha
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n β€” length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
2
7
for tc in range(int(input())): n = int(input()) arr = list(map(int, input().split())) ans = [] zeros = arr.count(0) ones = arr.count(1) if ones <= n // 2: print(zeros) print(*[0] * zeros) else: if ones % 2 == 0: print(ones) print(*[1] * ones) ...
PYTHON3
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; using LL = long long; const int MAX_N = 1e5 + 5; struct Graph { int to, cap, cost, next; } e[MAX_N * 50]; int fir[MAX_N], e_cnt; void clearGraph() { memset(fir, -1, sizeof(fir)); e_cnt = 0; } void Add_Edge(int u, int v, int c, int w) { e[e_cnt] = (Graph){v, c, w, fi...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; int read() { int t; scanf("%d", &t); return t; } int n, m; struct wangluoliu { const int inf = 0x3f3f3f3f; int head[40010], val[800000], last[800000], p = 1, v[800000]; int cur[40010], cnt = 1; inline void Add(int a, int b, int c) { v[++p] = b; last[p]...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; namespace FLOW { const int maxn = 40010; int V, cnt, head[maxn], lev[maxn]; struct edge { int to, cap, nxt; } e[maxn * 10]; void init(int _V) { V = _V, cnt = 0; fill(head, head + V + 1, -1); } void add_edge(int u, int v, int cap, bool dir = 0) { e[cnt] = (edge){v, c...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; struct Node { int pr, to, cap; } E[300005]; int tot = 1, fir[40005]; void adde(int x, int y, int z) { E[++tot].pr = fir[x]; fir[x] = tot; E[tot].to = y; E[tot].cap = z; } void addf(int x, int y, int z = 4, int z2 = 0) { adde(x, y, z), adde(y...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int nega = 1; while (!isdigit(ch)) { if (ch == '-') nega = -1; ch = getchar(); } int ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); } if (nega == -1) return -ans; return ans...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> template <class Flow> class MaxFlow_Network { const Flow INF = std::numeric_limits<Flow>::max(); struct Edge { int u, v; Flow c; Edge() : u(0), v(0), c(0) {} Edge(int _u, int _v, Flow _c) : u(_u), v(_v), c(_c) {} }; int n, S, T; std::vector<Edge> edge; std::vector<st...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int nega = 1; while (!isdigit(ch)) { if (ch == '-') nega = -1; ch = getchar(); } int ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); } if (nega == -1) return -ans; return ans...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; inline long long read() { char c = getchar(); long long x = 0; bool f = 0; for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; return x; } long long a[205][205], n; struct edge...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read(register T& t) { register T f = 1; register char ch = getchar(); t = 0; while (ch < '0' || ch > '9') { if (ch == '-') f = -f; ch = getchar(); } while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar(); t ...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; } template <typename T> bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; } int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f =...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; const int N = 50005; struct Graph { struct Edge { int to, nxt, c; } edge[N * 12]; int head[N], top; Graph() { memset(head, -1, sizeof(head)), top = -1; } inline void add(int x, int y, int k) { edge[++top] = (Edge){y, head[x], k}; head[x] = top; } } G...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; const int Maxn = (1 << 16); const int Block = (1 << 8) - 1; const int d[4] = {1, 256, -1, -256}; int n; int a[Maxn]; bool mp[4][Maxn]; int lis[1024], len; bool vis[Maxn]; bool S[Maxn], T[Maxn]; bool dfs(int u, bool *g) { vis[u] = 1; if (g[u]) { return 1; } for (...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 300 + 10; const int MAX_NODE = MAXN * MAXN; const int MAX_EDGE = 4 * MAXN * MAXN; const int INF = INT_MAX; struct MaxFlow { struct Edge { int v, f, n; bool disabled; Edge(int v = 0, int f = 0, int n = 0) : v(v), f(f), n(n), disabled(false) {} ...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int inf = 1 << 30; int n, m, cnt, sum, num, s, t, tt, b[205 << 2], cur[205 * 205], dep[205 * 205], a[205][205], d[205][205]; int tot = 1, tcp, w[700005], fa[700005], son[700005], nxt[700005], pre[70...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } long long gcd(long long a, long long b) { re...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; bool vis[205 * 205]; long long ANS; int n, a[205][205], cnt, tot = 1, s, ans, tmp, S[200005], T[200005], nxt[200005], val[200005], to[200005], node[200005], i, j, x, y; struct nde { int x, y, val; } w[205 << 2]; inline boo...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> int n, m, a[(205 * 205)]; int hd[(205 * 205)], _hd = 1; struct edge { int v, f, nxt; } e[(205 * 205) << 2]; inline void addedge(int u, int v) { e[++_hd] = (edge){v, 0, hd[u]}; hd[u] = _hd; e[++_hd] = (edge){u, 0, hd[v]}; hd[v] = _hd; } std::pair<int, int> val[(205 * 205)]; int tot; bo...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; const int c = 40005; int n, m, kov[c], t[c], f; long long sum, db; vector<int> sz[c], s[c], pos[c]; vector<pair<int, int> > ert; bool v[c]; void add(int a, int b, int c, int d) { if (t[a] * t[b] != 0) return; int x = sz[a].size(), y = sz[b].size(); pos[a].push_back(y)...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; namespace FLOW { const int maxn = 40010; int V, cnt, head[maxn], lev[maxn]; struct edge { int to, cap, nxt; } e[maxn * 10]; void init(int _V) { V = _V, cnt = 0; fill(head, head + V + 1, -1); } void add_edge(int u, int v, int cap, bool dir = 0) { e[cnt] = (edge){v, c...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using std::deque; using std::min; using std::sort; using std::vector; const int inf = 0x3f3f3f3f; namespace mf { const int N = 1e5 + 5; int n, s, t, ans; struct edge { int v, w, inv; bool ex; }; vector<edge> e[N]; bool bk[N]; inline edge &inv(edge ed) { return ...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
import java.io.*; import java.util.*; public class GFlow { FastScanner in; PrintWriter out; class Edge { int fr, to; int flow, cap; Edge rev; Edge(int fr, int to, int cap) { this.fr = fr; this.to = to; this.cap = cap; } } ...
JAVA
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using std::max; using std::min; const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; const long long INF = 0x3f3f3f3f3f3f3f3f; std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); template <typename _Tp> _Tp gcd(const _Tp &a, const _Tp &b) { return !b ? a : gcd(b, a % b); }...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t, class u> void chmax(t& first, u second) { if (first < second) first = second; } template <class t, class u> void chmin(t& first, u second) { if (second < first) first = second; } template <class t> using vc = vector<t>; template ...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") using namespace std; template <typename T1, typename T2> void ckmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> void ckmax(T1 &a, T2 b) { if (a < b) a = b; } int read() { int x = 0, f ...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; const int N = 200 + 7, INF = 0x3f3f3f3f; const long long LNF = 0x3f3f3f3f3f3f3f3f; int n; bool S[N][N], T[N][N], vis[N][N], ok[N][N][4]; int d[] = {0, 1, 0, -1}; int val[N][N]; int dfs(int x, int y, bool to[N][N]) { vis[x][y] = 1; if (to[x][y]) { return 1; } for...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 200 + 5; int vals[MAXN][MAXN]; int available[MAXN][MAXN][4]; int dt[4] = {0, 1, 0, -1}; int N; bool sources[MAXN][MAXN]; bool sinks[MAXN][MAXN]; bool visited[MAXN][MAXN]; void reset_visited() { for (int x = 0; x < N; x++) for (int y = 0; y < N; y++) v...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; int n; const int maxN = 202; int x[maxN][maxN]; const int F = (int)1e9; mt19937 rnd(228); int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> x[i][j]; } } int...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int nega = 1; while (!isdigit(ch)) { if (ch == '-') nega = -1; ch = getchar(); } int ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); } if (nega == -1) return -ans; return ans...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; template <class T> T gi() { T x = 0; bool f = 0; char c = getchar(); while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') f = 1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return f ? -x : x; } const int N ...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; const int Maxn = 40005; int n, m, c, s, t, ct, cnt, ans, b[Maxn], dis[Maxn], head[Maxn], cur[Maxn], a[205][205], id[205][205]; long long tot; bool vis[Maxn]; struct edg { int nxt, to, w; } edge[10 * Maxn]; void add(int x, int y, int w) { edge[++cnt] = (edg){head[x],...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> template <typename T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = false; while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); } while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); if (flag) x = -x; } using namespace std; const int inf = ...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; const int inf = 1e5; int begin1[1000010], ok = 0, total, hh = 0, st[1000010], p[1010][1010], next1[1000010], to1[1000010], e = 1, dis[1000010], q[1000010], x[1000010], y[1000010], t, w[1000010], d[1000010], vis[...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1, c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return f == 1 ? x : -x; } const int N = 40004, inf = 0x3f3...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; const int N = 205, INF = 0X3F3F3F3F; int n, a[N][N]; int res; int zip(int x, int y) { return (x - 1) * n + y; } bool IN(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= n; } struct MaxFlow { static const int N = ::N * ::N, M = N * 8; int S, T; int dep[N], q[N...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int nega = 1; while (!isdigit(ch)) { if (ch == '-') nega = -1; ch = getchar(); } int ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); } if (nega == -1) return -ans; return ans...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> #pragma GCC optimize("unroll-all-loops") using namespace std; int sum = 0; const int M = 200000; int st[M]; struct Dinic { struct edge { int to, flow, cap; }; const static int N = 207 * 207; edge e[350000]; int t = 0; vector<int> g[N + 7]; int dp[N + 7]; int ptr[N + 7]; in...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<db>; using vs = vector...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); int a[200][200]; int dx[] = {0, 0, -1, 1}; int dy[] = {-1, 1, 0, 0}; int vs = 0; int id[200][200]; const int N = 4e5 + 10; struct edge { int a, b, cap, flow; }; vector<int> g[N], gr[N]; vector<i...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; template <typename TH> void _dbg(const char* sdbg, TH h) { cerr << sdbg << "=" << h << "\n"; } template <typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) { while (*sdbg != ',') { cerr << *sdbg++; } cerr << "=" << h << ","; _dbg(sdbg + 1,...
CPP
1427_G. One Billion Shades of Grey
You have to paint with shades of grey the tiles of an nΓ— n wall. The wall has n rows of tiles, each with n tiles. The tiles on the boundary of the wall (i.e., on the first row, last row, first column and last column) are already painted and you shall not change their color. All the other tiles are not painted. Some of...
2
13
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmin(T &first, T second) { return second < first ? first = second, 1 : 0; } template <typename T> bool chkmax(T &first, T second) { return first < second ? first = second, 1 : 0; } template <typename T> void readint(T &first) { first = 0; ...
CPP