12160 - Unlock the Lock

All about problems in Volume 121. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
tamim1382csedu19
New poster
Posts: 18
Joined: Mon Jun 03, 2013 5:09 pm

12160 - Unlock the Lock

Post by tamim1382csedu19 » Fri Oct 25, 2013 3:37 pm

Getting WA for the problem. It should be a simple bfs problem. Here's my code

Code: Select all

#include <iostream>
#include <queue>
#include <string.h>
#include <stdio.h>
using namespace std;
int visited[10005];


int main()
{
    int lock,unlck,r,kase = 1;
    while(cin>>lock>>unlck>>r && (lock||unlck||r))
    {
        int A[r];
        for(int i=0;i<r;++i)
            cin>>A[i];
            memset(visited,-1,sizeof visited);
            queue<int> q;
            q.push(lock);
            bool found = 0;
            visited[lock] = 0;
            while(!q.empty())
             {

                int u = q.front(); q.pop();
                if(u == unlck)
                {
                    found = 1;
                    break;
                }
                for(int i=0;i<r;++i)
                {
                    int x = (u+A[i])%10000;
                    if(visited[x] != (-1) || x == lock)
                        continue;
                    visited[x] = visited[u] + 1;
                    q.push(x);

                }
            }
            if(!found)
                printf("Case %d: Permanently Locked\n",kase++);
            else
                printf("Case %d: %d\n",kase++,visited[unlck]);


    }
}
ideone link http://ideone.com/C6Oc1z

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12160 - Unlock the Lock

Post by brianfry713 » Fri Oct 25, 2013 9:37 pm

It looks like you figured it out
Check input and AC output for thousands of problems on uDebug!

triplemzim
New poster
Posts: 48
Joined: Sat Apr 06, 2013 6:02 pm

Re: 12160 - Unlock the Lock

Post by triplemzim » Fri Jan 10, 2014 9:14 am

Getting Wrong answer please help: here is my code:

Code: Select all

AC
:)
Last edited by triplemzim on Fri Jan 17, 2014 3:04 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12160 - Unlock the Lock

Post by brianfry713 » Wed Jan 15, 2014 12:10 am

That is AC code
Check input and AC output for thousands of problems on uDebug!

triplemzim
New poster
Posts: 48
Joined: Sat Apr 06, 2013 6:02 pm

Re: 12160 - Unlock the Lock

Post by triplemzim » Fri Jan 17, 2014 3:03 pm

brianfry713 wrote:That is AC code
I am surprised. I did not cleared the vector. But after clearing I din't submit it. So sorry. That is an AC code.

Post Reply

Return to “Volume 121 (12100-12199)”