id
int64 251M
307M
| language
stringclasses 12
values | verdict
stringclasses 290
values | source
stringlengths 0
62.5k
| problem_id
stringclasses 500
values | type
stringclasses 2
values |
---|---|---|---|---|---|
297,473,206 |
Python 3
|
WRONG_ANSWER on test 2
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
segments = 0
has_zero = False
i = 0
while i < n:
if a[i] != 0:
segments += 1
while i < n and a[i] != 0:
i += 1
else:
has_zero = True
i += 1
z = 0
for i in range(len(a)):
if(a[i]==0):
z+=1
if(z==n):
print(0)
elif(z==0):
print(1)
elif(z==1):
if(a[0]==0 or a[-1]==0):
print(1)
else:
print(2)
elif(z==2):
if(a[0]==0 and a[-1]==0):
print(1)
else:
print(2)
else:
if(segments==1):
print(1)
else:
print(2)
|
2049A
|
wrong_submission
|
297,485,089 |
Python 3
|
WRONG_ANSWER on test 2
|
# cook your dish here
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
m1=-1
for i in range(n):
if a[i]==0:
m1=i
break
if a.count(0)==n:
print(0)
continue
if a[0]==0 and a[-1]==0 and a.count(0)!=2:
print(2)
continue
if a.count(0)==0:
print(1)
continue
if m1>0 and m1<n-1:
print(2)
elif m1==0 or m1==n-1:
print(1)
else:
print(0)
|
2049A
|
wrong_submission
|
297,598,486 |
Python 3
|
WRONG_ANSWER on test 2
|
t=int(input())
def solve():
n=int(input())
arr=list(map(int,input().split()))
ans=0
if(list(set(arr))==[0]):
return 0
if(0 in arr[1:n-1]):
return 2
return 1
for _ in range(t):
print(solve())
|
2049A
|
wrong_submission
|
297,502,572 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
def solver(x):
breaks = 0
if x[0] == 0:
count = 0
else:
count = 1
for i in range(len(x)):
if x[i] == 0:
count = (count + 1) % 2
if x[i] != 0 and count != 0:
breaks = breaks + 1
count = 0
if breaks == 0:
return print(0)
if breaks == 1:
return print(1)
else:
return print(2)
t = input()
t = int(t)
for i in range(t):
y = input()
x = [int(i) for i in input().split()]
solver(x)
|
2049A
|
wrong_submission
|
297,475,152 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class A_MEX_Destruction {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt(); // No. of test cases
while (t-- > 0) {
int n = sc.nextInt(); // Length of array `a`
int[] a = new int[n]; // Array `a`
int zeroCount = 0;
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
if (a[i] == 0) {
zeroCount++;
}
}
// All elements are 0
if (zeroCount == n) {
System.out.println(0);
continue;
}
// Check if there is a zero in the middle of two positive numbers
boolean zeroInMiddle = false;
for (int i = 0; i < n - 2; i++) {
if (a[i] > 0 && a[i + 1] == 0 && a[i + 2] > 0) {
zeroInMiddle = true;
break;
}
}
if (zeroInMiddle) {
System.out.println(2);
} else {
System.out.println(1);
}
}
sc.close();
}
}
|
2049A
|
wrong_submission
|
297,474,849 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
for _ in range(int(input())):
n = int(input())
array = list(map(int,input().split()))
zerocount = 0
for num in array:
if num == 0:
zerocount +=1
if zerocount == n:
print(0)
continue
# exceptfirstandlast = 0
for i in range(1,n-1):
if array[i] == 0:
print(2)
break
else:
print(1)
|
2049A
|
wrong_submission
|
297,461,461 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
get_int = lambda: int(input())
get_tuple_int = lambda: map(int, input().split())
get_list_int = lambda: list(map(int, input().split()))
t = get_int()
for _ in range(t):
n = get_int()
a = get_list_int()
zeros = [i for i,j in enumerate(a) if j==0]
if len(zeros) == n:
print(0)
elif len(zeros)==0:
print(1)
elif len(zeros)==1 and zeros[0] in [0,n-1]:
print(1)
elif (n-max(zeros)) + (min(zeros)+1) == len(zeros):
print(1)
else:
print(2)
|
2049A
|
wrong_submission
|
297,460,142 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
for _ in range(int(input())):
t=int(input())
w=[*map(int,input().split())]
if w.count(0)==t:print(0)
else:
for i in range(t-2):
if w[i]>0 and w[i+1]==0 and w[i+2]>0:print(2);break
else:print(1)
|
2049A
|
wrong_submission
|
297,495,458 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class MEXDestruction {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
System.out.println(minOperations(a, n));
}
}
private static int minOperations(int[] a, int n) {
boolean allZero = true;
int c=0;
for (int num : a) {
if (num == 0) {
c++;
}
}
if(c==0) return 1;
if(c==n)return 0;
boolean check=false;
for (int i = 1; i < a.length - 1; i++) {
if (a[i] == 0 && a[i - 1] != 0 && a[i + 1] != 0) {
check=true;
}
}
if(check)return 2;
else return 1;
}
}
|
2049A
|
wrong_submission
|
301,291,799 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class MEX {
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
int t=in.nextInt();
for(int z=1;z<=t;z++)
{
int n=in.nextInt();
int[] a=new int[n];
int c=0;int c1=0;int k=0;boolean flag=true;int x=0;
for(int i=0;i<n;i++)
{
a[i]=in.nextInt();
if(a[i]!=0)
{
x++;
}
if(a[i]==0 && i!=0 && i!=n-1)
{
c++;
flag=false;
}
else if(flag==true && a[i]!=0 && i!=0 && i!=n-1)
{
k++;
}
if(a[i]==0)
c1++;
}
if(c1==n)
{
System.out.println("0");
}
else if(x==1 && c1==n-1)
{
System.out.println("1");
}
else
{
if(c1-c==2||c1-c==0)
{
if(c>0)
{
System.out.println("2");
}
else
{
System.out.println("1");
}
}
else
{
if(c>0 && (k+c)==n-2)
{
System.out.println("1");
}
else if(c>0)
{
System.out.println("2");
}
else
{
System.out.println("1");
}
}
}
}
}
}
|
2049A
|
wrong_submission
|
304,624,749 |
C++20 (GCC 13-64)
|
WRONG_ANSWER on test 2
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t,n;
cin >> t;
while(t--) {
cin >> n;
vector<int> a(n);
int sum = 0;
for (int i = 0; i < n;i++) {
cin >> a[i];
sum += a[i];
}
if (sum == 0) {
cout << 0 << endl;
continue;
}
bool flag = 0;
for (int i = 2; i < n;i++) {
//cout << a[i] << " " << a[i-1] << " " << a[i-2] << endl;
if (a[i] != 0 && a[i-1] == 0 && a[i-2] != 0) {flag = 1;
break;
}
}
if (flag) cout << 2 << endl;
else cout << 1 << endl;
}
return 0;
}
|
2049A
|
wrong_submission
|
297,616,333 |
Java 8
|
WRONG_ANSWER on test 2
|
import java.io.*;
import java.util.*;
public class Main {
private static class Kattio extends PrintWriter {
private BufferedReader r;
private StringTokenizer st;
public Kattio() {
this(System.in, System.out);
}
public Kattio(InputStream i, OutputStream o) {
super(o);
r = new BufferedReader(new InputStreamReader(i));
}
public String next() {
try {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(r.readLine());
}
return st.nextToken();
} catch (Exception e) {
return null;
}
}
public int nextInt() { return Integer.parseInt(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
public long nextLong() { return Long.parseLong(next()); }
}
public static void main(String[] args) {
Kattio io = new Kattio();
int tt = io.nextInt();
while (tt-->0) {
int n = io.nextInt();
int ide1=-1;
int ide2=-1;
boolean flag = true;
int[] arr = new int[n];boolean ffl = true;
int[] index = new int[1000];
for (int i = 0; i < n; i++) {
arr[i] = io.nextInt();
if(arr[i]!=0){
flag = false;
}
}
if(flag==false){
boolean f = true;
for (int i = 0; i < n; i++) {
if(arr[i]!=0||arr[i]==arr.length-1){
ide1 = i;break;
}
}
if(ide1!=arr.length-1){
for (int i = ide1+1; i < arr.length; i++) {
if(arr[i]==0||i==arr.length-1){
ide2 = i;break;
}
}
if(ide2!=arr.length-1){
for (int i = ide2+1; i < arr.length; i++) {
if(arr[i]!=0||i==arr.length-1){
f=false;break;
}
}
}
}
if(!f){
io.println(2);
}else{
io.println(1);
}
}else{
io.println(0);
}
}
io.close();
}
}
|
2049A
|
wrong_submission
|
297,505,657 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
def min_operations_to_zero(t, test_cases):
results = []
for n, arr in test_cases:
zero_count = arr.count(0)
if zero_count == n:
results.append(0)
elif zero_count == 1:
if arr[0] == 0 or arr[n-1]==0:
results.append(1)
else:
results.append(2)
elif zero_count == 2:
if arr[0]==0 and arr[n-1]==0:
results.append(1)
else:
results.append(2)
elif zero_count >=3:
if arr[0]==0 and arr[n-1]==0:
results.append(2)
else:
results.append(2)
else:
results.append(1)
return results
t = int(input())
test_cases = []
for _ in range(t):
n = int(input())
arr = list(map(int, input().split()))
test_cases.append((n, arr))
results = min_operations_to_zero(t, test_cases)
print("\n".join(map(str, results)))
|
2049A
|
wrong_submission
|
302,268,257 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
from collections import Counter
import sys
def main():
# Read input
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int, input().split()))
d = Counter(arr)
# all zeros
if d[0] == n:
print(0)
# all non zeros
elif d[0] == 0:
print(1)
# starts with 0
elif arr[0] == 0:
# also ends with 0
if arr[-1] == 0:
# no other zeros
if d[0] == 2:
print(1)
# zeros in bw as well
else:
print(2)
# no other zero
elif d[0] == 1:
print(1)
# zeros in bw
else:
print(2)
# starts with non zero
else:
# 0 on right only
if arr[-1] == 0:
print(1)
else:
print(2)
if __name__ == "__main__":
# Use input.txt only in local environment
try:
sys.stdin = open("input.txt", "r")
except FileNotFoundError:
pass
main()
|
2049A
|
wrong_submission
|
297,500,170 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.Scanner;
import java.util.Arrays;
public class Main {
static void solve(Scanner sc) {
int n = sc.nextInt();
int[] a = new int[n];
int c = 0;
for(int i = 0; i < n; i++) {
a[i] = sc.nextInt();
if(a[i] == 0) c++;
}
if(n != 4 && n != 5 && n != 6 && n != 7 && n != 1 && n != 2) {
System.out.println(n);
System.out.println(Arrays.toString(a));
}
if(c == n) System.out.println(0);
else if(c == 0) System.out.println(1);
else if((a[0] == 0 && c == 1) || (a[n - 1] == 0 && c == 1)) System.out.println(1);
else if(c == 2 && a[0] == 0 && a[n - 1] == 0) System.out.println(1);
else System.out.println(2);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0) solve(sc);
}
}
|
2049A
|
wrong_submission
|
297,475,062 |
Java 8
|
WRONG_ANSWER on test 2
|
import java.io.*;
import java.util.*;
//import java.math.*;
public class Looser1202{
final static int mod = 1000000007;
static long gcd(long a, long b)
{
while (a > 0 && b > 0) {
if (a > b) {
a = a % b;
}
else {
b = b % a;
}
}
if (a == 0) {
return b;
}
return a;
}
static boolean reverse(String s){
String rev = new StringBuilder(s).reverse().toString();
return s.equals(rev);
}
static boolean allSame(String s){
HashSet<Character> hs = new HashSet<>();
for(int i=0 ; i<s.length() ; i++){
hs.add(s.charAt(i));
}
if(hs.size() == 1)
return true;
return false;
}
static int XOR(int n)
{
if(n%4 == 0)
return n;
if(n%4 == 1)
return 1;
if(n%4 == 2)
return n+1;
return 0;
}
public static long leftMostBitNumber(long n){
long k = Long.numberOfLeadingZeros(n);
long num = 1 << (31 - k);
return num;
}
private static void solve() {
int n = nextInt();
int[] arr = new int[n];
boolean cornerL=false ,cornerR=false, allZero=true , noZero=true;
for(int i=0 ; i<n ; i++){
arr[i] = nextInt();
if(i==0 && arr[i]==0)
cornerL = true;
else if(i==n-1 && arr[i]==0)
cornerR = true;
else if(arr[i]==0){
noZero = false;
}
else if(arr[i]!=0){
if(noZero) noZero = true;
allZero = false;
}
}
if(allZero){
out.println(0);
return;
}
else if(noZero) {
out.println(1);
return;
}
else if((cornerL && !cornerR)||(cornerR && !cornerL)){
out.println(1);
}
else if(noZero){
out.println(2);
}
else out.println(2);
}
private static void run() {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
int tt = nextInt();
//int tt=1;
for(int i=1 ; i<=tt ; i++)
solve();
out.close();
}
private static StringTokenizer st;
private static BufferedReader br;
private static PrintWriter out;
private static String next() {
while (st == null || !st.hasMoreElements()) {
String s;
try {
s = br.readLine();
} catch (IOException e) {
return null;
}
st = new StringTokenizer(s);
}
return st.nextToken();
}
private static int nextInt() {
return Integer.parseInt(next());
}
private static long nextLong() {
return Long.parseLong(next());
}
public static void main(String[] args) throws java.lang.Exception{
run();
}
}
|
2049A
|
wrong_submission
|
297,485,046 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
import java.io.*;
/*
⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⣾⡳⣼⣆⠀⠀⢹⡄⠹⣷⣄⢠⠇⠻⣷⣶⢀⣸⣿⡾⡏⠀⠰⣿⣰⠏⠀⣀⡀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡀⣀⣀⣀⡹⣟⡪⢟⣷⠦⠬⣿⣦⣌⡙⠿⡆⠻⡌⠿⣦⣿⣿⣿⣿⣦⣿⡿⠟⠚⠉⠀⠉⠳⣄⡀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⡀⢀⣼⣟⠛⠛⠙⠛⠉⠻⢶⣮⢿⣯⡙⢶⡌⠲⢤⡑⠀⠈⠛⠟⢿⣿⠛⣿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣆⠀⠀⠀
⠀⠀⠀⠀⠀⡸⠯⣙⠛⢉⣉⣙⣿⣿⡳⢶⣦⣝⢿⣆⠉⠻⣄⠈⢆⢵⡈⠀⠀⢰⡆⠀⣼⠓⠀⠀⠀ Nah ⠈⣷⠀⠀
⠀⠀⠀⠖⠉⠻⣟⡿⣿⣭⢽⣽⣶⣈⢛⣾⣿⣧⠀⠙⠓⠀⠑⢦⡀⠹⣧⢂⠀⣿⡇⢀⣿⠺⠇⠀ I'd⠀ ⣿⠀⠀
⠀⠀⠀⠀⠐⠈⠉⢛⣿⣿⣶⣤⣈⠉⣰⣗⡈⢛⣇⠀⣵⡀⠀⠘⣿⡄⢻⣤⠀⢻⡇⣼⣧⣿⡄⠀⠀ Win⠀ ⠀⡿⠀⠀
⠀⠀⠀⠀⠀⣠⣾⣿⢍⡉⠛⠻⣷⡆⠨⣿⣭⣤⣍⠀⢹⣷⡀⠀⠹⣿⡄⠈⠀⢿⠁⣿⣿⠏ ⠀⠀⠀⣇⠀⠀
⠀⣿⣇⣠⣾⣿⣛⣲⣿⠛⠀⠀⢀⣸⣿⣿⣟⣮⡻⣷⣤⡙⢟⡀⠀⠙⢧⠀⠀⠎⠀⠉⠁⠰⣿⠀⠀ ⠀⢀⡿⠀⠀
⠀⠈⢻⣿⣿⣽⣿⣿⣿⣴⡏⠚⢛⣈⣍⠛⠛⠿⢦⣌⢙⠻⡆⠁⠀⠀⠀⣴⣦⠀⠀⠀⠐⢳⢻⣦⣀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠮⠀⠀⠀
⠀⠀⠈⠙⣿⣧⣶⣿⠿⣧⣴⣿⢻⡉⠀⢀⣠⣴⣾⡟⠿⠃⠁⣠⣤⡶⣾⡟⠅⠀⣀⡄⠀⣾⢸⣿⣏⢻⢶⣦⣤⣤⣄⢶⣾⣿⣡⣤⡄⠀
⠀⠀⣠⣞⣋⣿⣿⣾⣿⡿⡛⣹⡟⣤⢰⡿⠟⠉⣀⣀⣤⣤⡠⠙⢁⣾⡿⠂⠀⣿⠟⣁⠀⣹⠀⣹⣿⡟⣼⣿⣿⣌⣿⣞⣿⣿⠁⠀⠀⠀
⠀⢠⡿⢛⢟⣿⣿⣿⣿⣿⣿⡟⣼⣿⣟⢓⠛⣿⣏⣿⣵⣗⣵⣴⣿⢟⡵⣣⣼⣿⢟⣵⣶⢻⣶⣿⠀⠀⣈⢻⣿⣿⣿⢿⣾⢿⣧⠀⠀⠀
⠀⠘⠃⢸⣿⡾⣿⣿⣿⣿⣯⣿⣿⣿⣶⣿⣿⣟⣾⡿⣫⣿⣿⣿⣽⣿⣿⣿⣿⢫⣾⣿⣿⣿⣿⣿⣴⡆⣻⣿⡏⣿⢻⣧⣿⡿⣿⡆⠀⠀
⠀⠀⠀⠜⣿⣾⢿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣭⣿⣖⣿⢿⣿⡿⣿⣿⣿⡿⢡⢯⣿⣿⣿⣿⣿⣿⣿⣧⡿⣾⣷⣿⣿⢿⣿⡇⠉⠁⠀⠀
⠀⠀⠀⠀⣿⣥⣾⣿⣿⣿⣿⣿⣿⣿⡇⣭⣿⣿⣿⣿⠃⠞⠟⣸⣿⠏⣸⣧⣀⠿⢿⣿⣿⣟⣿⣿⣿⣿⣽⣿⢿⣿⣿⣿⣿⠁⠀⠀⠀⠀
⠀⠀⠀⠈⠛⣹⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⣟⣿⣿⡿⢶⣦⣄⣿⠏⠀⣿⣟⣿⣶⠾⣿⣟⣋⣛⣿⣿⣿⣿⡇⣻⣿⣿⣿⡏⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠟⠛⠫⣿⣿⣿⣿⣿⡿⣧⠛⣿⠛⣿⣿⣿⣷⡌⠹⡟⠀⠀⠉⡟⠋⢠⣾⣿⣿⣿⡟⣿⣿⣿⣿⢀⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠘⠋⣾⣷⣿⣿⣧⠙⠀⠙⢣⠝⠛⠋⣽⣷⢦⠇⠀⠀⠘⠁⣤⣾⣿⠝⠛⠉⠘⢻⣿⣿⢿⣼⣷⡟⢻⣷⠉⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠐⠟⢻⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠉⠀⠀⠀⠀⠀⠀⠈⠛⠀⠀⠀⠀⠀⣾⠟⠀⢸⣷⣿⡇⠀⠛⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠁⠀⢹⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⡧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠈⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⢻⡿⠈⠁⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣇⠀⠀⠀⠀⠀⠀⠀⠀⠲⣄⠀⡄⠆⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⣀⠀⠀⣠⣾⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⢻⣆⠀⠛⠁⠶⣶⣶⣶⣶⣶⣶⡶⠆⠘⠋⣠⡾⢫⣾⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠛⠀⠙⣷⡀⠀⠀⠙⠛⠛⠛⠛⠋⠁⠀⢀⣴⠋⠀⣾⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣿⣰⣦⡀⠸⣿⣦⡀⠀⠀⠀⠀⠀⠀⢀⣴⡟⠁⠀⠐⢻⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⡄⢺⣿⡄⠹⣿⠻⢦⣤⣤⣤⣤⣶⣿⡟⢀⣀⠀⠀⢸⣿⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣮⣿⣿⡀⠹⡷⣦⣀⡀⡀⢸⣿⠏⢠⣾⣿⠀⠀⣾⣿⣿⣿⣿⣶⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀
⣀⣤⣴⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠘⣷⣻⡟⠀⡼⠁⣴⣿⣿⣯⣥⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⣀⠀⠀⠀⠀
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣯⣿⣤⣤⣤⣬⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⣄
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
*/
/*Write you code here -------- */
public class Main {
public static void main(String[] args) throws IOException {
MyTemplate.FastIO jio = new MyTemplate().new FastIO();
int t = jio.nextInt();
while (t-- > 0) {
int n=jio.nextInt();
int arr[]=jio.readIntArray(n);
HashSet<Integer> st=new HashSet<>();
for(int i=0;i<n;i++){
st.add(arr[i]);
}
if(st.size()==1 && arr[0]==0){
jio.println(0);
continue;
}
if(arr[0]==0 || arr[n-1]==0){
if(arr[0]==0 && arr[n-1]!=0 ){
jio.println(min(arr, 1,n-1)!=0?1:2);
}
else if(arr[0]!=0 && arr[n-1]==0){
jio.println(min(arr, 0,n-2)!=0?1:2);
}
else{
jio.println(min(arr, 1,n-2)!=0?1:2);
}
continue;
}
jio.println(min(arr,0,n-1)==0?2:1);
}
}
public static int min(int arr[],int a,int b){
int min=(int)1e9;
for(int i=a;i<=b;i++){
min=Math.min(min,arr[i]);
}
return min;
}
}
/*end here-------------------- */
class MyTemplate {
class Calc{
public static ArrayList<Integer> generatePrimes(int n) {
// Create an array to track prime status
boolean[] isPrime = new boolean[n + 1];
ArrayList<Integer> primes = new ArrayList<>();
// Initialize all numbers as prime
for (int i = 2; i <= n; i++) {
isPrime[i] = true;
}
// Sieve of Eratosthenes algorithm
for (int p = 2; p * p <= n; p++) {
if (isPrime[p]) {
// Mark all multiples of p as non-prime
for (int multiple = p * p; multiple <= n; multiple += p) {
isPrime[multiple] = false;
}
}
}
// Collect all prime numbers
for (int i = 2; i <= n; i++) {
if (isPrime[i]) {
primes.add(i);
}
}
return primes;
}
public static long GCD(long a,long b){
if(a<b){
long temp=a;
a=b;
b=temp;
}
if(b==0){
return a;
}
return GCD(b,a%b);
}
public static int GCD(int a,int b){
if(a<b){
int temp=a;
a=b;
b=temp;
}
if(b==0){
return a;
}
return GCD(b,a%b);
}
public static void swap(int a,int b){
int temp=a;
a=b;
b=temp;
}
public static void swap(long a,long b){
long temp=a;
a=b;
b=temp;
}
}
class FastIO {
private BufferedReader br;
private BufferedWriter bw;
private StringTokenizer st;
// Constructor to initialize input and output
public FastIO() {
br = new BufferedReader(new InputStreamReader(System.in));
bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
// Method to read next line
public String nextLine() throws IOException {
return br.readLine();
}
// Method to read next token
public String next() throws IOException {
while (st == null || !st.hasMoreElements()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
// Method to read an integer
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
// Method to read a long
public long nextLong() throws IOException {
return Long.parseLong(next());
}
// Method to read a double
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
// Method to read an integer array
public int[] readIntArray(int size) throws IOException {
int[] arr = new int[size];
for (int i = 0; i < size; i++) {
arr[i] = nextInt();
}
return arr;
}
// Method to read a long array
public long[] readLongArray(int size) throws IOException {
long[] arr = new long[size];
for (int i = 0; i < size; i++) {
arr[i] = nextLong();
}
return arr;
}
// Method to print a string without a newline
public void print(String str) throws IOException {
bw.write(str);
bw.flush();
}
// Method to print a string followed by a newline
public void println(String str) throws IOException {
bw.write(str + "\n");
bw.flush();
}
// Method to print an integer followed by a newline
public void println(int num) throws IOException {
bw.write(num + "\n");
bw.flush();
}
// Method to print a long followed by a newline
public void println(long num) throws IOException {
bw.write(num + "\n");
bw.flush();
}
// Method to print an integer array
public void printArray(int[] arr) throws IOException {
for (int i = 0; i < arr.length; i++) {
bw.write(arr[i] + (i == arr.length - 1 ? "" : " "));
}
bw.write("\n");
bw.flush();
}
// Method to print a long array
public void printArray(long[] arr) throws IOException {
for (int i = 0; i < arr.length; i++) {
bw.write(arr[i] + (i == arr.length - 1 ? "" : " "));
}
bw.write("\n");
bw.flush();
}
// Flush the output stream
public void flush() throws IOException {
bw.flush();
}
// Close input and output streams
public void close() throws IOException {
br.close();
bw.close();
}
}
}
/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣬⢧⣬⡒⠀⠀⠀⢀⣠⠝⠉⠉⠉⠉⠁⠀⠸⠟⠙⠹⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣈⡹⠒⠚⠁⣠⠞⣉⠀⢀⡴⠚⠉⠁⡀⠀⠀⠀⠀⠀⠀⠉⠙⠲⠶⣶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⡤⠴⠞⠁⠀⠀⢀⢞⡡⠊⠁⡰⢋⣠⣶⠖⠋⠁⠀⠠⡄⠀⠀⠀⠀⠀⠀⢠⡀⣀⣉⠭⠿⠟⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⢯⣍⡻⠭⠭⠤⠄⣀⠴⠂⠀⣰⠟⠉⠀⣠⡾⠛⢩⣷⠃⠀⠀⠀⠀⠀⢱⠀⡆⡀⣠⠀⠀⠘⢿⠮⣷⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⣛⡿⣣⢯⠄⡴⢫⡅⠀⢀⡴⠃⠀⠀⣾⠇⠀⠀⢸⠀⠀⠀⠸⡄⡇⡇⣿⡇⠀⠀⠈⢷⡄⠙⢿⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡾⠋⣰⠟⣡⢞⡵⠋⠀⢠⠎⠀⡤⠀⢠⡟⠀⠀⠀⡇⢠⠀⡀⠀⣷⣷⣧⢿⡗⢲⡀⠀⢸⡿⡄⠀⠙⢾⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⢴⣚⣡⠞⠞⠁⣾⠵⠋⢀⢆⣴⠏⣠⠊⢀⣠⡼⠀⠀⠀⠀⡷⠘⣷⡇⢰⣿⣿⣳⡼⣧⠸⣷⠀⠀⠇⠙⢦⡀⠈⢿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠉⠁⣼⠃⣠⡾⠉⠀⠀⢀⡿⠋⣸⠞⢁⡠⠋⠁⠀⠀⠀⠀⣴⠃⣸⣿⡃⢸⣱⡸⢻⣿⣿⣿⣿⢸⠀⢤⠀⢀⠙⢦⡀⠹⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⡷⣾⣿⠃⠀⡄⢀⡜⠁⠐⡧⠴⠊⠀⠀⠀⢀⠀⢠⠖⠛⢠⣿⡏⡇⣸⣿⣿⣾⣿⣿⣿⣿⣸⡄⠈⣦⠈⣧⠠⣷⡦⣝⡟⠦⣄⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡿⠟⢰⣿⠃⠀⣼⢠⡟⡀⠀⠀⡇⢀⡇⢰⠀⢀⡎⢠⡏⠀⡤⢸⣿⡇⣧⠿⣯⣿⣿⣿⣿⣿⣿⣷⣷⢀⡈⢧⣹⢦⡙⢷⡀⠉⠙⠛⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠤⠒⠃⠀⣰⢟⣥⠃⢠⣧⡟⣰⡇⠀⠀⢀⡞⣰⣧⠀⡜⣰⢻⠃⢸⣸⠈⢻⣳⣇⡿⣿⠘⢿⣿⣼⣿⣏⣿⣿⡇⠟⣦⡉⢳⡘⠓⢿⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣞⣵⣟⠁⢀⣾⢿⡹⣹⠀⢠⢀⠞⣰⣻⠃⣰⡷⠃⣸⡆⡏⡿⠀⢸⠉⢹⡇⣿⣿⣼⣿⡿⣿⣿⣼⣹⡀⢠⣿⣿⠸⡗⢶⣶⣯⡿⠶⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢀⣴⠿⠋⣞⡼⢀⡞⢹⣿⡇⣿⠀⡟⣏⡼⣱⣯⡶⠿⠁⡄⢹⣿⢧⠃⠀⢸⠀⣼⡏⢙⣿⠻⣿⣷⣽⣿⣿⡻⡇⢸⢯⡇⣷⡿⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⣰⡿⣣⣿⠀⣼⣿⣿⡟⢸⢀⣿⠱⢋⡟⠀⢀⠆⡇⣼⡏⠸⢠⠃⢻⣴⣿⠁⢸⣿⠀⣿⢻⣿⢿⡍⡛⣇⣾⣦⣷⡈⢿⠯⢷⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣯⡟⢩⡟⣰⠟⢦⣯⣇⣼⣿⡇⠀⣿⡇⠀⣼⣿⢳⠀⡇⡀⣾⢰⣼⣿⣿⣀⣿⣿⡄⣿⣿⣿⠀⡇⣅⣿⣵⠇⣿⣿⣮⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀
⠀⠀⠀⠀⠀⠀⠀⠀⠘⠛⠛⠀⢸⣵⢻⣄⣆⣿⣿⣿⣿⡇⢀⣿⡇⢠⣻⢹⣾⣰⢷⢷⣿⢸⣿⣿⣻⣿⡿⠿⣿⣿⠾⡏⢰⠃⣿⡿⡟⢿⣏⣻⡈⠙⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⠇⢸⣿⣾⣷⣻⣏⣿⣇⣼⡿⡇⣸⣿⣾⣷⣿⣩⣿⣯⡿⢡⣿⣿⣿⣿⣿⣿⣯⣄⣹⡟⣤⣿⣾⢀⣾⠏⢿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠁⠀⢸⣿⠻⣏⡟⣿⣿⣿⣿⣡⣿⣿⣿⣿⣿⣿⣿⣿⣿⡓⠃⢘⣿⠟⣿⣭⢳⠉⠹⠿⢠⣿⡏⣹⣿⣿⠀⠀⠈⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠾⠃⠀⠙⣦⣻⣿⠿⠙⡿⢿⣿⣽⠋⢯⣿⡏⠀⠻⠃⣤⣻⢏⣀⠛⠟⢋⣤⠗⣠⡄⣿⡴⠋⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⣿⠲⠀⠀⠘⠋⠛⠀⠈⠿⠁⠀⠀⠀⠐⠌⠓⠛⣿⠿⡿⠓⠀⠉⢠⣟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣴⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢻⣟⡭⠁⠀⢀⣾⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣾⣿⣿⣿⣿⡌⢷⡀⢤⡄⠀⠀⠀⠀⠳⣄⢀⡤⠀⠀⠀⠀⠀⣿⣷⠀⢀⣼⣿⣿⣿⣿⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣴⣾⣿⣿⣿⣿⣿⣿⣿⡇⠀⢿⣄⠋⠲⢶⣤⣀⣀⣤⣤⣶⣶⣶⣶⣶⠖⠋⠀⣠⠞⢹⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠛⢦⡀⡓⠿⣿⣟⣻⡿⢖⣚⣿⠟⠁⢀⣴⠞⠁⠀⣾⣿⣿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠄⠀⠘⡎⣿⣷⣤⡈⠛⠛⠻⠛⠛⠉⢁⣴⣿⠋⠐⣠⣾⣿⣿⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣄⠀⠀⢁⠘⣿⢷⣤⣀⣀⠀⣀⣠⣿⠿⡻⣡⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣠⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡖⠘⠦⢼⣟⠸⠛⢻⣻⣽⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣻⣿⣿⣿⣿⣿⣿⣿⣶⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⣬⠽⣷⣶⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⠀⠀⠀⠀⠀⠀
⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣋⣀⣿⠏⠰⢺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡬⣿⣿⢯⣷⣶⠝⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡘⠛⢤⣀
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣌⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣷⣶⢿⣷⣶⢤⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠉
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⢿⣒⣺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣀⠀
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢧⣴⢾⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⢛⣩⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶
⣿⣿⣿⣿⣿⣿⣿⣦⣭⣉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣮⣿⡖⣿⣿⣿⣿⣿⣿⣿⣿⣶⣿⠿⠿⠿⢿⣿⣿⠿⢿⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⠿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣭⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣶⣶⠿⠟⢛⣥⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣏⣾⣟⢿⣿⣿⣿⣿⣿
*/
|
2049A
|
wrong_submission
|
297,493,725 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class main{
public static void main(String args[]){
Scanner read = new Scanner(System.in);
int t = read.nextInt();
for(int q=0; q<t; q++){
int n = read.nextInt();
int[] arr = new int[n];
for(int i=0; i<n; i++){
arr[i] = read.nextInt();
}
int cnt = 0;
boolean allzero = true;
boolean allnonzero = true;
boolean fl = false;
if(arr[n-1]==0 && arr[0]==0){
fl = true;
}
for(int i: arr){
if(i!=0){
allzero = false;
cnt++;
}
}
for(int i:arr){
if(i==0){
allnonzero = false;
}
}
if(allzero==true){
System.out.println(0);
}
else if(allnonzero==true){
System.out.println(1);
}
else if(cnt==(n-1) && (arr[0]==0 || arr[n-1]==0)){
System.out.println(1);
}
else if(fl && cnt==(n-2)){
System.out.println(1);
}
else{
System.out.println(2);
}
}
}
}
|
2049A
|
wrong_submission
|
300,341,508 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
t=int(input())
for _ in range(t):
n=int(input())
a=list(map(int,input().split()))
if sum(a)==0:
print(0)
elif 0 not in a:
print(1)
elif a.count(0)==1 and a[0]==0 or a.count(0)==1 and a[-1]==0:
print(1)
elif a.count(0)==2 and a[0]==0 and a[-1]==0:
print(1)
else:
print(2)
|
2049A
|
wrong_submission
|
297,601,001 |
Java 8
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class JavaCode{
public static int solve(int n , int a[] , int z){
if(z == a.length){
return 0;
}
if(z == 0){
return 1;
}
int prev= a[0];
boolean flag = false;
for(int i =1 ; i < n-1 ; i++){
if(a[i] == 0 && prev != 0 && a[i+1] != 0){
flag = true;
}
prev = a[i];
}
if(flag){
return 2;
}
return 1;
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int a[] =new int[n];
int zero = 0;
for(int i =0 ; i < n ; i++){
a[i] = sc.nextInt();
if(a[i] == 0){
zero++;
}
}
System.out.println(solve(n , a , zero));
}
}
}
|
2049A
|
wrong_submission
|
297,472,642 |
PyPy 3-64
|
WRONG_ANSWER on test 4
|
def algo():
n = int(input())
word = input().replace(" ", "").strip("0")
zeros = word.count("0")
if len(word) == 0:
return 0
if zeros > 0:
return 2
return 1
tests = range(int(input()))
for i in tests:
print(algo())
|
2049A
|
wrong_submission
|
297,508,533 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
t=int(input())
for _ in range(t):
n=int(input())
a=list(map(int,input().split()))
v=0
nb=0
if max(a)==0:
print(0)
else:
for j in range(n-1):
if a[j]!=0 and v!=8:
nb+=1
v=8
if a[j]==0 and v==8:
v=0
if nb>=2:
print(2)
else:
print(1)
|
2049A
|
wrong_submission
|
297,771,860 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class A_MEX_Destruction {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int z=0;z<t;z++){
int n = sc.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int c=0;boolean flag = true;
for(int i=1;i<n-1;i++){
if(a[i]==0){
c++;
}
}
if(n==1){
if(a[0]==0)System.out.println(0);
else System.out.println(1);
}else if(n==2){
if(a[0]==0 && a[1]==0)System.out.println(0);
else System.out.println(1);
}
else if(c==n-2){
System.out.println(0);
}else{
if(c==0){
System.out.println(1);
}else{
System.out.println(2);
}
}
}
}
}
|
2049A
|
wrong_submission
|
297,497,967 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.io.*;
import java.util.*;
public class Main{
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ;
public static void main(String[] args) throws IOException{
int t = Integer.parseInt(br.readLine());
out :while(t-- > 0){
int n = Integer.parseInt(br.readLine());
String[] s = br.readLine().split(" ");
int[] a = new int[n+1];
for(int i = 0; i < n; i ++){
a[i] = Integer.parseInt(s[i]);
}
if(n == 1){
System.out.println(a[0] == 0?0:1);
continue out ;
}
int ans = 0;
if(a[0] == 0) ans++;
if(a[n-1] == 0) ans++;
if(n == 2 && ans == n){
System.out.println(0);
continue out ;
}else if(n == 2){
System.out.println(1);
continue out ;
}
for(int i = 1; i < n -1; i ++){
if(a[i] == 0) ans++;
if(a[i] == 0 && a[i+1] !=0 && a[i-1] != 0){
System.out.println(2);
continue out;
}
}
if(ans == n){
System.out.println(0);
continue out;
}else{
System.out.println(1);
}
}
}
}
|
2049A
|
wrong_submission
|
297,459,667 |
C++20 (GCC 13-64)
|
WRONG_ANSWER on test 2
|
// VK5
#include <bits/stdc++.h>
using namespace std;
// ready for the action
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;
#define ll long long
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define fsort(a) sort(a.begin(), a.end())
#define ssort(a) sort(all(a), sortbysec);
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define bs(a, b) binary_search(all(a), b)
#define pb(a) push_back(a)
#define sz(a) a.size()
#define vread(a) \
for (auto &x : a) \
cin >> x
#define vprint(a) \
for (auto &x : a) \
cout << x << ' '
#define nl '\n';
#define mod 1000000007
void bs_real()
{
float l = 0.0f, r = 1e14f;
for (ll i = 0; i < 1000 && l + 1e-6 < r; ++i)
{
float mid = 0.5f * (l + r);
// check;
if (true)
r = mid;
else
l = mid;
}
}
long long binpow(long long a, long long b)
{ // modular exponentiation
a %= mod;
long long res = 1;
while (b > 0)
{
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
ll fact(ll n)
{
ll ans = 1;
for (ll i = 1; i <= n; i++)
{
ans = (ans * i) % mod;
}
return ans;
}
ll C(ll n, ll k, ll fact[])
{
if (n < k)
return 0LL;
return (fact[n] * binpow((fact[n - k] * fact[k]) % mod, mod - 2)) % mod;
}
bool sortbysec(const pair<ll, ll> &a,
const pair<ll, ll> &b)
{
if (a.second != b.second)
return a.second < b.second;
return a.first < b.first;
}
// Returns factorial of n
void solve()
{
ll n;
cin >> n;
deque<ll> a(n), p(n);
vread(a);
ll h = 0;
p = a;
sort(all(p));
if (p[0] == p[n - 1])
{
cout << 0 << endl;
return;
}
while (a.front() == 0)
{
a.pop_front();
}
while (a.back() == 0)
{
a.pop_back();
}
ll zero = 0;
for (ll i = 0; i < a.size(); i++)
{
if (a[i] == 0)
{
zero++;
}
}
cout << 1 + (zero!=0)<< endl;
}
int32_t main()
{
cin.tie(nullptr);
cout.tie(nullptr);
ll t;
cin >> t;
while (t--)
solve();
return 0;
}
|
2049A
|
wrong_submission
|
297,460,506 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
#from math import ceil,log,lcm,gcd,isfinite
#from collections import deque,Counter,defaultdict
#from bisect import bisect
#from heapq import heappush,heappop
#from fractions import Fraction as fr
#from sortedcontainers import SortedList,SortedSet,SortedDict
#from random import randint
from sys import stdin,stdout
input=lambda:stdin.readline().rstrip()
print=lambda *x,sep=' ',end='\n':stdout.write(sep.join(map(str,x))+end)
def out(l):
print(' '.join(map(str,l)))
def yes():
print('Yes')
def no():
print('No')
def alice():
print('Alice')
def bob():
print('Bob')
def solve():
n=int(input())
a=list(map(int,input().split()))
cnt=a.count(0)
if cnt==n:
print(0)
else:
if cnt==0 or (a[0]==0 and cnt==1) or (a[-1]==0 and cnt==1) or (cnt==2 and a[0]==0 and a[-1]==0):
print(1)
else:
print(2)
for _ in range(int(input())):
solve()
|
2049A
|
wrong_submission
|
297,711,609 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
for k in range(int(input())):
n=int(input())
s=input().split(" ")
t=s[1:-1]
br=0
for i in range(n):
if i>0:
if s[i]=="0" and "0"!=s[i-1] or s[i]!="0" and "0"==s[i-1]:
br+=1
if "0" in t:
r=2
else:
r=1
if br==1:
r=1
if s.count("0")==n:
r=0
print(r)
|
2049A
|
wrong_submission
|
297,477,919 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class ans {
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int t=s.nextInt();
s.nextLine();
for (int i=0;i<t;i++){
int n=s.nextInt();
int sum=0;
int[] arr=new int[n];
for (int j=0;j<n;j++){
arr[j]=s.nextInt();
sum=sum+arr[j];
}
if (sum==0){
System.out.println(0);
}
else{
int d=0;
for (int k=1;k<n-1;k++){
if (arr[k]==0){
d++;
}
}
if (d==0 && ((arr[0]!=0 && arr[n-1]!=0) || (arr[0]==0 && arr[n-1]==0) || (arr[0]==0 || arr[n-1]==0))){
System.out.println(1);
}
else {
System.out.println(2);
}
}
}
}
}
|
2049A
|
wrong_submission
|
297,624,772 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes heren
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int arr[]=new int[n];
int count=0;
for(int i=0;i<n;i++) {
arr[i]=sc.nextInt();
if(arr[i]==0)
count++;
}
boolean flag=false;
for(int i=1;i<n-1;i++)
{
if(arr[i]==0&&arr[i+1]!=0&&arr[i-1]!=0)
{
flag=true;
break;
}
}
if(flag)
System.out.println(2);
else{
if(count==n)
System.out.println(0);
else
System.out.println(1);
}
}
}
}
|
2049A
|
wrong_submission
|
297,615,832 |
C++20 (GCC 13-64)
|
WRONG_ANSWER on test 2
|
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin() , a.end()
#define int long long
#define mpi make_pair
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t ; cin >> t ;
while(t--){
int n ; cin >> n ;
vector<int>a(n);
for(int i = 0 ; i < n ; i ++) cin >>a[i];
int cnt = 0 ,ans = 0 ;
for(int i = 0 ; i < n ; i++){
if(a[i]==0) cnt++; }
if(cnt==n)ans=0;
else if(cnt==0)ans=1;
else if((cnt==2||cnt==1)&&(a[0]==0||a[n-1]==0))ans=1;
else ans=2;
cout<<ans<<"\n";
}
return 0;
}
|
2049A
|
wrong_submission
|
297,527,584 |
Java 21
|
WRONG_ANSWER on test 2
|
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.Scanner;
public class Main {
public static int ans(int[]arr,int n)
{int count=0;
for(int i=0;i<n;i++)
{if(arr[i]==0)
{count++;}}
if(count==n){return 0;}
if(count==0){return 1;}
if(arr[0]!=0)
{if(arr[n-1]!=0){
return 2;}
else{ if(count>1){return 2;}
return 1;}
}
else{
if(arr[n-1]!=0)
{if(count==1)
{return 1;}
return 2;}
else
{ if(count>2)
{return 2;}
return 1;}
}
}
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
for(int i=0;i<t;i++)
{int n=s.nextInt();
int arr[]=new int[n];
for(int j=0;j<n;j++)
{arr[j]=s.nextInt();}
System.out.println(ans(arr,n));
}
}
}
|
2049A
|
wrong_submission
|
297,467,046 |
Java 21
|
WRONG_ANSWER on test 3
|
import java.net.Inet4Address;
import java.util.*;
public class pupil {
static class Pair<T, U> {
public T first;
public U second;
public Pair(T first, U second) {
this.first = first;
this.second = second;
}
@Override
public String toString() {
return "(" + first + ", " + second + ")";
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Pair<?, ?> pair = (Pair<?, ?>) obj;
return first.equals(pair.first) && second.equals(pair.second);
}
}
// XOR OF ALL ELEMENTS FROM L TO R
public static long findXor(long n) {
long mod = n % 4;
if (mod == 0) return n;
else if (mod == 1) return 1;
else if (mod == 2) return n + 1;
else if (mod == 3) return 0;
return 0;
}
public static long findXor(long l, long r) {
return (findXor(l - 1) ^ findXor(r));
}
public static <T extends Comparable<T>> boolean nextPermutation(T[] nums) {
int n = nums.length;
int k = -1;
for (int i = n - 2; i >= 0; i--) {
if (nums[i].compareTo(nums[i + 1]) < 0) {
k = i;
break;
}
}
if (k == -1) return false;
int l = -1;
for (int i = n - 1; i > k; i--) {
if (nums[i].compareTo(nums[k]) > 0) {
l = i;
break;
}
}
T temp = nums[k];
nums[k] = nums[l];
nums[l] = temp;
reverse(nums, k + 1, n - 1);
return true;
}
private static <T> void reverse(T[] nums, int start, int end) {
while (start < end) {
T temp = nums[start];
nums[start] = nums[end];
nums[end] = temp;
start++;
end--;
}
}
public static long sum(long[] nums) {
long res = 0;
for (long i : nums) res += i;
return res;
}
public static long fmax(long[] nums) {
long max = nums[0];
for (long num : nums) if (num > max) max = num;
return max;
}
public static long fmin(long[] nums) {
long min = nums[0];
for (long num : nums) if (num < min) min = num;
return min;
}
public static boolean nextPermutation(long[] nums) {
int n = nums.length;
int k = -1;
for (int i = n - 2; i >= 0; i--) {
if (nums[i] < nums[i + 1]) {
k = i;
break;
}
}
if (k == -1) {
Arrays.sort(nums);
return false;
}
int l = -1;
for (int i = n - 1; i > k; i--) {
if (nums[i] > nums[k]) {
l = i;
break;
}
}
long temp = nums[k];
nums[k] = nums[l];
nums[l] = temp;
reverse(nums, k + 1, n - 1);
return true;
}
public static void swap(long[] nums, int i, int j) {
long temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
public static void reverse(long[] nums, int start, int end) {
while (start < end) {
swap(nums, start, end);
start++;
end--;
}
}
public static int upper_bound(int[] a, int key) {
int l = 0, r = a.length;
while (l < r) {
int mid = l + (r - l) / 2;
if (a[mid] <= key) l = mid + 1;
else r = mid;
}
return l;
}
public static int lower_bound(int[] a, int key) {
int l = 0, r = a.length;
while (l < r) {
int mid = l + (r - l) / 2;
if (a[mid] < key) l = mid + 1;
else r = mid;
}
return l;
}
public static int power(int x, int y, int mod) {
long res = 1;
while (y > 0) {
if (y % 2 != 0) res = (res * (long) x) % mod;
y = y >> 1;
x = (int) (((long) x * x) % mod);
}
return (int) res;
}
public static long gcd(long a, long b) {
if (b == 0) return a;
else return gcd(b, a % b);
}
//Factorial Logic
// static final int MAX_N = 200000;
// static final int MOD = 1_000_000_007;
// static long[] fact = new long[MAX_N + 1];
//
// static {
// fact[0] = 1;
// for (int i = 1; i <= MAX_N; i++) {
// fact[i] = (fact[i - 1] * i) % MOD;
// }
// }
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int[] a = new int[n];
for(int i = 0; i < n; i++) a[i] = sc.nextInt();
int c = 0;
for(int i : a){
if(i == 0) c++;
}
if(c == 0) System.out.println(1);
else if(c == n) System.out.println(0);
else{
int i = 0;
while(i < n && a[i] == 0) i++;
int j = n - 1;
int y = 0;
while(j >= 0 && a[j] == 0) j--;
for(int l = i; l <= j; l++){
if(a[l] == 0){
y++;
}
}
Arrays.sort(a);
int x = 0;
for(int z = 0; z < n; z++){
if(x == a[z]) x++;
else break;
}
if(x == n){
System.out.println(1);
} else {
if(y > 0){
System.out.println(2);
}
else System.out.println(1);
}
}
}
}
}
|
2049A
|
wrong_submission
|
297,489,232 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0;i<t;i++) {
int n = sc.nextInt();
int[] arr = new int[n];
for(int j=0;j<n;j++) {
arr[j] = sc.nextInt();
}
boolean q = true;
for(int j=0;j<n;j++) {
if(arr[j] == 0) {
continue;
}else {
q = false;
break;
}
}
if(q == true) {
System.out.println(0);
continue;
}
int s = 0;
int e = n-1;
for(int j=0;j<n;j++) {
if(arr[j] == 0) {
s = j;
}else {
break;
}
}
for(int j=n-1;j>0;j--) {
if(arr[j] == 0) {
e = j;
}else {
break;
}
}
int res = 1;
for(int j=s+1;j<e-1;j++) {
if(arr[j] == 0) {
res = 2;
}
}
System.out.println(res);
}
}
}
|
2049A
|
wrong_submission
|
297,460,229 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
########################################################################################################################
# -----------------------------------------------AUTHOR: Omm AKA Antonio Colapso---------------------------------------#
########################################################################################################################
import time
import bisect
import functools
import math
import os
import random
import re
import sys
import threading
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import cmp_to_key, lru_cache, reduce
from heapq import heapify, heappop, heappush, heappushpop, nlargest, nsmallest
from io import BytesIO, IOBase
from itertools import accumulate, combinations, permutations
from operator import add, iand, ior, itemgetter, mul, xor
from string import ascii_lowercase, ascii_uppercase
from typing import *
import collections
import heapq
import itertools
def vsInput():
sys.stdin = open('inputf.in', 'r')
sys.stdout = open('outputf.out', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip('\r\n')
#########################################################################################################
#-------------------------------------Functions : Antonio Colapso---------------------------------------#
#########################################################################################################
def SieveOfEratosthenes(n):
prime = [True for i in range(n+1)]
p = 2
l = []
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
for p in range(2, n+1):
if prime[p]:
l.append(p)
# print(p)
else:
continue
return l
def isPrime(n):
prime_flag = 0
if n > 1:
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
prime_flag = 1
break
if prime_flag == 0:
return True
else:
return False
else:
return False
def gcdofarray(a):
x = 0
for p in a:
x = math.gcd(x, p)
return x
def printDivisors(n):
i = 1
ans = []
while i <= math.sqrt(n):
if (n % i == 0):
if (n / i == i):
ans.append(i)
else:
ans.append(i)
ans.append(n // i)
i = i + 1
ans.sort()
return ans
def binaryToDecimal(n):
return int(n, 2)
def countTriplets(a, n):
s = set()
for i in range(n):
s.add(a[i])
count = 0
for i in range(n):
for j in range(i + 1, n, 1):
xr = a[i] ^ a[j]
if xr in s and xr != a[i] and xr != a[j]:
count += 1
return int(count // 3)
def countOdd(L, R):
N = (R - L) // 2
if (R % 2 != 0 or L % 2 != 0):
N += 1
return N
def isPalindrome(s):
return s == s[::-1]
def suffixsum(a):
test_list = a.copy()
test_list.reverse()
n = len(test_list)
for i in range(1, n):
test_list[i] = test_list[i] + test_list[i - 1]
return test_list
def prefixsum(b):
a = b.copy()
for i in range(1, len(a)):
a[i] += a[i - 1]
return a
def badachotabadachota(nums):
nums.sort()
i = 0
j = len(nums) - 1
ans = []
cc = 0
while len(ans) != len(nums):
if cc % 2 == 0:
ans.append(nums[j])
j -= 1
else:
ans.append(nums[i])
i += 1
cc += 1
return ans
def chotabadachotabada(nums):
nums.sort()
i = 0
j = len(nums) - 1
ans = []
cc = 0
while len(ans) != len(nums):
if cc % 2 == 1:
ans.append(nums[j])
j -= 1
else:
ans.append(nums[i])
i += 1
cc += 1
return ans
def primeFactors(n):
ans = []
while n % 2 == 0:
ans.append(2)
n = n // 2
for i in range(3, int(math.sqrt(n))+1, 2):
while n % i == 0:
ans.append(i)
n = n // i
if n > 2:
ans.append(n)
return ans
def closestMultiple(n, x):
if x > n:
return x
z = (int)(x / 2)
n = n + z
n = n - (n % x)
return n
def getPairsCount(arr, n, sum):
m = [0] * 1000
for i in range(0, n):
m[arr[i]] += 1
twice_count = 0
for i in range(0, n):
twice_count += m[int(sum - arr[i])]
if (int(sum - arr[i]) == arr[i]):
twice_count -= 1
return int(twice_count / 2)
def remove_consec_duplicates(test_list):
res = [i[0] for i in itertools.groupby(test_list)]
return res
def BigPower(a, b, mod):
if b == 0:
return 1
ans = BigPower(a, b//2, mod)
ans *= ans
ans %= mod
if b % 2:
ans *= a
return ans % mod
def nextPowerOf2(n):
count = 0
if (n and not (n & (n - 1))):
return n
while (n != 0):
n >>= 1
count += 1
return 1 << count
# This function multiplies x with the number
# represented by res[]. res_size is size of res[]
# or number of digits in the number represented
# by res[]. This function uses simple school
# mathematics for multiplication. This function
# may value of res_size and returns the new value
# of res_size
def multiply(x, res, res_size):
carry = 0 # Initialize carry
# One by one multiply n with individual
# digits of res[]
i = 0
while i < res_size:
prod = res[i] * x + carry
res[i] = prod % 10 # Store last digit of
# 'prod' in res[]
# make sure floor division is used
carry = prod//10 # Put rest in carry
i = i + 1
# Put carry in res and increase result size
while (carry):
res[res_size] = carry % 10
# make sure floor division is used
# to avoid floating value
carry = carry // 10
res_size = res_size + 1
return res_size
def Kadane(a, size):
max_so_far = -1e18 - 1
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if max_ending_here < 0:
max_ending_here = 0
return max_so_far
def highestPowerof2(n):
res = 0
for i in range(n, 0, -1):
if ((i & (i - 1)) == 0):
res = i
break
return res
def MEX(nList, start):
nList = set(nList)
mex = start
while mex in nList:
mex += 1
return mex
def getClosest(val1, val2, target):
if (target - val1 >= val2 - target):
return val2
else:
return val1
def tobinary(a): return bin(a).replace('0b', '')
def nextPerfectSquare(N):
nextN = math.floor(math.sqrt(N)) + 1
return nextN * nextN
def modFact(n, p):
result = 1
for i in range(1, n + 1):
result *= i
result %= p
return result
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den, p - 2, p)) % p
def sqrtl(x):
if (x == 0 or x == 1):
return x
start = 1
end = x//2
while (start <= end):
mid = (start + end) // 2
if (mid*mid == x):
return mid
if (mid * mid < x):
start = mid + 1
ans = mid
else:
end = mid-1
return ans
def ceill(a, b):
return (a // b) + int(a % b != 0)
def LcmOfArray(arr, idx):
# lcm(a,b) = (a*b/gcd(a,b))
if (idx == len(arr)-1):
return arr[idx]
a = arr[idx]
b = LcmOfArray(arr, idx+1)
return int(a*b / math.gcd(a, b))
def base_change_Excluding_certain_Digits_or_Base_conversion(number_of_hated_digits, list_of_hated_digits, find_nth_number):
digits1 = '0123456789'
digits = "" # only digits we want
for i in digits1:
if int(i) not in list_of_hated_digits:
digits += i
# final integer base after excluding "t" hated digits
base = 10-number_of_hated_digits
sol = []
while find_nth_number:
sol.append(digits[find_nth_number % base])
find_nth_number //= base
sol.reverse()
return ("".join(sol))
# print(base_change_Excluding_certain_Digits_or_Base_conversion(2,[1,8],10))
def counter(l):
cts = {}
for x in l:
cts[x] = cts.get(x, 0) + 1
return cts
def mimic_string(sm,sn): #//minimum steps to make both string equal
prev_dp = list(range(len(sm) + 1))
curr_dp = [0] * (len(sm) + 1)
for i in range(1, len(sn) + 1):
curr_dp[0] = i
for j in range(1, len(sm) + 1):
if sn[i - 1] == sm[j - 1]:
curr_dp[j] = prev_dp[j - 1]
else:
curr_dp[j] = min(prev_dp[j], prev_dp[j - 1], curr_dp[j - 1]) + 1
prev_dp = curr_dp[:]
return(curr_dp[len(sm)])
def LCS_length(s, t):
m, n = len(s), len(t)
prev_dp = [0] * (n + 1)
curr_dp = [0] * (n + 1)
for i in range(1, m + 1):
for j in range(1, n + 1):
if s[i - 1] == t[j - 1]:
curr_dp[j] = prev_dp[j - 1] + 1
else:
curr_dp[j] = max(prev_dp[j], curr_dp[j - 1])
prev_dp = curr_dp[:]
return curr_dp[n]
lcs = ""
i, j = m, n
while i > 0 and j > 0:
if s[i - 1] == t[j - 1]:
lcs = s[i - 1] + lcs
i -= 1
j -= 1
elif dp[i - 1][j] > dp[i][j - 1]:
i -= 1
else:
j -= 1
return lcs
def kadane(arr):
n = len(arr)
max_ending_here = arr[0]
max_so_far = arr[0]
for i in range(1, n):
max_ending_here = max(arr[i], max_ending_here + arr[i])
max_so_far = max(max_so_far, max_ending_here)
return max_so_far
def maxsubarrayproduct(arr):
n = len(arr)
max_ending_here = 1
min_ending_here = 1
max_so_far = 0
flag = 0
for i in range(0, n):
if arr[i] > 0:
max_ending_here = max_ending_here * arr[i]
min_ending_here = min(min_ending_here * arr[i], 1)
flag = 1
elif arr[i] == 0:
max_ending_here = 1
min_ending_here = 1
else:
temp = max_ending_here
max_ending_here = max(min_ending_here * arr[i], 1)
min_ending_here = temp * arr[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if flag == 0 and max_so_far == 0:
return 0
return max_so_far
class DisjointSet:
def __init__(self, n):
self.parent = [i for i in range(n+1)] # n+1 to handle 1 based indexed graph
self.size = [1 for i in range (n+1)]
self.rank = [0 for _ in range(n+1)]
def find(self, u):
if self.parent[u] == u:
return u
self.parent[u] = self.find(self.parent[u])
return self.parent[u]
def unionByRank(self, u, v):
u = self.find(u)
v = self.find(v)
if u == v:
return False
if self.rank[u] > self.rank[v]:
u, v = v, u
self.parent[u] = v
if self.rank[u] == self.rank[v]:
self.rank[v] += 1
return True
def unionBySize(self,u,v):
u = self.find(u)
v = self.find(v)
if u == v:
return False
if self.rank[u] > self.rank[v]:
u, v = v, u
self.parent[u] = v
self.size[v] += self.size[u]
return True
#########################################################################################################
alphabets = list("abcdefghijklmnopqrstuvwxyz")
vowels = list("aeiou")
MOD1 = int(1e9 + 7)
MOD2 = 998244353
INF = int(1e17)
#########################################################################################################
#------------------------------------------------Input--------------------------------------------------#
#########################################################################################################
I = lambda: input()
II = lambda: int(input())
MII = lambda: map(int, input().split())
LI = lambda: list(input().split())
LII = lambda: list(map(int, input().split()))
LGMII = lambda: map(lambda x: int(x) - 1, input().split())
LGLII = lambda: list(map(lambda x: int(x) - 1, input().split()))
inf = float('inf')
#########################################################################################################
#-----------------------------------------------Code----------------------------------------------------#
#########################################################################################################
#
def yn(ff):
if ff : return "YES"
return "NO"
def solve():
ans = 1
n=II()
l=LII()
if l.count(0)==n:
return 0
if l.count(0)==1:
if l[0]==0 or l[-1]==0:return 1
return 2
if l.count(0)>=2:
if l[0]==0 and l[-1]==0:
l=l[1:-1]
# print(l)
if 0 in l:
return l.count(0)
return 1
return yn(ans)
for __ in range (II()):
print((solve()))
|
2049A
|
wrong_submission
|
297,564,566 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
c=int(input())
for _ in range(c):
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range (n):
if a[i]==0:
cnt+=1
if cnt==n:
print(0)
else:
if a[0]==0: cnt-=1
if a[-1]==0: cnt-=1
if cnt==0: print(1)
else:print(2)
|
2049A
|
wrong_submission
|
301,300,642 |
PyPy 3-64
|
WRONG_ANSWER on test 4
|
# Code by B10_STITI
# the world is full of cruel people
# [int(x) for x in input().split()]
for _ in range(int(input())):
n = int(input())
a = [x for x in input().split('0')]
res = 0
for x in a:
if x not in ['', ' ']:
res += 1
if res == 0: print(0)
elif res == 1: print(1)
else: print(2)
|
2049A
|
wrong_submission
|
297,476,779 |
Java 21
|
WRONG_ANSWER on test 2
|
// हर हर महादेव
import java.io.*;
import java.util.*;
public class Solution {
static final int MOD = 1000000007;
static final int MOD1 = 998244353;
static final long INF = (long)1e18;
public static void main(String[] args) {
try {
// For local testing: Redirect input and output to files
boolean isLocal = System.getProperty("ONLINE_JUDGE") == null; // Check environment
if (isLocal) {
// Redirect input and output for local testing
System.setIn(new FileInputStream("input.txt"));
System.setOut(new PrintStream(new FileOutputStream("output.txt")));
}
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = 1;
// Uncomment this line for multiple test cases
t = in.nextInt();
while (t-- > 0) {
solve(in, out);
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
static void solve(FastReader in, PrintWriter out) {
// Write your solution here
int n ;
n = in.nextInt();
int[] arr = new int[n];
for(int i = 0; i < n; i++){
arr[i] = in.nextInt();
}
//check for only zeroes
for(int i = 0; i < n; i++){
if(arr[i]!=0){
break;
}
if(i==n-1){
out.println('0');
return;
}
}
//check for no zeroes
for(int i = 0; i < n; i++){
if(arr[i]==0){
break;
}
if(i==n-1){
out.println('1');
return;
}
}
int idx;
for(idx = 0; idx < n; idx++){
if(idx!=0 && idx != n-1){
if(arr[idx]==0 && arr[idx-1]>0 && arr[idx+1]>0){
out.println('2');
return;
}
}
}
if(arr[0]==0 && arr[n-1]==0){
out.println('1');
return;
}
for(int i = 0; i < n; i++){
if(i==0 && arr[i]==0 && arr[i+1]>0){
out.println('1');
return;
}
if(i==n-1 && arr[i]==0 && arr[i-1]>0){
out.println('1');
return;
}
}
out.println('1');
}
// Utility Functions
// Exponentiation: (a^b) % mod
static long expo(long a, long b, long mod) {
long res = 1;
a = a % mod;
while (b > 0) {
if ((b & 1) == 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
// Extended GCD: returns array [x, y, gcd(a,b)] such that ax + by = gcd(a,b)
static long[] extendGCD(long a, long b) {
if (b == 0)
return new long[]{1, 0, a};
long[] vals = extendGCD(b, a % b);
long x = vals[1];
long y = vals[0] - vals[1] * (a / b);
return new long[]{x, y, vals[2]};
}
// Modular Inverse (for non-prime modulus)
static long mminv(long a, long b) {
long[] vals = extendGCD(a, b);
return vals[0];
}
// Modular Inverse (for prime modulus)
static long mminvprime(long a, long mod) {
return expo(a, mod - 2, mod);
}
// Sieve of Eratosthenes: returns list of primes up to n
static List<Long> sieve(int n) {
boolean[] isPrime = new boolean[n + 1];
Arrays.fill(isPrime, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (isPrime[i]) {
for (int j = i * 2; j <= n; j += i)
isPrime[j] = false;
}
}
List<Long> primes = new ArrayList<>();
for (int i = 2; i <= n; i++) {
if (isPrime[i])
primes.add((long)i);
}
return primes;
}
// Modular Addition
static long modAdd(long a, long b, long mod) {
a %= mod;
b %= mod;
return (a + b + mod) % mod;
}
// Modular Multiplication
static long modMul(long a, long b, long mod) {
a %= mod;
b %= mod;
return (a * b) % mod;
}
// Modular Subtraction
static long modSub(long a, long b, long mod) {
a %= mod;
b %= mod;
return (a - b + mod) % mod;
}
// Modular Division (only for prime mod)
static long modDiv(long a, long b, long mod) {
a %= mod;
b %= mod;
return (modMul(a, mminvprime(b, mod), mod)) % mod;
}
// Binary Search: returns index of target in sorted list, or -1 if not found
static int binarySearch(List<Long> list, long target) {
int left = 0;
int right = list.size() - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
long midVal = list.get(mid);
if (midVal == target)
return mid;
if (midVal < target)
left = mid + 1;
else
right = mid - 1;
}
return -1;
}
// Decimal to Binary Conversion
static String decimalToBinary(long decimal) {
return Long.toBinaryString(decimal);
}
// Binary to Decimal Conversion
static long binaryToDecimal(String binary) {
return Long.parseLong(binary, 2);
}
// Sort and Rearrange two lists based on the sorting of the first list
static void sortAndRearrange(List<Long> a, List<Long> b) {
List<Integer> indices = new ArrayList<>();
for (int i = 0; i < a.size(); i++)
indices.add(i);
indices.sort(Comparator.comparingLong(a::get));
List<Long> a_sorted = new ArrayList<>();
List<Long> b_sorted = new ArrayList<>();
for (int idx : indices) {
a_sorted.add(a.get(idx));
b_sorted.add(b.get(idx));
}
a.clear();
a.addAll(a_sorted);
b.clear();
b.addAll(b_sorted);
}
// Compute GCD using Stein's Algorithm (Binary GCD)
static long gcd(long a, long b) {
if (a == 0)
return b;
if (b == 0)
return a;
// Find common factors of 2
int shift;
for (shift = 0; ((a | b) & 1) == 0; ++shift) {
a >>= 1;
b >>= 1;
}
// Make 'a' odd
while ((a & 1) == 0)
a >>= 1;
while (b != 0) {
// Make 'b' odd
while ((b & 1) == 0)
b >>= 1;
// Now both 'a' and 'b' are odd. Swap if necessary so a <= b,
// then set b = b - a (which is even)
if (a > b) {
long temp = a;
a = b;
b = temp;
}
b = b - a;
}
// Restore common factors of 2
return a << shift;
}
// Check if a number is prime
static boolean isPrime(long n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (long i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
// FastReader Class for Fast Input
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){ return Integer.parseInt(next()); }
long nextLong(){ return Long.parseLong(next()); }
double nextDouble(){ return Double.parseDouble(next()); }
String nextLine(){
String str = "";
try{
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch(IOException e){
e.printStackTrace();
}
return str;
}
}
}
|
2049A
|
wrong_submission
|
297,486,124 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
def f(n,l):
a=l.count(0)
b=0
d=0
if a==0:
return 1
c=l.index(0)
if l.count(0)==n:
return 0
if c==n-a:
return 1
if a==n-1:
return 1
for i in range(c+1,n):
if l[i]!=0:
b+=1
else:
break
for i in range(n):
if l[i]==0:
d+=1
else:
break
if b==n-a or d==a:
return 1
return 2
m=int(input())
for i in range(m):
n=int(input())
l=list(map(int,input().split()))
print(f(n,l))
|
2049A
|
wrong_submission
|
297,488,721 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
def func():
b = int(input())
c = list(map(int, input().split()))
flag = 0
flag2 = 0
for j in range(b):
if c[j] == 0:
if j != 0 and j != b - 1:
if c[j - 1] != 0:
flag2 += 1
elif j == b - 1:
flag2 -= 1
else:
flag = 1
if flag2 > 0:
return 2
if flag:
return 1
else:
return 0
a = int(input())
for i in range(a):
print(func())
|
2049A
|
wrong_submission
|
297,466,697 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class A_MEX_Destruction {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t=s.nextInt();
for(int i=1; i<=t; i++){
int n = s.nextInt();
int[] a = new int[n];
int ze=0;
for(int j=0; j<n; j++){
a[j] = s.nextInt();
if(a[j]==0){
ze++;
}
}
int ans=0;
if(ze==n){
ans=0;
}else if(ze==0){
ans=1;
}else if(ze==1 &&(a[0]==0 || a[n-1]==0)){
ans=1;
}else if (ze==2 && a[0]==0 && a[n-1]==0){
ans=1;
}else{
ans=2;
}
System.out.println(ans);
}
}
}
|
2049A
|
wrong_submission
|
297,490,120 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class mex {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int tt = sc.nextInt();
while (tt-- > 0) {
int n = sc.nextInt();
int arr[] = new int[n];
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
int count = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] == 0) {
count++;
}
}
if (count == n) {
System.out.println(0);
} else if ((arr[0] == 0 || arr[n - 1] == 0) && count == 1) {
System.out.println(1);
} else if ((arr[0] == 0 && arr[n - 1] == 0) && count > 2) {
System.out.println(2);
} else if ((arr[0] == 0 && arr[n - 1] == 0) && count == 2) {
System.out.println(1);
} else if ((arr[0] == 0 || arr[n - 1] == 0) && count == 2) {
System.out.println(2);
} else if (count == 0) {
System.out.println(1);
} else
System.out.println(2);
}
}
}
|
2049A
|
wrong_submission
|
297,781,457 |
C++23 (GCC 14-64, msys2)
|
WRONG_ANSWER on test 2
|
#include <bits/stdc++.h>
using namespace std;
#define writtenByGreatRevan ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define pll pair<long long, long long>
#define pb push_back
#define ff first
#define ss second
#define sz(s) (ll)s.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define forll(i,a,b) for(ll i = a; i <= b; i++)
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define endl "\n"
const ll MaX = LLONG_MAX;
const ll MiN = -MaX;
const double Pi = 3.141592653589793;
void code(){
ll n;
cin>>n;
ll a[n];
ll mx = -1;
forll(i,0,n-1){
cin>>a[i];
mx = max(mx, a[i]);
}
if (!mx){
cout<<0<<endl;
return;
}
ll l = 0, r = n-1;
bool lt = 0, rt = 0;
while (l <= r){
if (a[l] == 0 and lt){
cout<<2<<endl;
return;
}
if (a[r] == 0 and rt){
cout<<2<<endl;
return;
}
if (a[l] > 0) lt = 1;
if (a[r] > 0) rt = 1;
l++, r--;
}
cout<<1<<endl;
}
int main(){
writtenByGreatRevan;
ll tcs = 1;
cin>>tcs;
while(tcs--){
code();
}
}
/*
██████╗░░█████╗░███╗░░██╗░░░░░██╗░█████╗
██╔════╝░██╔══██╗████╗░██║░░░░░██║██╔══██╗
██║░░██╗░███████║██╔██╗██║░░░░░██║███████║
██║░░╚██╗██╔══██║██║╚████║██╗░░██║██╔══██║
╚██████╔╝██║░░██║██║░╚███║╚█████╔╝██║░░██║
░╚═════╝░╚═╝░░╚═╝╚═╝░░╚══╝░╚════╝░╚═╝░░╚═╝
*/ /**
░░░░███████╗██████╗░██╗████████╗██╗░░░░░░░
░░░░██╔════╝██╔══██╗██║╚══██╔══╝██║░░░░░░░
░░░░█████╗░░██████╔╝██║░░░██║░░░██║░░░░░░░
░░░░██╔══╝░░██╔══██╗██║░░░██║░░░██║░░░░░░░
░░░░██║░░░░░██║░░██║██║░░░██║░░░███████╗░░
░░░╚═╝░░░░░╚═╝░░╚═╝╚═╝░░░╚═╝░░░╚══════╝░
**/
|
2049A
|
wrong_submission
|
297,474,832 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
t = int(input())
def solve():
n = int(input())
arr = list(map(int,input().split()))
if 0 not in arr:
return 1
if set(arr) == {0}:
return 0
if arr.count(0) > 2:
return 2
else:
return 1 if (arr[-1] == 0 or arr[0] == 0) else 2
for _ in range(t):
print(solve())
|
2049A
|
wrong_submission
|
297,460,597 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
for i in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
if 0 not in a:
print(1)
elif a.count(0)==n:
print(0)
else:
for i in range(1,n-1):
if a[i]==0 and a[i-1]!=0 and a[i+1]!=0:
print(2)
break
else:
print(1)
|
2049A
|
wrong_submission
|
297,603,551 |
PyPy 3
|
WRONG_ANSWER on test 2
|
t = int(input()) # Number of test cases
for _ in range(t):
n = int(input()) # Length of the array
a = list(map(int, input().split()))
zero_count = a.count(0)
# Apply the conditions
if zero_count == n:
print(0)
elif zero_count == 0:
print(1) # Exactly one zero or no zeros, 1 operation needed
elif zero_count == 1:
if a[0] ==0 or a[-1]==0:
print(1) # Exactly one zero or no zeros, 1 operation needed
else:
print(2)
elif zero_count == 2 and(( a[0] ==0 and a[-1]==0) or (a[0] ==0 and a[1]==0) or a[-2] ==0 and a[-1]==0):
print(1)
else:
print(2) # Exactly two zeros and other non-zero elements, 2 operations needed
|
2049A
|
wrong_submission
|
306,103,168 |
PyPy 3
|
WRONG_ANSWER on test 4
|
n = int(input())
L = []
for i in range(n):
a = int(input())
L1 = list(map(int,input().split()))
str1 = ''
for i in L1:
str1 += str(i)
if L1.count(0) == len(L1):
L.append(0)
elif L1.count(0) == 0:
L.append(1)
elif str1.strip('0').count('0') != 0:
L.append(2)
else:
L.append(1)
for i in L:
print(i)
|
2049A
|
wrong_submission
|
297,464,672 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
if len(set(l))==1 and l[0]==0:
print(0)
else:
k=0
for i in range(n):
if l[i]==0:
if i!=0:
try:
if l[i-1]!=0 and l[i+1]!=0:
k+=1
break
except:
pass
if k:
print(2)
else:
print(1)
|
2049A
|
wrong_submission
|
299,434,164 |
Java 8
|
WRONG_ANSWER on test 2
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i=sc.nextInt();
sc.nextLine();
for(int z=1;z<=i;z++)
{
int n=sc.nextInt();
sc.nextLine();
int ar[]=new int[n];
String s=sc.nextLine().trim();
String arr[]=s.split(" ");
boolean b1=true;
for(int x=0;x<n;x++)
{
ar[x]=Integer.parseInt(arr[x]);
if(ar[x]!=0)
{
b1=false;
}
}
if(b1==true)
{
System.out.println(0);
}
else if(n==2)
{
System.out.println(1);
}
else
{
int i1=0;
int i2=n-1;
while(i1!=i2)
{
if(ar[i1]!=0&&ar[i2]!=0)
{
boolean b=true;
for(int x=i1+1;x<i2;x++)
{
if(ar[x]==0)
{
System.out.println(2);
i1=i2;
b=false;
break;
}
}
if(b==true)
{
System.out.println(1);
break;
}
}
else if(ar[i1]==0&&ar[i2]!=0)
{
if(i1+1==i2)
{
System.out.println(1);
}
i1++;
}
else
if(ar[i1]!=0&&ar[i2]==0)
{
if(i1+1==i2)
{
System.out.println(1);
}
i2--;
}
else
if(ar[i1]==0 && ar[i2]==0)
{
i1++;
i2--;
}
}
}
}
}
}
|
2049A
|
wrong_submission
|
299,136,019 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
# --------------------------------------------------------------------------------
# होइहि सोइ जो राम रचि राखा। को करि तर्क बढ़ावै साखा॥
# अस कहि लगे जपन हरिनामा। गईं सती जहँ प्रभु सुखधामा॥
# --------------------------------------------------------------------------------
# Author : Shivam Mishra
# Date : 28th Dec 2024
# --------------------------------------------------------------------------------
import sys
import math
from collections import defaultdict
import heapq
from collections import Counter
MOD = 1000000007
MOD1 = 998244353
PI = 3.141592653589793238462
INF = float('inf')
# Helper functions
def ps(x, y):
return f"{x:.{y}f}"
def input_array():
return list(map(int, input().split()))
def debug(x):
if 'ONLINE_JUDGE' not in globals():
print(f"{x}", file=sys.stderr)
def getcount(r,l,f):
a = 0
b = len(f)-1
ans = -1
while a<=b:
mid = (a+b)//2
if f[mid]<=r:
a=mid+1
ans = mid
else:
b=mid-1
a = 0
b = len(f)-1
ans1 = -1
while a<=b:
mid = (a+b)//2
if f[mid]>=l:
b=mid-1
ans1 = mid
else:
a=mid+1
if ans == -1 or ans1==-1:
result = 0
else:
result = abs(ans-ans1)+1
return result
def is_Permu(l):
l.sort()
n = len(l)
cnt = 1
for i in range(n):
if l[i] != cnt:
return False
cnt+=1
return True
def jaiishriRam():
n = int(input())
a = input_array()
cnt = 0
for i in range(n):
cnt+=a[i]
if cnt == 0:
print(0)
return
for i in range(1,n-1,1):
if a[i] == 0 :
for j in range(i-1,-1,-1):
if a[j]!=0:
print(2)
return
for j in range(i+1,n,1):
if a[j]!=0:
print(2)
return
print(1)
return
# Equivalent to `int main()`
def main():
if 'ONLINE_JUDGE' not in globals():
sys.stderr = open("Error.txt", "w")
t = int(input()) # Input for number of test cases
#t = 1
for _ in range(t):
jaiishriRam()
if __name__ == "__main__":
main()
|
2049A
|
wrong_submission
|
300,638,501 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
t=int(input())
for _ in range(t):
n=int(input())
a=list(map(int,input().split()))
if n<4:
if n==1:
if a[0]==0:
print(0)
else:
print(1)
elif n==2:
if sum(a)==0:
print(0)
else:
print(1)
else:
if sum(a)==0:
print(0)
if a[1]==0:
if a[0]!=0 and a[2]!=0:
print(2)
else:
print(1)
else:
print(1)
continue
else:
temp=sum(a[1:n-1])
if temp+a[0]+a[n-1]==0:
print(0)
continue
elif temp==0 and (a[0]==0 or a[n-1]==0):
print(1)
continue
elif temp==0:
print(2)
continue
start,end=False,False
middle,cont=False,True
for i in range(n):
if i==0:
if a[i]==0:
start=True
elif i==n-1:
if a[i]==0:
end=True
else:
if a[i]==0:
middle=True
if a[i-1]!=0 and a[i+1]!=0:
cont=False
if start==True or end==True:
if middle==True:
print(2)
else:
print(1)
else:
if middle==True and cont==True:
print(1)
elif middle==True and cont==False:
print(2)
else:
print(1)
|
2049A
|
wrong_submission
|
297,481,794 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
t = int(input())
for i in range(t):
n= int(input())
a = list(map(int , input().split()))
# print(a)
count =0
for i in range(n):
if a[i] != 0:
count =1
for j in range(i+1,n):
if a[j] == 0:
for k in range(j+1,n):
if a[k] != 0:
count =2
break
break
break
print(count)
|
2049A
|
wrong_submission
|
297,475,673 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class div2_166 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine();
while (t-- > 0) {
int n = sc.nextInt();
sc.nextLine();
ArrayList<Integer> arr = new ArrayList<>();
int zerocount = 0;
for (int i = 0; i < n; i++) {
arr.add(sc.nextInt());
if (arr.get(i) == 0) {
zerocount++;
}
}
if (zerocount == n) {
System.out.println("0");
} else if (zerocount == 0) {
System.out.println("1");
} else if (zerocount == 1 && arr.get(0) == 0) {
System.out.println("1");
} else if (zerocount == 2 && arr.get(0) == 0 && arr.get(n - 1) == 0) {
System.out.println("1");
} else if (zerocount == 1 && arr.get(n-1) == 0) {
System.out.println("1");
}else{
System.out.println("2");
}
}
sc.close();
}
}
|
2049A
|
wrong_submission
|
297,464,749 |
C++20 (GCC 13-64)
|
WRONG_ANSWER on test 2
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while (t--)
{
int n;
cin>>n;
vector<int>a(n);
for (int i = 0; i < n; i++)
{
cin>>a[i];
}
int zeros=0;
for (int i = 0; i < n; i++)
{
if (a[i]==0)
{
zeros++;
}
}
if (zeros==n)
{
cout<<0<<endl;
}
else
{
if (zeros==1)
{
if (a[0]==0 || a[n-1]==0)
{
cout<<1<<endl;
}
else
{
cout<<2<<endl;
}
}
else
{
int first=0;
int last=n-1;
for (int i = 0; i < n; i++)
{
if (a[i]==0)
{
first=i;
}
else
{
break;
}
}
for (int i = n-1; i >=0; i--)
{
if (a[i]==0)
{
last=i;
}
else
{
break;
}
}
bool ans=false;
for (int i = first+1; i <last-1; i++)
{
if (a[i]==0)
{
cout<<2<<endl;
ans=true;
break;
}
}
if (!ans)
{
cout<<1<<endl;
}
}
}
}
}
|
2049A
|
wrong_submission
|
297,491,257 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
def mex(b):
c=0
while c in b:
c=c+1
return c
t=int(input())
for _ in range(t):
n=int(input())
arr=list(map(int,input().split()))
if arr.count(0)==n:
print(0)
elif 0 not in arr:
print(1)
else:
if arr[0]==0 and arr[-1]!=0:
if 0 in arr[1:n-1]:
print(2)
else:
print(1)
elif arr[0]!=0 and arr[-1]==0:
if 0 in arr[1:n-1]:
print(2)
else:
print(1)
elif arr[0]==arr[-1]==0:
if 0 not in arr[1:n-1]:
print(1)
else:
print(2)
else:
print(2)
|
2049A
|
wrong_submission
|
297,516,065 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
for _ in range(int(input())):
n = int(input())
all_zeros = True
mid_zero = False
for i, num in enumerate(input().split()):
num = int(num)
if num == 0:
if i != 0 and i != n - 1:
mid_zero = True
else:
all_zeros = False
if all_zeros:
print(0)
elif mid_zero:
print(2)
else:
print(1)
|
2049A
|
wrong_submission
|
299,408,360 |
Java 8
|
WRONG_ANSWER on test 2
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
sc.nextLine();
for (int z = 1; z <= i; z++) {
int n = sc.nextInt();
sc.nextLine();
int ar[] = new int[n];
String s = sc.nextLine().trim();
String arr[] = s.split(" ");
boolean b1 = true;
for (int x = 0; x < n; x++) {
ar[x] = Integer.parseInt(arr[x]);
if (ar[x] != 0) {
b1 = false;
}
}
if (b1 == true) {
System.out.println(0);
} else if (n == 2) {
System.out.println(1);
} else if(n==1)
{
if(ar[0]==0)
{
System.out.println(0);
}
else
{
System.out.println(1);
}
}
else {
int i1 = 0;
int i2 = n - 1;
while (i1 != i2) {
if (ar[i1] != 0 && ar[i2] != 0) {
boolean b = true;
for (int x = i1 + 1; x < i2; x++) {
if (ar[x] == 0) {
System.out.println(2);
i1 = i2;
b = false;
break;
}
}
if (b == true) {
System.out.println(1);
break;
}
} else if (ar[i1] == 0 && ar[i2] != 0) {
i1++;
} else if (ar[i1] != 0 && ar[i2] == 0) {
i2--;
} else if (ar[i1] == 0 && ar[i2] == 0) {
i1++;
i2--;
}
}
}
}
}
}
|
2049A
|
wrong_submission
|
300,558,579 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
import java.io.*;
import java.math.*;
public class CodeChef {
public static int abs(int a) { return Math.abs(a); }
public static int max(int a,int b) { return Math.max(a,b); }
public static int min(int a,int b) { return Math.min(a,b); }
public static double floor(double a) { return Math.floor(a); }
public static double ceil(double a) { return Math.ceil(a); }
public static double round(double a) { return Math.round(a); }
public static double pow(double a,double b) { return Math.pow(a,b); }
public static void main(String[] args) throws java.lang.Exception {
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();
while(tc-- > 0)
{
int n = sc.nextInt();
int zero = 0;
int arr[] = new int[n];
for(int i = 0; i < n; i++) {
int a = sc.nextInt();
if(a == 0) zero++;
arr[i] = a;
}
int ans = 0;
if(zero == n) ans = 0;
else {
ans = 1;
// Two zeros but none of them are in between two non-zero values.
// If there is a zero b/w two non-zero values.
for(int i = 1; i < n-1; i++) {
if(arr[i] == 0) {
if(arr[i-1] > 0 && arr[i+1] > 0) {
ans = 2;
break;
}
}
}
}
System.out.println(ans);
}
sc.close();
}
}
|
2049A
|
wrong_submission
|
297,575,548 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
mid = False
for i in range(1,n-1):
if a[i]==0:
mid = True
break
all0 = True
# check if all 0s
for i in range(n):
if a[i]!=0:
all0 = False
break
if all0:
print(0)
continue
if mid==True and a[0]==0 and a[-1]==0:
print(2)
continue
if mid==True and a[0]==0:
print(1)
continue
if mid==True and a[-1]==0:
print(1)
continue
if mid==True:
print(2)
continue
if mid==False:
print(1)
continue
|
2049A
|
wrong_submission
|
297,535,534 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
cases=int(input())
for test in range(cases):
n=int(input())
arr=list(map(int, input().split()))
if arr.count(0)==len(arr):
print(0)
continue
if arr.count(0)==0:
print(1)
continue
if arr[0]!=0 and arr[-1]!=0 and arr.count(0)==(len(arr)-2):
print(2)
continue
flag=0
for i in range(1, n-1):
if arr[i]==0 and arr[i-1]!=0 and arr[i+1]!=0:
flag=1
break
#print(i, flag)
if flag==1:
print(2)
continue
if flag==0 and 0 in arr:
print(1)
continue
|
2049A
|
wrong_submission
|
297,590,520 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class A_MEX_Destruction {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int arr[] = new int[n];
int f = -1, l =n;
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
boolean tr=true,all=true;
for (int i = 0; i <= (n-1)/2; i++) {
if(arr[i]==0){
if(f==i-1)
f++;
else{
tr=false;
}
}
if(arr[n-i-1]==0){
if(l==n-i)
l--;
else{
tr=false;
}
}
if(arr[i]!=0 || arr[n-i-1]!=0){
all=false;
}
}
if(tr==false){
System.out.println(2);
}else{
if(all){
System.out.println(0);
}else{
System.out.println(1);
}
}
}
}
}
|
2049A
|
wrong_submission
|
297,472,593 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
from collections import defaultdict, deque
from itertools import permutations, combinations
import heapq
import math
from bisect import bisect_right, bisect_left
string = lambda: input().strip()
n_int = lambda: int(input())
m_int = lambda: map(int, input().split())
array = lambda: list(map(int, input().split()))
def solve():
n = n_int()
a = array()
z = a.count(0)
if z == n:
print(0)
elif z > 0:
if z == 1 and a[0] == 0:
print(1)
return
if z == 1 and a[n-1] == 0:
print(1)
return
if z == 2 and a[0] == 0 and a[n-1] == 0:
print(1)
return
print(2)
else:
print(1)
if __name__ == '__main__':
for _ in range(n_int()):
# print('-----------------------------')
solve()
|
2049A
|
wrong_submission
|
297,478,741 |
PyPy 3-64
|
WRONG_ANSWER on test 4
|
t = int(input())
for i in range(t):
n = int(input())
a = "".join(input().split())
a = a.lstrip("0")
a = a.rstrip("0")
a = list(map(int, a))
if a == []:
print(0)
continue
if 0 in a:
print(2)
else:
print(1)
|
2049A
|
wrong_submission
|
297,465,131 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
for _ in range(int(input())):
n=int(input())
l=[int(x) for x in input().split()]
s=set(l)
if s=={0}:
print(0)
else:
if l.count(0)==0:
print(1)
elif l.count(0)==1:
if l.index(0)==0 or l.index(0)==n-1:
print(1)
else:
print(2)
else:
i=0
while l[i]!=0:
i+=1
j=n-1
while l[j]!=0:
j-=1
if i==0 and j==n-1:
while l[i]==0:
i+=1
while l[j]==0:
j-=1
print(1 if 0 not in l[i:j+1] else 2)
else:
print(2)
|
2049A
|
wrong_submission
|
297,472,322 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class A_MEX_Destruction {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
int n = scanner.nextInt();
int[] a = new int[n];
int mex = 0;
int sum = 0;
for (int j = 0; j < n; j++) {
a[j] = scanner.nextInt();
sum += a[j];
if(j != 0) {
if(a[j] == 0 && a[j-1] != 0) {
mex++;
}
}
}
if(sum == 0) {
System.out.println(0);
} else if(mex == 0) {
System.out.println(1);
} else if(mex == 1 && (a[0] == 0 || a[n-1] == 0) ) {
System.out.println(1);
} else {
System.out.println(2);
}
}
scanner.close();
}
}
|
2049A
|
wrong_submission
|
297,511,259 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
import java.lang.*;
import java.io.*;
public class codechef
{
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int a[] = new int[n];
for(int i = 0;i<n;i++){
a[i] = sc.nextInt();
}
int count = 0;
int zero = 0;
for(int i = 0;i<n;i++){
if(a[i] == 0){
zero++;
}
if(i!=0 && i != n-1 && a[i] == 0 && a[i+1]!=0 && a[i-1]!=0 ){
count+=2;
}
else if( i!=n-1 && a[i] == 0 && a[i+1]!=0){
count++;
}
}
if(zero == n){
System.out.println("0");
}
else if(zero == 0){
System.out.println("1");
}
else if(zero == 1 && a[n-1] == 0){
System.out.println("1");
}
else{
if(count == 1){
System.out.println("1");
}
else{
System.out.println("2");
}
}
}
}
}
|
2049A
|
wrong_submission
|
299,798,055 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
def Fn(a):
if sum(a)==0:
return 0
for i in range(len(a)):
if a[i]!=0:
a[i]=1
if sum(a)==len(a):
return 1
for index,number in enumerate(a):
if number==0:
if index==0 or index==len(a)-1:
continue
else:
if a[index+1]==1 and a[index-1]==1:
return 2
return 1
tst=int(input())
for _ in range(tst):
l=int(input())
a=list(map(int, input().split()))
print(Fn(a))
|
2049A
|
wrong_submission
|
300,397,343 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
long[] ans1 = new long[t];
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
int[] arr =new int[n];
boolean b = true;
for(int j =0;j<n;j++){
arr[j] = sc.nextInt();
}
for(int j =0;j<n;j++){
if(j-1>=0 && j+1<n && arr[j] == 0){
if(arr[j-1] != 0 && arr[j+1] != 0){
b = false;
break;
}
}
}
int[] temp = arr;
Arrays.sort(arr);
boolean nozero = arr[0] != 0;
if(arr[n-1] == 0){
ans1[i] = 0;
}
else{
if(nozero || b){
ans1[i] = 1;
}
else{
ans1[i] = 2;
}
}
}
System.out.println();
for (int i = 0; i < t; i++) {
System.out.println(ans1[i]);
}
}
}
class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(File s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public int[] nextArr(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException {
return br.ready();
}
}
class Pair implements Comparable {
int a;
int b;
public Pair(int a, int b) {
this.a = a;
this.b = b;
}
public int compareTo(Object o) {
if (((Pair) o).a > a) {
return -1;
} else if (((Pair) o).a < a) {
return 1;
} else {
return 0;
}
}
public String toString() {
return a + " " + b;
}
}
|
2049A
|
wrong_submission
|
297,469,836 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class Main {
static int abhimanyu(int n, int arr[]){
int zeroes = 0;
boolean mid = false;
for(int i = 0; i<n; i++) {
if(i > 0 && i < n-1 && arr[i] == 0) mid = true;
if (arr[i] == 0) zeroes++;
}
if(zeroes == n) return 0;
if(zeroes == 0) return 1;
if(mid) return 2;
return 1;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int arr[] = new int[n];
for(int i = 0; i<n; i++){
arr[i] = sc.nextInt();
}
System.out.println(abhimanyu(n, arr));
}
}
}
|
2049A
|
wrong_submission
|
297,481,094 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
for _ in range(int(input())):
num = int(input())
l=list(map(int,input().split(' ')))
if(list(set(l))==[0]):
print(0)
elif(0 not in l):
print(1)
else:
i=0
j=num-1
if((l[0]==0)^(l[num-1]==0)):
print(1)
else:
if(l[0]==0 and l[num-1]==0):
while(l[i]==0):
i+=1
while(l[j]==0):
j-=1
l=l[i:j+1]
num=len(l)
if(0 not in l):
print(1)
else:
print(2)
|
2049A
|
wrong_submission
|
297,462,512 |
PyPy 3-64
|
WRONG_ANSWER on test 4
|
from sys import stdin
input = stdin.readline
from collections import defaultdict,deque,Counter
from bisect import bisect_left,bisect_right
from heapq import heappush,heappop,heapify
from functools import lru_cache
from itertools import accumulate, permutations, combinations
from math import *
ii = lambda: int(input())
ti = lambda: tuple(map(int, input().split(' ')))
li = lambda: list(map(int, input().split(' ')))
si = lambda: input().strip()
wi = lambda: [w.strip() for w in input().split(' ')]
MOD = 998244353
for _ in range(ii()):
n = ii()
nums = li()
s = ''.join(map(str, nums))
s = s.strip('0')
if len(s) == 0:
print(0)
elif '0' in s:
print(2)
else:
print(1)
|
2049A
|
wrong_submission
|
297,469,030 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
allzeros = True
middlezero = False
cnt = 0
for i in range(n):
if a[i] != 0:
allzeros = False
cnt += 1
else:
if i != 0 and i != n - 1:
middlezero = True
if allzeros:
print(0)
elif middlezero and cnt > 1:
print(2)
else:
print(1)
|
2049A
|
wrong_submission
|
297,496,196 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
T=int(input())
for _ in range(T):
t=int(input())
lane=list(map(int,input().strip().split()))
n=0
count=0
for i in range(t):
if i==t-1 and lane[i]!=0:
count+=1
elif lane[i]!=0 and n==0:
n=1
elif lane[i]==0 and n==1:
count+=1
if count<=2:
print(count)
else:
print(2)
|
2049A
|
wrong_submission
|
297,477,560 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int[] arr = new int[n];
int zero = 0;
for(int i=0;i<n;i++){
arr[i] = sc.nextInt();
if(arr[i]==0)
zero++;
}
if(zero==n)
System.out.println(0);
else if(zero==0)
System.out.println(1);
else if(zero==1 && (arr[0]==0 || arr[n-1]==0))
System.out.println(1);
else if(zero==1 && (arr[0]!=0 && arr[n-1]!=0))
System.out.println(2);
else if(zero==2 && (arr[0]==0 && arr[n-1]==0))
System.out.println(1);
else
System.out.println(2);
}
}
}
|
2049A
|
wrong_submission
|
297,544,992 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
def main(f):
final_list=[]
for _ in range(f):
e=int(input())
a=list(map(int,input().split()))
n=0
if all(x==0 for x in a):
pass
else:
for i in range(1):
if a[0]==0:
if a[-1]==0:
if 0 in a[1:len(a)-1]:
n+=2
elif 0 not in a[1:len(a)-1]:
n+=1
break
else:
if 0 not in a[1:len(a)]:
n+=1
else:
n+=2
elif a[-1]==0:
if a[-2]==0:
n=1
else:
if 0 in a[0:len(a)-1]:
n+=2;
elif 0 not in a[0:len(a)-1]:
n+=1;
break
elif 0 in a[0:len(a)]:
n+=2
else:
n+=1
final_list.append(n)
for i in final_list:
print(i)
main(int(input()))
|
2049A
|
wrong_submission
|
297,464,172 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
def INT(): return int(input())
def MAP(): return map(int, (input().split()))
def MAT(n): return [list(map(int, (input().split()))) for _ in range(n)]
for _ in range(INT()):
n=INT()
a=list(MAP())
if n==1:
print(0 if a[0]==0 else 1)
continue
if 0 in a:
l=a.index(0)
else:
print(1)
continue
r=n-1-a[::-1].index(0)
ct=a.count(0)
if ct!= r-l+1:
if l==0 and r==n-1 and ct==2:
print(1)
else:
print(2)
continue
if l==0 and r==n-1:
print(0)
continue
if l==0 or r==n-1:
print(1)
continue
print(2)
|
2049A
|
wrong_submission
|
297,471,511 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t --> 0) {
int n = in.nextInt();
int[] arr = new int[n];
for(int i=0; i<n; i++) arr[i] = in.nextInt();
int zeros = 0;
for(int i=0; i<n; i++) {
if(arr[i] == 0) zeros++;
}
if(zeros == n) {
System.out.println(0);
continue;
}
if(zeros == 0) {
System.out.println(1);
continue;
}
int cnt = 0;
for(int i=1; i<n-1; i++) {
if(arr[i] == 0 && arr[i-1] != 0 && arr[i+1] != 0) cnt++;
}
if(cnt > 0) System.out.println(2);
else{
System.out.println(1);
}
}
}
}
|
2049A
|
wrong_submission
|
297,508,397 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
t = int(input())
final = []
def ans(n, arr):
if arr.count(0) == n:
return 0
if 0 not in arr:
return 1
if arr.count(0) == 1 and (arr[0] == 0 or arr[-1] == 0):
return 1
if arr.count(0) == 1 and arr[0] != 0 and arr[-1] != 0:
return 2
if arr.count(0) == 2:
if arr[0] == 0 and arr[-1] == 0:
return 1
else:
return 2
if arr.count(0) > 2:
if arr[:arr.count(0)].count(0) == arr.count(0) or arr[-arr.count(0):].count(0) == arr.count(0):
return 1
else:
return 2
for o in range(t):
n = int(input())
arr = list(map(int, input().split()))
c = ans(n, arr)
final.append(c)
for elem in final:
print(elem)
|
2049A
|
wrong_submission
|
297,527,455 |
Java 21
|
WRONG_ANSWER on test 4
|
import java.util.*;
public class A_MEX_Destruction {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0;i<t;i++){
int n=sc.nextInt();
int ar[]=new int[n];
StringBuilder str=new StringBuilder();
for(int j=0;j<n;j++)
{
ar[j]=sc.nextInt();
str.append(ar[j]);
}
int count=0;
int x=0,y=n-1;
while(x<=y)
{
if(ar[x]==0)
{
count++;
x++;
}
else if(ar[y]==0)
{
y--;
count++;
}
else
{
if(str.toString().substring(x,y+1).contains("0"))
{
System.out.println(2);
break;
}
else
{
System.out.println(1);
break;
}
}
}
if(count==n)
System.out.println(0);
}
}
}
|
2049A
|
wrong_submission
|
302,603,904 |
C++23 (GCC 14-64, msys2)
|
WRONG_ANSWER on test 2
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define loop(i,startFrom,endBefore) for (int i = startFrom; i < endBefore; i++)
#define loopR(i,startFrom,endAt) for (int i = startFrom; i >= endAt; i--)
#define inputV(v) for(ll ii = 0; ii < v.size(); ii++) cin>>v[ii];
#define printV(v) for (auto i : v) cout<<i<<' '; cout<<endl;
typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int mod = 1e9+7;
void solve() {
int n;
cin>>n;
vector<int> a(n);
inputV(a);
vector<int> pz;
int mex = 0;
loop(i,0,n) {
if (a[i] == 0) {
pz.push_back(i);
// cout<<i<<endl;
}
}
if (pz.size() == n) {
cout<<0<<endl;
}
else if (pz.size() == 0) {
cout<<1<<endl;
}
else if (pz.size() == 1 && (pz[0] == 0 || pz[0] == n-1)) {
cout<<1<<endl;
}
else if (pz.size() == 2 && pz[0] == 0 && pz[1] == n-1) {
cout<<1<<endl;
}
else if (pz.size() != 1 && pz[0] == pz[pz.size()-1] - pz.size() + 1) {
cout<<1<<endl;
}
else {
cout<<2<<endl;
}
}
int32_t main() {
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
|
2049A
|
wrong_submission
|
299,816,938 |
Java 8
|
WRONG_ANSWER on test 2
|
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
int t=in.nextInt();
while (t-- > 0)
{
int n = in.nextInt() ,z=0;
int[] arr=new int[n];
for(int i=0 ; i < n ; i++)
{
arr[i] =in.nextInt();
if(arr[i] == 0 ) z++;
}
if(z == n) System.out.println(0);
//? 0 3 9 0
else if(z == 0 || (arr[0] == 0 && z == 1) || ( arr[n-1]== 0 && z == 1) || (arr[0] == 0 && arr[n-1] == 0 && z == 2))
System.out.println(1);
else System.out.println(2);
} }
}
|
2049A
|
wrong_submission
|
297,462,364 |
PyPy 3-64
|
WRONG_ANSWER on test 2
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
occur0= []
cnt0 = 0
for i in range(len(a)):
if a[i] == 0:
occur0.append(i)
cnt0 += 1
if cnt0 == n:
print(0)
elif cnt0 == 0:
print(1)
elif cnt0 == 1:
if occur0[0] == 0 or occur0[0] == n-1:
print(1)
else:
print(2)
elif cnt0 == 2:
if occur0[0] == 0 and occur0[1] == n-1:
print(1)
else:
print(2)
else:
print(2)
|
2049A
|
wrong_submission
|
297,463,479 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.util.Scanner;
public class F {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
while (N-- > 0) {
int length = scanner.nextInt();
if (length == 1) {
if (scanner.nextInt() == 0) {
System.out.println(0);
} else {
System.out.println(1);
}
} else {
boolean firstNum = scanner.nextInt() == 0;
int numberOfZeros = 0;
for (int i = 1; i < length - 1; i++) {
if (scanner.nextInt() == 0) {
numberOfZeros++;
}
}
boolean lastNum = scanner.nextInt() == 0;
if (firstNum && lastNum && numberOfZeros == length - 2) {
System.out.println(0);
} else if (numberOfZeros != 0) {
System.out.println(2);
} else {
System.out.println(1);
}
}
}
}
}
|
2049A
|
wrong_submission
|
297,507,355 |
Java 21
|
WRONG_ANSWER on test 2
|
// हर हर महादेव
import java.io.*;
import java.util.*;
public class Solution {
static final int MOD = 1000000007;
static final int MOD1 = 998244353;
static final long INF = (long)1e18;
public static void main(String[] args) {
try {
// For local testing: Redirect input and output to files
boolean isLocal = System.getProperty("ONLINE_JUDGE") == null; // Check environment
if (isLocal) {
// Redirect input and output for local testing
System.setIn(new FileInputStream("input.txt"));
System.setOut(new PrintStream(new FileOutputStream("output.txt")));
}
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = 1;
// Uncomment this line for multiple test cases
t = in.nextInt();
while (t-- > 0) {
solve(in, out);
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
static void solve(FastReader in, PrintWriter out) {
// Write your solution here
int count =1;
int n ;
n = in.nextInt();
int arr[] = new int[n];
for(int i=0; i<n; i++){
arr[i] = in.nextInt();
}
//check only zeroes
for(int i=0; i<n; i++){
if(arr[i]!=0){
break;
}
if(i==n-1){
out.println(0);
return;
}
}
int idx = -1;
for(int i=0; i<n; i++){
if(arr[i]==0 && i!=0){
idx = i;
break;
}
}
if(idx==-1){
out.println(count);
return;
}
for(int i=idx+1; i<n; i++){
if(arr[i]==0){
continue;
}
if(arr[i]>0){
count ++;
if(count == 2){
out.println(count);
return;
}
}
}
out.println(count);
}
// Utility Functions
// Exponentiation: (a^b) % mod
static long expo(long a, long b, long mod) {
long res = 1;
a = a % mod;
while (b > 0) {
if ((b & 1) == 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
// Extended GCD: returns array [x, y, gcd(a,b)] such that ax + by = gcd(a,b)
static long[] extendGCD(long a, long b) {
if (b == 0)
return new long[]{1, 0, a};
long[] vals = extendGCD(b, a % b);
long x = vals[1];
long y = vals[0] - vals[1] * (a / b);
return new long[]{x, y, vals[2]};
}
// Modular Inverse (for non-prime modulus)
static long mminv(long a, long b) {
long[] vals = extendGCD(a, b);
return vals[0];
}
// Modular Inverse (for prime modulus)
static long mminvprime(long a, long mod) {
return expo(a, mod - 2, mod);
}
// Sieve of Eratosthenes: returns list of primes up to n
static List<Long> sieve(int n) {
boolean[] isPrime = new boolean[n + 1];
Arrays.fill(isPrime, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (isPrime[i]) {
for (int j = i * 2; j <= n; j += i)
isPrime[j] = false;
}
}
List<Long> primes = new ArrayList<>();
for (int i = 2; i <= n; i++) {
if (isPrime[i])
primes.add((long)i);
}
return primes;
}
// Modular Addition
static long modAdd(long a, long b, long mod) {
a %= mod;
b %= mod;
return (a + b + mod) % mod;
}
// Modular Multiplication
static long modMul(long a, long b, long mod) {
a %= mod;
b %= mod;
return (a * b) % mod;
}
// Modular Subtraction
static long modSub(long a, long b, long mod) {
a %= mod;
b %= mod;
return (a - b + mod) % mod;
}
// Modular Division (only for prime mod)
static long modDiv(long a, long b, long mod) {
a %= mod;
b %= mod;
return (modMul(a, mminvprime(b, mod), mod)) % mod;
}
// Binary Search: returns index of target in sorted list, or -1 if not found
static int binarySearch(List<Long> list, long target) {
int left = 0;
int right = list.size() - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
long midVal = list.get(mid);
if (midVal == target)
return mid;
if (midVal < target)
left = mid + 1;
else
right = mid - 1;
}
return -1;
}
// Decimal to Binary Conversion
static String decimalToBinary(long decimal) {
return Long.toBinaryString(decimal);
}
// Binary to Decimal Conversion
static long binaryToDecimal(String binary) {
return Long.parseLong(binary, 2);
}
// Sort and Rearrange two lists based on the sorting of the first list
static void sortAndRearrange(List<Long> a, List<Long> b) {
List<Integer> indices = new ArrayList<>();
for (int i = 0; i < a.size(); i++)
indices.add(i);
indices.sort(Comparator.comparingLong(a::get));
List<Long> a_sorted = new ArrayList<>();
List<Long> b_sorted = new ArrayList<>();
for (int idx : indices) {
a_sorted.add(a.get(idx));
b_sorted.add(b.get(idx));
}
a.clear();
a.addAll(a_sorted);
b.clear();
b.addAll(b_sorted);
}
// Compute GCD using Stein's Algorithm (Binary GCD)
static long gcd(long a, long b) {
if (a == 0)
return b;
if (b == 0)
return a;
// Find common factors of 2
int shift;
for (shift = 0; ((a | b) & 1) == 0; ++shift) {
a >>= 1;
b >>= 1;
}
// Make 'a' odd
while ((a & 1) == 0)
a >>= 1;
while (b != 0) {
// Make 'b' odd
while ((b & 1) == 0)
b >>= 1;
// Now both 'a' and 'b' are odd. Swap if necessary so a <= b,
// then set b = b - a (which is even)
if (a > b) {
long temp = a;
a = b;
b = temp;
}
b = b - a;
}
// Restore common factors of 2
return a << shift;
}
// Check if a number is prime
static boolean isPrime(long n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (long i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
// FastReader Class for Fast Input
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}
catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){ return Integer.parseInt(next()); }
long nextLong(){ return Long.parseLong(next()); }
double nextDouble(){ return Double.parseDouble(next()); }
String nextLine(){
String str = "";
try{
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch(IOException e){
e.printStackTrace();
}
return str;
}
}
}
|
2049A
|
wrong_submission
|
297,473,365 |
Java 21
|
WRONG_ANSWER on test 2
|
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.InputMismatchException;
public class Codeforces_Round_994_Div_2 {
static Scanner in = new Scanner(System.in);
static OutputWriter out = new OutputWriter(System.out);
static StringBuilder ans = new StringBuilder();
static int timer = 0, testCases, f, n, x_, y_, k, w, h, a11, b1, g, m, r, q, a_, b_, c_;
static char x[], y[], z[], _A[][], _B[][];
static long a[], b[], c[], suffix[], prefix[], A[][], B[][], d[], dp[];
static double time[], distance[], quries[];
static int p[], trie[], u[], v[];
static String s1[];
static long seive[], factorial[], L[], R[];
static long N = (long) (1e5 + 10), K, M, sum = 0L, G, a1, ak, X, Y, C, l_, t_, P, R_, N_, X1, Y1, Z;
static long xs, ys, xt, yt;
static char mat[][];
static long H, mod = (998244353L);
static char ch[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
static int[] dx = {1, -1, 0, 0, 1, -1, 1, -1};
static int[] dy = {0, 0, 1, -1, -1, 1, 1, -1};
static int dir[][] = new int[][]{{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
static void A(int t) {
int countZero = 0;
for (long i : a) {
if (i == 0) {
++countZero;
}
}
if (countZero == n) {
ans.append("0");
} else if (countZero == 0) {
ans.append("1");
} else {
if ((countZero == 1) && (a[0] == 0)) {
ans.append("1");
} else if (countZero == 1 && a[n - 1] == 0) {
ans.append("1");
} else if (countZero == 2 && a[0] == 0 && a[n - 1] == 0) {
ans.append("1");
} else {
ans.append("2");
}
}
if (t != testCases) {
ans.append("\n");
}
}
public static void main(String[] Amit) throws IOException {
testCases = in.nextInt();
//testCases = 1;
//b = new long[200004];
for (int t = 0; t < testCases; ++t) {
A_input();
A(t + 1);
}
out.print(ans.toString());
out.flush();
}
private static void A_input() throws IOException {
n = in.nextInt();
a = new long[n];
for (int i = 0; i < n; ++i) {
a[i] = in.nextLong();
}
}
private static void B_input() throws IOException {
n = in.nextInt();
k = in.nextInt();
}
private static void C_input() throws IOException {
x = in.next().toCharArray();
n = x.length;
}
private static void C1_input() throws IOException {
X = in.nextLong();
M = in.nextLong();
}
private static void C2_input() throws IOException {
X = in.nextLong();
M = in.nextLong();
}
private static void D_input() throws IOException {
n = in.nextInt();
a = new long[n];
for (int i = 0; i < n; ++i) {
a[i] = in.nextLong();
}
}
private static void D1_input() throws IOException {
}
private static void D2_input() throws IOException {
N = in.nextLong();
K = in.nextLong();
}
private static void E_input() throws IOException {
n = in.nextInt();
m = in.nextInt();
}
static void F_input() throws IOException {
n = in.nextInt();
a = new long[n];
m = in.nextInt();
for (int i = 0; i < n; ++i) {
a[i] = in.nextLong();
}
u = new int[m];
v = new int[m];
for (int i = 0; i < m; ++i) {
u[i] = in.nextInt() - 1;
v[i] = in.nextInt() - 1;
}
}
static void G1_input() {
n = in.nextInt();
a = new long[n + 1];
for (int i = 1; i <= n; ++i) {
a[i] = in.nextLong();
}
}
static void G_input() {
n = in.nextInt();
u = new int[n - 1];
v = new int[n - 1];
for (int i = 0; i < n - 1; ++i) {
u[i] = in.nextInt();
v[i] = in.nextInt();
}
}
private static class SegmentTree {
private long arr[], tree[];
private int len;
public SegmentTree(long arr[]) {
this.arr = arr;
int n = this.arr.length;
int height = (int) Math.ceil(Math.log(n) / Math.log(2));
int maxSize = 2 * (int) Math.pow(2, height) + 10;
this.len = maxSize;
this.tree = new long[this.len];
buildSegmentTree(0, n - 1, 0);
}
private void buildSegmentTree(int start, int end, int node) {
if (start == end) {
tree[node] = arr[start];
return;
}
int mid = (start + end) / 2;
buildSegmentTree(start, mid, 2 * node + 1);
buildSegmentTree(mid + 1, end, 2 * node + 2);
tree[node] = gcd(tree[2 * node + 1], tree[2 * node + 2]);
}
public long rangeGCD(int L, int R) {
return rangeGCDUtil(0, arr.length - 1, L, R, 0);
}
private long rangeGCDUtil(int start, int end, int L, int R, int node) {
if (start > R || end < L) {
return 0;
}
if (start >= L && end <= R) {
return tree[node];
}
int mid = (start + end) / 2;
return gcd(rangeGCDUtil(start, mid, L, R, 2 * node + 1),
rangeGCDUtil(mid + 1, end, L, R, 2 * node + 2));
}
public void update(int idx, long value) {
if (idx < 0 || idx >= arr.length) {
throw new IndexOutOfBoundsException("Index out of bounds");
}
arr[idx] = value;
updateUtil(0, arr.length - 1, idx, value, 0);
}
private void updateUtil(int start, int end, int idx, long value, int node) {
if (start == end) {
tree[node] = value;
return;
}
int mid = (start + end) / 2;
if (idx <= mid) {
updateUtil(start, mid, idx, value, 2 * node + 1);
} else {
updateUtil(mid + 1, end, idx, value, 2 * node + 2);
}
tree[node] = gcd(tree[2 * node + 1], tree[2 * node + 2]);
}
}
private static long xnor(long x, long y) {
// x should be larger
if (x < y) {
// swapping x and y;
long temp = x;
x = y;
y = temp;
}
if (x == 0 && y == 0) {
return 1L;
}
// for last bit of x
long x_rem = 0L;
// for the last bit of y
long y_rem = 0L;
// counter for c bit
// and set bit in xnorn
long c = 0;
// to make new xnor number
long xnorn = 0;
// for set bits in new xnor number
while (true) {
// get last bit of x
x_rem = x & 1;
// get the last bit of y
y_rem = y & 1;
// Checking if the current two bits are the same
if (x_rem == y_rem) {
xnorn |= (1 << c);
}
// counter for c bit
c++;
x = x >> 1;
y = y >> 1;
if (x < 1) {
break;
}
}
return xnorn;
}
private static class Pair_ implements Comparable<Pair_> {
long u, v;
public Pair_(long u, long v) {
this.u = u;
this.v = v;
}
@Override
public int compareTo(Pair_ p) {
if (this.u > p.u) {
return 1;
} else if (this.u < p.u) {
return -1;
} else if (this.u == p.u) {
if (this.v > p.v) {
return 1;
} else if (this.v < p.v) {
return -1;
} else {
return 0;
}
}
return 0;
}
@Override
public int hashCode() {
int hash = 5;
hash = 11 * hash + (int) (this.u ^ (this.u >>> 32));
hash = 11 * hash + (int) (this.v ^ (this.v >>> 32));
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Pair_ other = (Pair_) obj;
if (this.u != other.u) {
return false;
}
return this.v == other.v;
}
}
private static class Element implements Comparable<Element> {
long first, second, third;
public Element(long first, long second) {
this.first = first;
this.second = second;
}
public Element(long first, long second, long third) {
this.first = first;
this.second = second;
this.third = third;
}
public Element(long first) {
this.first = first;
}
@Override
public int compareTo(Element element) {
if (this.first > element.first) {
return -1;
} else if (this.first < element.first) {
return 1;
} else if (this.first == element.first) {
return 0;
}
return 0;
}
}
private static class Point {
double x, y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
private double distance(Point p) {
return Math.sqrt(Math.pow(Math.abs(this.x - p.x), 2L) + Math.pow(Math.abs(this.y - p.y), 2L));
}
}
static void print(long a[]) {
for (long i : a) {
System.out.print(i + " ");
}
System.out.println("");
}
static void print(int a[]) {
for (int i : a) {
System.out.print(i + " ");
}
System.out.println();
}
static void factorial() {
int N = (2 * (int) (1e5)) + 1;
factorial = new long[N];
--N;
factorial[0] = 1L;
for (int i = 1; i <= N; ++i) {
factorial[i] = factorial[i - 1] * i;
factorial[i] %= mod;
}
}
static void copy(int i, long a[], long b[]) {
if (i >= a.length) {
return;
}
a[i] = b[i];
copy(i + 1, a, b);
}
static void seive() {
seive = new long[10000001];
int n = 10000001;
for (int i = 1; i < n; ++i) {
seive[i] = i;
}
for (int i = 2; i * i <= n; ++i) {
if (seive[i] == i) {
for (int j = i * i; j < n; j += i) {
seive[j] = i;
}
}
}
}
static void copy(int i, long b[]) {
if (i > n) {
return;
}
b[i] = a[i - 1];
copy(i + 1, b);
}
static void reverse(char x[]) {
int n = x.length;
for (int i = 0; i < n / 2; ++i) {
char temp = x[i];
x[i] = x[n - i - 1];
x[n - i - 1] = temp;
}
}
static void reverse(long a[], int l, int r) {
while (l < r) {
swap(a, l, r);
++l;
--r;
}
}
static boolean equal(long a, long b) {
return String.valueOf(a).equalsIgnoreCase(String.valueOf(b));
}
static int mod(String num, int a) {
int res = 0;
for (int i = 0; i < num.length(); i++) {
res = (res * 10 + (int) num.charAt(i) - '0') % a;
}
return res;
}
static long mod(String num, long a) {
long res = 0L;
for (int i = 0; i < num.length(); i++) {
res = (res * 10 + (long) num.charAt(i) - '0') % a;
}
return res;
}
static long mul(long a[], int i, long mul) {
if (i >= a.length) {
return mul;
}
mul *= a[i];
return mul(a, i + 1, mul);
}
static long sum(long a[], int i, long sum) {
if (i >= a.length) {
return sum;
}
sum = (a[i] + sum);
//sum %= mod;
return sum(a, i + 1, sum);
}
static long max(long a[], int n, int i, long max) {
if (i >= n) {
return max;
}
max = Math.max(a[i], max);
return max(a, n, i + 1, max);
}
static long min(long a[], int i, int n, long min) {
if (i >= n) {
return min;
}
min = Math.min(min, a[i]);
return min(a, i + 1, n, min);
}
static int min_index(long a[], int n, int i, long min, int min_index) {
if (i >= n) {
return min_index;
}
if (a[i] == min) {
min_index = i;
}
return min_index(a, n, i + 1, min, min_index);
}
static class pair implements Comparable<pair> {
long value;
int index;
public pair(long value, int index) {
this.value = value;
this.index = index;
}
@Override
public int compareTo(pair p) {
if (this.value > p.value) {
return 1;
} else if (this.value < p.value) {
return -1;
}
return 0;
}
}
static long pow(long value, long power) {
long pow_value = 1L;
while (power > 0L) {
if (power % 2L == 1L) {
pow_value *= value;
pow_value %= mod;
}
value *= value;
value %= mod;
power /= 2L;
}
return pow_value;
}
static int upper_bound(long arr[], int N, long X) {
int mid;
int low = 0;
int high = N;
while (low < high) {
mid = low + (high - low) / 2;
if (X >= arr[mid]) {
low = mid + 1;
} else {
high = mid;
}
}
if (low < N && arr[low] <= X) {
low++;
}
return low;
}
static int upper_bound(double arr[], int N, double X) {
int mid;
int low = 0;
int high = N;
while (low < high) {
mid = low + (high - low) / 2;
if (X >= arr[mid]) {
low = mid + 1;
} else {
high = mid;
}
}
if (low < N && arr[low] <= X) {
low++;
}
return low;
}
static int lower_bound(long a[], long value) {
int n = a.length;
int l = 0, r = n - 1;
int index = -1;
while (r >= l) {
int mid = (l + r) / 2;
if (a[mid] > value) {
r = mid - 1;
} else {
l = mid + 1;
index = mid;
}
}
return index;
}
static int lower_bound(double a[], double value) {
int n = a.length;
int l = 0, r = n - 1;
int index = 0;
while (r > l) {
int mid = (l + r) / 2;
if (a[mid] > value) {
r = mid - 1;
} else {
l = mid + 1;
index = mid;
}
}
return index;
}
static long gcd(long a, long b) {
if (b == 0L) {
return a;
}
return gcd(b, a % b);
}
static long lcm(long a, long b) {
long gcd = gcd(a, b);
long lcm = (a * b) / gcd;
return lcm;
}
static class Binary_Index_Tree {
int len;
long element[];
int index[];
public Binary_Index_Tree(int len) {
element = new long[len + 1];
index = new int[len + 2];
this.len = len;
}
void add(int index, long value) {
for (; index <= len; index += (index & -index)) {
element[index] += value;
}
}
long query(int index) {
long sum = 0L;
for (; index > 0; index -= (index & -index)) {
sum += element[index];
}
return sum;
}
int get(int index) {
if (this.index[index] == index) {
return index;
} else {
return this.index[index] = get(this.index[index]);
}
}
}
static int search(long a[], long x, int last) {
int i = 0, j = last;
while (i <= j) {
int mid = i + (j - i) / 2;
if (a[mid] == x) {
return mid;
}
if (a[mid] < x) {
i = mid + 1;
} else {
j = mid - 1;
}
}
return -1;
}
static void swap(long a[], int i, int j) {
long temp = a[i];
a[i] = a[j];
a[j] = temp;
}
static void swap(int a[], int i, int j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
static void reverse(long a[]) {
int len = a.length;
for (int i = 0; i < len / 2; ++i) {
swap(a, i, len - i - 1);
}
}
static long max_element(long a[], int i, int n, long max) {
if (i > n) {
return max;
}
max = Math.max(a[i], max);
return max(a, i + 1, n, max);
}
static long min_element(long a[], int i, int n, long max) {
if (i > n) {
return max;
}
max = Math.min(a[i], max);
return max(a, i + 1, n, max);
}
static void printArray(long a[]) {
for (long i : a) {
System.out.print(i + " ");
}
System.out.println();
}
static boolean isSmaller(String str1, String str2) {
int n1 = str1.length(), n2 = str2.length();
if (n1 < n2) {
return true;
}
if (n2 < n1) {
return false;
}
for (int i = 0; i < n1; i++) {
if (str1.charAt(i) < str2.charAt(i)) {
return true;
} else if (str1.charAt(i) > str2.charAt(i)) {
return false;
}
}
return false;
}
static String sub(String str1, String str2) {
if (isSmaller(str1, str2)) {
String t = str1;
str1 = str2;
str2 = t;
}
String str = "";
int n1 = str1.length(), n2 = str2.length();
int diff = n1 - n2;
int carry = 0;
for (int i = n2 - 1; i >= 0; i--) {
int sub
= (((int) str1.charAt(i + diff) - (int) '0')
- ((int) str2.charAt(i) - (int) '0')
- carry);
if (sub < 0) {
sub = sub + 10;
carry = 1;
} else {
carry = 0;
}
str += String.valueOf(sub);
}
for (int i = n1 - n2 - 1; i >= 0; i--) {
if (str1.charAt(i) == '0' && carry > 0) {
str += "9";
continue;
}
int sub = (((int) str1.charAt(i) - (int) '0')
- carry);
if (i > 0 || sub > 0) {
str += String.valueOf(sub);
}
carry = 0;
}
return new StringBuilder(str).reverse().toString();
}
static String sum(String str1, String str2) {
if (str1.length() > str2.length()) {
String t = str1;
str1 = str2;
str2 = t;
}
String str = "";
int n1 = str1.length(), n2 = str2.length();
int diff = n2 - n1;
int carry = 0;
for (int i = n1 - 1; i >= 0; i--) {
int sum = ((int) (str1.charAt(i) - '0')
+ (int) (str2.charAt(i + diff) - '0') + carry);
str += (char) (sum % 10 + '0');
carry = sum / 10;
}
for (int i = n2 - n1 - 1; i >= 0; i--) {
int sum = ((int) (str2.charAt(i) - '0') + carry);
str += (char) (sum % 10 + '0');
carry = sum / 10;
}
if (carry > 0) {
str += (char) (carry + '0');
}
return new StringBuilder(str).reverse().toString();
}
static long detect_sum(int i, long a[], long sum) {
if (i >= a.length) {
return sum;
}
return detect_sum(i + 1, a, sum + a[i]);
}
static String mul(String num1, String num2) {
int len1 = num1.length();
int len2 = num2.length();
if (len1 == 0 || len2 == 0) {
return "0";
}
int result[] = new int[len1 + len2];
int i_n1 = 0;
int i_n2 = 0;
for (int i = len1 - 1; i >= 0; i--) {
int carry = 0;
int n1 = num1.charAt(i) - '0';
i_n2 = 0;
for (int j = len2 - 1; j >= 0; j--) {
int n2 = num2.charAt(j) - '0';
int sum = n1 * n2 + result[i_n1 + i_n2] + carry;
carry = sum / 10;
result[i_n1 + i_n2] = sum % 10;
i_n2++;
}
if (carry > 0) {
result[i_n1 + i_n2] += carry;
}
i_n1++;
}
int i = result.length - 1;
while (i >= 0 && result[i] == 0) {
i--;
}
if (i == -1) {
return "0";
}
String s = "";
while (i >= 0) {
s += (result[i--]);
}
return s;
}
static class Node<T> {
T data;
Node<T> next;
public Node() {
this.next = null;
}
public Node(T data) {
this.data = data;
this.next = null;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public Node<T> getNext() {
return next;
}
public void setNext(Node<T> next) {
this.next = next;
}
@Override
public String toString() {
return this.getData().toString() + " ";
}
}
static class ArrayList1<T> {
Node<T> head, tail;
int len;
public ArrayList1() {
this.head = null;
this.tail = null;
this.len = 0;
}
int size() {
return len;
}
boolean isEmpty() {
return len == 0 || head == null || tail == null;
}
int indexOf(T data) {
if (isEmpty()) {
throw new ArrayIndexOutOfBoundsException();
}
Node<T> temp = head;
int index = -1, i = 0;
while (temp != null) {
if (temp.getData() == data) {
index = i;
}
i++;
temp = temp.getNext();
}
return index;
}
void add(T data) {
Node<T> newNode = new Node<>(data);
if (isEmpty()) {
head = newNode;
tail = newNode;
len++;
} else {
tail.setNext(newNode);
tail = newNode;
len++;
}
}
void see() {
if (isEmpty()) {
throw new ArrayIndexOutOfBoundsException();
}
Node<T> temp = head;
while (temp != null) {
System.out.print(temp.getData().toString() + " ");
//out.flush();
temp = temp.getNext();
}
System.out.println();
//out.flush();
}
void inserFirst(T data) {
Node<T> newNode = new Node<>(data);
Node<T> temp = head;
if (isEmpty()) {
head = newNode;
tail = newNode;
len++;
} else {
newNode.setNext(temp);
head = newNode;
len++;
}
}
T get(int index) {
if (isEmpty() || index >= len) {
throw new ArrayIndexOutOfBoundsException();
}
if (index == 0) {
return head.getData();
}
Node<T> temp = head;
int i = 0;
T data = null;
while (temp != null) {
if (i == index) {
data = temp.getData();
}
i++;
temp = temp.getNext();
}
return data;
}
void addAt(T data, int index) {
if (index >= len) {
throw new ArrayIndexOutOfBoundsException();
}
Node<T> newNode = new Node<>(data);
int i = 0;
Node<T> temp = head;
while (temp.next != null) {
if (i == index) {
newNode.setNext(temp.next);
temp.next = newNode;
}
i++;
temp = temp.getNext();
}
// temp.setNext(temp);
len++;
}
void popFront() {
if (isEmpty()) {
//return;
throw new ArrayIndexOutOfBoundsException();
}
if (head == tail) {
head = null;
tail = null;
} else {
head = head.getNext();
}
len--;
}
void removeAt(int index) {
if (index >= len || index < 0) {
throw new ArrayIndexOutOfBoundsException();
}
if (index == 0) {
this.popFront();
return;
}
Node<T> temp = head;
int i = 0;
Node<T> n = new Node<>();
while (temp != null) {
if (i == index) {
n.next = temp.next;
temp = n;
--len;
//break;
}
i++;
n = temp;
temp = temp.getNext();
}
//tail = n;
//--len;
}
void clearAll() {
this.head = null;
this.tail = null;
}
}
static void merge(long a[], int left, int right, int mid) {
int n1 = mid - left + 1, n2 = right - mid;
long L[] = new long[n1];
long R[] = new long[n2];
for (int i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (int i = 0; i < n2; i++) {
R[i] = a[mid + 1 + i];
}
int i = 0, j = 0, k1 = left;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
a[k1] = L[i];
i++;
} else {
a[k1] = R[j];
j++;
}
k1++;
}
while (i < n1) {
a[k1] = L[i];
i++;
k1++;
}
while (j < n2) {
a[k1] = R[j];
j++;
k1++;
}
}
static void sort(long a[], int left, int right) {
if (left >= right) {
return;
}
int mid = (left + right) / 2;
sort(a, left, mid);
sort(a, mid + 1, right);
merge(a, left, right, mid);
}
static void merge(double a[], int left, int right, int mid) {
int n1 = mid - left + 1, n2 = right - mid;
double L[] = new double[n1];
double R[] = new double[n2];
for (int i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (int i = 0; i < n2; i++) {
R[i] = a[mid + 1 + i];
}
int i = 0, j = 0, k1 = left;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
a[k1] = L[i];
i++;
} else {
a[k1] = R[j];
j++;
}
k1++;
}
while (i < n1) {
a[k1] = L[i];
i++;
k1++;
}
while (j < n2) {
a[k1] = R[j];
j++;
k1++;
}
}
static void sort(double a[], int left, int right) {
if (left >= right) {
return;
}
int mid = (left + right) / 2;
sort(a, left, mid);
sort(a, mid + 1, right);
merge(a, left, right, mid);
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void println() {
writer.println();
}
public void print(long[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(array[i]);
}
}
public void separateLines(int[] array) {
for (int i : array) {
println(i);
}
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
static class Scanner {
private final InputStream stream;
private final byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public Scanner(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int peek() {
if (numChars == -1) {
return -1;
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int sum = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
sum *= 10;
sum += c - '0';
c = read();
} while (!isSpaceChar(c));
return sum * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long sum = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
sum *= 10;
sum += c - '0';
c = read();
} while (!isSpaceChar(c));
return sum * sgn;
}
public String next() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder sum = new StringBuilder();
do {
if (Character.isValidCodePoint(c)) {
sum.appendCodePoint(c);
}
c = read();
} while (!isSpaceChar(c));
return sum.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private String readLine0() {
StringBuilder buf = new StringBuilder();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r') {
buf.appendCodePoint(c);
}
c = read();
}
return buf.toString();
}
public String readLine() {
String s = readLine0();
while (s.trim().length() == 0) {
s = readLine0();
}
return s;
}
public String readLine(boolean ignoreEmptyLines) {
if (ignoreEmptyLines) {
return readLine();
} else {
return readLine0();
}
}
public String nextLine() {
return readLine();
}
public char nextCharacter() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
return (char) c;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double sum = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E') {
return sum * Math.pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
sum *= 10;
sum += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E') {
return sum * Math.pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
m /= 10;
sum += (c - '0') * m;
c = read();
}
}
return sum * sgn;
}
public boolean isExhausted() {
int value;
while (isSpaceChar(value = peek()) && value != -1) {
read();
}
return value == -1;
}
public SpaceCharFilter getFilter() {
return filter;
}
public void setFilter(SpaceCharFilter filter) {
this.filter = filter;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
public int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; ++i) {
array[i] = nextInt();
}
return array;
}
public int[] nextSumIntArray(int n) {
int[] array = new int[n];
array[0] = nextInt();
for (int i = 1; i < n; ++i) {
array[i] = array[i - 1] + nextInt();
}
return array;
}
public long[] nextLongArray(int n) {
long[] array = new long[n];
for (int i = 0; i < n; ++i) {
array[i] = nextLong();
}
return array;
}
public long[] nextSumLongArray(int n) {
long[] array = new long[n];
array[0] = nextInt();
for (int i = 1; i < n; ++i) {
array[i] = array[i - 1] + nextInt();
}
return array;
}
}
}
|
2049A
|
wrong_submission
|
297,491,565 |
C++23 (GCC 14-64, msys2)
|
WRONG_ANSWER on test 2
|
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<algorithm>
#include<set>
#define mod 1000000007
#define ll long long
using namespace std;
ll max(ll a,ll b)
{
return a>=b?a:b;
}
ll min(ll a,ll b)
{
return a<=b?a:b;
}
ll divi(ll a,ll b)
{
if(a%b)
{
return a/b+1;
}
return a/b;
}
void solve()
{
ll n,i,j;
cin>>n;
vector<ll>vec(n);
ll zero_count=0;
for(i=0;i<n;i++)
{
cin>>vec[i];
if(vec[i]==0)
zero_count++;
}
if(zero_count==0)
{
cout<<1<<endl;
return;
}
if(zero_count==n)
{
cout<<0<<endl;
return;
}
if(zero_count==1)
{
if(vec[0]==0 || vec[n-1]==0)
{
cout<<1<<endl;
return;
}
cout<<2<<endl;
return;
}
ll consecutive=0;
i=0;
while(i<n)
{
if(vec[i]!=0)
{
i++;
continue;
}
if(i!=0)
consecutive++;
i++;
}
if(consecutive==1)
{
cout<<1<<endl;
return;
}
cout<<2<<endl;
}
int main()
{
ll cases;
cin>>cases;
while(cases--)
solve();
}
/*
1
3 10
4 8 4
2 9 10
10
1 14 30 1 16 25 2 32 4 44
1 8 16 24 32 40 48 56 64 72 80 88 96 104 112 120 128
*/
|
2049A
|
wrong_submission
|
297,612,405 |
C++20 (GCC 13-64)
|
WRONG_ANSWER on test 2
|
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vs vector<string>
#define vb vector<bool>
#define pb push_back
#define pii pair<int, int>
#define vpi vector<pii>
#define M 1000000007
#define endl "\n"
// #define int long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, k, n) for (int i = k; i <= n; i++)
#define rep2(i, k, n) for (int i = k; i >= n; i--)
#define print(a) \
rep(i, a.size()) cout << a[i] << ' '; \
cout << endl;
#define printvpi(a) \
rep(i, a.size()) cout << a[i].f << ' ' << a[i].s << endl; \
cout << endl;
#define read(a, n) \
vi a(n); \
rep(i, n) cin >> a[i];
#define inp(a) \
int a; \
cin >> a;
#define all(a) a.begin(), a.end()
#define mi map<int, int>
#define f first
#define s second
vector<vi> adj(1e5 + 1);
vi vis(1e5 + 1, 0);
vi dist(1e5 + 1, 0);
bool great(pii &a, pii &b)
{
return a.first > b.first;
}
void solve()
{
inp(n);
read(a, n);
if (all_of(all(a), [](int x)
{ return x == 0; }))
{
cout << 0 << endl;
return;
}
if (all_of(all(a), [](int x)
{ return x != 0; }))
{
cout << 1 << endl;
return;
}
if (a[0] == 0 && a[n - 1] == 0)
{
int j = 0;
while (j < n && a[j] == 0)
j++;
bool flag = false;
rep1(i, j, n - 2)
{
if (a[i] == 0)
{
cout << 2 << endl;
flag = true;
break;
}
}
if (!flag)
{
cout << 1 << endl;
}
return;
}
if (a[0] == 0)
{
int j = 0;
while (j < n && a[j] == 0)
j++;
bool flag = false;
rep1(i, j, n - 1)
{
if (a[i] == 0)
{
cout << 2 << endl;
return;
}
}
cout << 1 << endl;
return;
}
if (a[n - 1] == 0)
{
int j = n - 2;
while (j >=0 &&a[j] == 0)
j--;
bool flag = false;
rep2(i, j, 0)
{
if (a[i] == 0)
{
cout << 2 << endl;
return;
}
}
cout << 1 << endl;
return;
}
cout << 2 << endl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt = 1;
cin >> tt;
while (tt--)
{
solve();
}
return 0;
}
|
2049A
|
wrong_submission
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.