11385 - Da Vinci Code

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

Moderator: Board moderators

Kenpachi24
New poster
Posts: 20
Joined: Wed Oct 30, 2013 7:06 pm

Re: 11385 - Da Vinci Code

Post by Kenpachi24 » Fri Feb 07, 2014 8:35 am

Code: Select all

AC
Last edited by Kenpachi24 on Wed Feb 12, 2014 10:31 am, edited 2 times in total.

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

Re: 11385 - Da Vinci Code

Post by brianfry713 » Fri Feb 07, 2014 9:13 pm

Use class Main
Check input and AC output for thousands of problems on uDebug!

Kenpachi24
New poster
Posts: 20
Joined: Wed Oct 30, 2013 7:06 pm

Re: 11385 - Da Vinci Code

Post by Kenpachi24 » Fri Feb 07, 2014 11:50 pm

I forget to change in the moment of publish; but throws me RE

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

Re: 11385 - Da Vinci Code

Post by brianfry713 » Wed Feb 12, 2014 12:24 am

Try input:

Code: Select all

2
11
13 2 89 377 8 3 233 34 144 21 1
OH, LAME SAINT!AAAAAA
15
34 21 13 144 1597 3 987 610 8 5 89 2 377 2584 1
O, DRACONIAN DEVIL!
Check input and AC output for thousands of problems on uDebug!

chachachowdhury
New poster
Posts: 2
Joined: Wed Dec 17, 2014 5:26 pm

Re: 11385 - Da Vinci Code

Post by chachachowdhury » Wed Dec 17, 2014 5:29 pm

help wa

Code: Select all

#include <cmath>

#include <climits>

#include <queue>

#include <vector>

#include <map>

#include <cstdlib>

#include <fstream>

#include <iomanip>

#include <iostream>

#include <sstream>  // istringstream buffer(myString);

#include <stack>

#include <algorithm>

#include <cstring>

#include <cassert>

using namespace std;

#define bit(x,i) (x&(1<<i))  //select the bit of position i of x

#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x

#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest

#define max(a,b) (a<b?b:a)

#define abs(x) (x<0?(-x):x) // big bug here if "-x" is not surrounded by "()"

#define IN(i,l,r) (l<i&&i<r) //the next for are for checking bound

#define LINR(i,l,r) (l<=i&&i<=r)

#define LIN(i,l,r) (l<=i&&i<r)

#define INR(i,l,r) (l<i&&i<r)

#define F(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"

#define FE(i,L,R) for (int i = L; i <= R; i++)

#define FF(i,L,R) for (int i = L; i > R; i--)

#define FFE(i,L,R) for (int i = L; i >= R; i--)

#define getI(a) scanf("%d", &a) //next three are handy ways to get ints, it's also force you to use '&' sign

#define getII(a,b) scanf("%d%d", &a, &b)

#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)

#define wez(n) int (n); scanf("%d",&(n)) //handy if the input is right after the definition of a variable

#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m))

#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))

#define TESTS wez(testow)while(testow--) //for multilple cases problems

#define whileZ int T; getI(T); while(T--) // the same as above

#define getS(x) scanf("%s", x) //get a char* string

#define clr(a,x) memset(a,x,sizeof(a)) //set elements of array to some value

#define char2Int(c) (c-'0')

#define lastEle(vec) vec[vec.size()-1]

#define SZ(x) ((int)((x).size()))

#define REMAX(a,b) (a)=max((a),(b)) // set a to the maximum of a and b

#define REMIN(a,b) (a)=min((a),(b));

#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) // traverse an STL data structure

#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"

#define PRESENT(c,x) ((c).find(x) != (c).end())

#define CPRESENT(c,x) (find(ALL(c),x) != (c).end())

#define ll long long //data types used often, but you don't want to type them time by time

#define ull unsigned long long

#define ui unsigned int

#define us unsigned short

#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf

#define INF 1001001001

#define PI 3.1415926535897932384626

#define size 4000


using namespace std;

int ary[100+10];

map<int, int>M;

void pre()
{
    M.clear();

    ary[1] = 1;
    M[ary[1]]=1;
    ary[2] = 2;
    M[ary[2]]=2;

    for (int i = 3; i <46; i++)
    {
        ary[i] = ary[i - 1] + ary[i - 2];
        M[ary[i]] = i;
        //printf("%d\n",ary[17]);
        //printf("%d\n",M[ary[i]]);
    }
    //for (int i = 1; i <46; i++)
    //printf("%d %d\n",ary[17],M[ary[17]]);
}

int main()
{

    pre();
    //vector<int>numbers;
    string ss;
    int numbers[1010];
    char result[1010];

    //freopen("in.txt","r",stdin );
    //freopen("out.txt","w+",stdout );
    int test,fib,no;
    scanf("%d", &test);
    while ( test-- )
    {
        scanf("%d", &fib);
        for(int i=0; i<fib; i++)
        {
            scanf("%d",&numbers[i] );
            //numbers.push_back;
        }



        getchar();
        getline(cin,ss);
        //cout<<ss<<endl;

        memset(result,' ',sizeof(result));
        int k=0;
        int cn=0;
        int max=0;
        for(int i=0; i<ss.length(); i++)
        {
            if ( ss[i] >= 'A' && ss[i] <= 'Z' )
            {

                int y = M[ numbers[k] ];
                result[y-1] = ss[i];
                if( (y-1) > max )
                    max = y-1;

                k++;

            }
        }

        if( max == 0 )
        {
            sort( numbers,numbers+fib );
            int d=numbers[0];
            max=M[d];
            //printf("%d\n",max);
        }
        //result[]=;

        result[max+1]='\0';
        cout<<result;
        cout<<endl;

    }

    return 0;
}


lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11385 - Da Vinci Code

Post by lighted » Sun Dec 21, 2014 11:24 am

Input

Code: Select all

5
5
8 5 3 2 1
ABCDEFG
4
1 5 2 3
ABCDE
4
1 3 2 5 
A a B b C c D d E e
1
13
ABCD
1
3
ABC
Acc Output

Code: Select all

EDCBA
ACDB
ACBD
     A
  A
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

gautamzero
New poster
Posts: 32
Joined: Fri Oct 10, 2014 1:10 pm
Location: Sylhet, Bangladesh

Re: 11385 - Da Vinci Code

Post by gautamzero » Tue Dec 30, 2014 9:15 pm

why WA?? :(

Code: Select all

erased
Last edited by gautamzero on Wed Dec 31, 2014 6:16 pm, edited 1 time in total.
None but a fool is always right..
so don't be upset when u r wrong..

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11385 - Da Vinci Code

Post by lighted » Wed Dec 31, 2014 10:42 am

Increase array bound, one char for '\0'.

Code: Select all

char s2[l2 + 1];
Otherwise this line may lead to undefined results.

Code: Select all

s2[l2] = '\0';
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

gautamzero
New poster
Posts: 32
Joined: Fri Oct 10, 2014 1:10 pm
Location: Sylhet, Bangladesh

Re: 11385 - Da Vinci Code

Post by gautamzero » Wed Dec 31, 2014 6:10 pm

tnx :D but..
i coded same way many problems...
i got AC for them..
None but a fool is always right..
so don't be upset when u r wrong..

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11385 - Da Vinci Code

Post by lighted » Fri Jan 02, 2015 3:11 pm

If you got acc that way many times then you are very lucky, but not this time. :D
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Cpx
New poster
Posts: 2
Joined: Thu Oct 06, 2016 12:38 pm

Re: 11385 - Da Vinci Code

Post by Cpx » Sat Oct 22, 2016 5:46 pm

guys why is this code getting WA??

Code: Select all

#include<iostream>
#include<cstdio>
#include<string>
#include<string.h>
#include<utility>
#include<algorithm>
#include<vector>
#include<cstring>
#include<ctype.h>
#include<cstdlib>
#include<math.h>
using namespace std;
int main() {
	string katas;
	char ans[101];
	int series[101];
	int left, right, target, index, mid, k;
	vector<int> fibos;
	fibos.push_back(1);
	fibos.push_back(2);
	unsigned int a, b, c = 2, fib = 0;
	while (c <= 100) {
		if (fib >= 2147438647) break;
		fib = fibos[c - 2] + fibos[c - 1];
		fibos.push_back(fib);
		c++;
	}
	scanf("%d", &a);
	for (int i = 0; i < a; i++)
	{
		memset(ans, 32, sizeof(ans));
		scanf("%d", &b);
		for (int j = 0; j < b; j++)
		{
			scanf("%d", &series[j]);
		}
		katas = "";
		getline(cin, katas);
		getline(cin, katas);
		k = 0;
		for (int j = 0;j < b;j++) {
			left = 0;
			right = fibos.size();
			target = series[j];
			while (left <= right) {
				mid = (right + left) / 2;
				if (fibos[mid] == target) {
					while (!isalpha(katas.at(k)) || !isupper(katas.at(k)))k++;
					ans[mid] = katas.at(k);
					k++;
					break;
				}
				else if (fibos[mid] > target) {
					right = mid - 1;
				}
				else if (fibos[mid] < target) {
					left = mid + 1;
				}
			}

		}
		for (int j = 0; j < b; j++)
		{
			if (ans[j] == ' ')b++;
			printf("%c", ans[j]);
		}
		if (i != a - 1) {
			printf("\n");
		}
	}
	return 0;
}

Post Reply

Return to “Volume 113 (11300-11399)”