TWTCLOSE - Editorial

https://www.codechef.com/viewsolution/10581225

Why is this getting WA?

can anyone please point out my mistake in this solution, it gives wrong ans on submission.
https://www.codechef.com/viewsolution/11548341

its showing wrong answer but works fine. can anyone please tell me whats wrong?

def checker(x):
    p = 0
    for i in range(len(x)):
        if x* == 1:
            p += 1
    print(p)
 
 
def end(x):
    return x[-1:]
n,k = input().split()
n,k = int(n),int(k)
 
tweetstatus = []
while n>0:
    tweetstatus.append(0)
    n -= 1
while k>0:
    s = str(input())
 
    if s == 'CLOSEALL':
        for i in range(len(tweetstatus)):
            tweetstatus* = 0
 
    else:
        z = int(end(s))
 
        if tweetstatus[z-1] == 0:
            tweetstatus[z-1] = 1
        else:
            tweetstatus[z-1] = 0
 
    checker(tweetstatus)
 
 
 
    k-= 1

https://www.codechef.com/viewsolution/15965360

Can anyone tell me what’s wrong in my solution? It’s showing Runtime error.

My solution is working correctly with the sample test case(after running on my system)
But not working after submission.
Please help me out!
#include<iostream> #include<string> using namespace std; int main(){ int N,K; cin>>N>>K; string choice; int in,count = 0,arr[N]; for(int i = 0;i < N;i++) arr* = 0; while(K--){ cin>>choice; if(choice.compare("CLICK")==0){ cin>>in; if(arr[in-1]){ arr[in] = 0; count--; } else{ arr[in-1] = 1; count++; } } else if(choice.compare("CLOSEALL")==0){ for(int j = 0;j < K;j++) arr[j] = 0; count = 0; } cout<<count<<endl; } }

I applied the same approach

while it gets wrong when i use getline

https://www.codechef.com/viewsolution/16737490 correct

this got correct when i didn’t.

https://www.codechef.com/viewsolution/16737259 is not correct

can anyone help me finding out why.

Can anyone help why I am getting a wrong answer?
My solution is https://www.codechef.com/viewsolution/18952476

I am unable to understand what is wrong with this solution : https://www.codechef.com/viewsolution/19271123
When i run this program it shows : Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 7
at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:44)
at java.base/java.lang.String.charAt(String.java:692)
at numberOfOpenTweets.main(numberOfOpenTweets.java:16)
So if you can spot the error please tell

Memset would also take O(N) time to go through each element. But yes, the actual time might be lesser.
For every CLOSEALL, we do not do anything if number of tweets is 0. That could help but doesn’t lower worst case time.

I used memset for filling 0s. My solution was showing wrong answer though I have implemented it same as mentioned in the tutorial.
http://www.codechef.com/viewsolution/1132512
Can’t find what is the difference :frowning:

@vikram535 : Please check the ‘memset’ function in the library. The last parameter should be the number of bytes, and not number of elements in the array. If your array is int A[1001]; , you should use it as, memset(A,0,sizeof(A));

1 Like

You meant for example O(1/2 * N)? In fact that doesn’t matter, it’s asymptotically O(N).

Thank you so much for pointing out my mistake. I was not able to find it. Thanks again :slight_smile:

here is counter example - http://ideone.com/A6o21

hey thnx…my mistake i didn’t observe dat…thnx a lot…

Your class cannot be public, that’s the first problem at CodeChef. In addition

int c = Integer.parseInt(t1.substring(n - 1, n));
c = c - 1;

smells - http://ideone.com/J3TYWf

@ajinkya1p3

You forgot to print number of open tweets after input “CLOSEALL”

I have added print statement and here’s the accepted version of your code

http://www.codechef.com/viewsolution/5479172

1 Like

Thanks a lot!! :smiley:

most welcome :slight_smile:

I did it in a similar way and the answer is submitted

#include
#include
#include
#include
using namespace std;
int main ()
{ ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
std::string str;
std::bitset<1000> boo;
while(k–){
cin>>str;
if(str ==“CLOSEALL”){
boo.reset();
cout<<0<<"\n";

}
else{
    int c;
    cin>>c;
    boo = boo.flip(1000-c);
    cout<<boo.count();
    cout<<endl;
}

}

return 0;
}