TWTCLOSE - Editorial

Why is this getting WA?

can anyone please point out my mistake in this solution, it gives wrong ans on submission.

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
def end(x):
    return x[-1:]
n,k = input().split()
n,k = int(n),int(k)
tweetstatus = []
while n>0:
    n -= 1
while k>0:
    s = str(input())
    if s == 'CLOSEALL':
        for i in range(len(tweetstatus)):
            tweetstatus* = 0
        z = int(end(s))
        if tweetstatus[z-1] == 0:
            tweetstatus[z-1] = 1
            tweetstatus[z-1] = 0
    k-= 1

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("CLICK")==0){ cin>>in; if(arr[in-1]){ arr[in] = 0; count--; } else{ arr[in-1] = 1; count++; } } else if("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 correct

this got correct when i didn’t. is not correct

can anyone help me finding out why.

Can anyone help why I am getting a wrong answer?
My solution is

I am unable to understand what is wrong with this solution :
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(
at java.base/java.lang.String.charAt(
at numberOfOpenTweets.main(
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.
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 -

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 -


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

1 Like

Thanks a lot!! :smiley:

most welcome :slight_smile:

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

using namespace std;
int main ()
{ ios_base::sync_with_stdio(false);
int n,k;
std::string str;
std::bitset<1000> boo;
if(str ==“CLOSEALL”){

    int c;
    boo = boo.flip(1000-c);


return 0;