CLEANUP - Editorial

add return 0; at the end it will fix the run-time error

In java ,it’s showing NZEC error. WHY?
Any Hint?

In java , I’m getting NZEC error . why? any guess?

@sp1rs here - AkuyWd - Online Java Compiler & Debugging Tool - Ideone.com is input causing NZEC :wink:

so many people getting WA despite being a simple problem and what it seems to be a correct solution. Something is fishy here

1 Like

can anyone tell why my code gives runtime error sigsegv
#include
using namespace std;

int main()
{
int t;
cin>>t;
while(t–){
int n,m;
cin>>n>>m;
int a[n+1]={0};
for(int i=0;i<m;i++){
int x;
cin>>x;
a[x] = 1;
}
int c=0,f=0;
int chef[n]={0},ass[n]={0};
for(int i=1,j=0,k=0;i<n+1;i++){
if(a[i]==0&&c==0){
chef[j]=i;
j++;
c=1;
f=0;
}
else if(a[i]==0&&f==0){
ass[k]=i;
k++;
f=1;
c=0;
}
}
for(int i=0;chef[i]!=0;i++)cout<<chef[i]<<" “;
cout<<endl;
for(int i=0;ass[i]!=0;i++)cout<<ass[i]<<” ";
cout<<endl;
}
return 0;
}

tho it gives ac for int chef[n+1],ass[n+1];

Can someone guide me where the issue lies. It works perfectly with the Sample I/O but fails to submit correclty.

#include< iostream>
using namespace std;

// Completed jobs are marked as -1
// Chefs jobs are markes as 1
// Assistants are marked as 2

int main() {
int t;
cin >> t;
if(t > 50) return 0;
while(t–) {
//
// Input
//
int n, m;
cin >> n >> m;
if(n > 1000 || m > n) return 0;
int jobs[n];
for(int i = 0; i < m; i++) {
int mark;
cin >> mark;
if(mark >= n) return 0;
jobs[mark - 1] = -1;
}
//
// Filling and Flaging/marking
//
int turn = 1, chefs = 0, assistants = 0;
for(int i = 0; i < n; i++) {
if(jobs[i] == -1) {
continue;
}
else if(turn == 1) {
jobs[i] = 1;
chefs++;
turn = 2;
}
else if(turn == 2) {
jobs[i] = 2;
assistants++;
turn = 1;
}
}
//
// Output for chef
//
for(int i = 0; i < n; i++)
if(jobs[i] == 1) {
cout << i + 1;
if(chefs-- > 1) cout << " ";
}
cout << endl;
//
// Output for Assistant
//
for(int i = 0; i < n; i++)
if(jobs[i] == 2) {
cout << i + 1;
if(assistants-- > 1) cout << " ";
}
if(t != 0) cout << endl;
}
return 0;
}

from array import array

t = int(input())
while t > 0:
n, m = map(int, input().split())
completed = array(‘i’, map(int, input().split()))
tasks = array(‘i’, range(1, n+1))
chefs = []
assitants = []
tasks = list(set(tasks) - set(completed))
tasks.sort()
for i, val in enumerate(tasks):
if i % 2 == 0:
chefs.append(str(val))
else:
assitants.append(str(val))
print(’ ‘. join(chefs))
print(’ '.join(assitants))
t = t - 1

MEETOO :slight_smile: Wrong answer, but there is no one to check the code on the server now…

Can anyone please post executed python code for this question? Because I’m getting run time error while trying to submit the question.

for _ in range(int(input())):
	n, m = map(int, input().split())
	s = list(map(int, input().split()))
	l = []
	for i in range(1, n+1):
		l.append(i)	
	for p in s:
		l.remove(p)
	chef = []
	assistant = []
	for i in l:
		if (l.index(i)+1)%2 == 0:
			assistant.append(i)
		else:
			chef.append(i)
	print(*chef, sep = ' ')
	print(*assistant, sep = ' ')

Use Try catch. error Will be gone!!

I have solved the problem in c# .but i cannot submit the program as c# is not avaliable .i had drop a mail at bugs@codechef.com but have not received the response.

#include <iostream>

#include
using namespace std;

int main() {
// your code goes here
int t,c,a,fin;
int n,m;
cin>>t;
while(t–){
bool turn=true;
float n1,m1,s;
cin>>n1>>m1;
n=n1,m=m1;
s=(double)(n-m)/2;
a=floor(s);
c=ceil(s);
int chef[c],ass[a],ci=0,ai=0;
bool arr[n];
fill_n(arr, n, 0);
for(int i=0;i<m;i++){
cin>>fin;
arr[fin-1]=true;
}
for(int i=0;i<n;i++){
if(arr[i]==false){
if(turn==true){
chef[ci]=i+1;
ci++;
turn=false;
}else{
ass[ai]=i+1;
ai++;
turn=true;
}
}
}

    for(int i=0;i<c;i++){
        cout<<chef[i]<<" ";
    }
    cout<<endl;
    for(int i=0;i<a;i++){
        cout<<ass[i]<<" ";
    }
    cout<<endl;
}
return 0;

}

I can’t seem to find the mistake in this: -

    # cook your dish here
    try:
        t = int(input())
        while (t > 0):
            secondLine = list(map(int, input().strip().split(' ')))
            n = secondLine[0]
            m = secondLine[1]
            thirdLine = list(map(int, input().strip().split(' ')))
            chef = []
            assistant = []
            for i in range(1, n + 1):
                if i in thirdLine:
                    continue
                if (len(chef) + len(assistant)) == (n - m):
                    break
                if (len(chef) + len(assistant)) % 2 != 0:
                    assistant.append(i)
                else:
                    chef.append(i)
            t-=1
            print(*chef)
            if t == 0:
                print(*assistant, end='')
            else:
                print(*assistant)
    except:
        pass

It keeps giving me runtime error and if I put try/except then it gives wrong answer. Can someone please help?

I would advise everyone to not waste their time on this problem.
Your solutions are all correct and this problem is very straight forward.

There is an error in the judge because the inputs have not been tested properly across all languages. It’s a very frequent problem in Codechef contests to get runtime errors - sometimes its extra spaces, sometimes its invalid characters, anything and everything not conforming to specified input format. I am just more let down that this happened in a cook-off problem and is still not rectified

2 Likes

I agree. This should be addressed. I solved the problem in 15 mins and then ended up wasting 1.5 hours to understand what went wrong and still couldn’t figure it out. My core language is Java but I am writing these in python to learn it and kept thinking what mistake I made in syntax after I realized that the logic is correct.

1 Like

def createList(r1, r2):

if (r1 == r2): 

    return r1 

else:

    res = [] 

    while(r1 < r2+1 ): 

        res.append(r1) 

        r1 += 1

    return res

def Diff(li1, li2):

return (list(list(set(li1)-set(li2)) + list(set(li2)-set(li1))))

T = int(input())

for i in range(1,T+1):

N, M = input().split()

N = int(N)

M = int(M)

a = list(map(int,input().strip().split()))[:M]

r1 = 1

r2 = N

list1 = createList(r1,r2)

list2 = Diff(list1,a)

n = len(list2)

for i in range(0,n,2):

    print(list2[i],end=" ")

print("")

for j in range(1,n,2):

    print(list2[j],end=" ")

print("")

This code runs properly with custom inputs but it shows runtime error after submitting this

CodeChef: Practical coding for everyone[My code.]

Can anyone please help me, what is the mistake in my code/logic.
Thanks.

u r working with default values when only declaring array(char jobs[n+1]).
try to assign while declaring the array
char jobs[n+1]={0}