0

Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?

A sequence a is a subsequence of an array b if a can be obtained from b by deletion of several (possibly, zero or all) elements. The longest increasing subsequence of an array is the longest subsequence such that its elements are ordered in strictly increasing order.

heres my answer, I keep getting "the system cannot find the file specified" whats wrong?

enter image description here

#include <algorithm>
#include <iostream>
    using namespace std;
    int main(){
        int t, n;
        cin >> t;

        while(t != 0){
            cin >> n;
            int* a = new int [n];
            cin >> a[0];
            int min = a[0];

            for (int i = 1 ; i < n ; i++){
                cin >> a [i];
                if (min > a[i])
                    min = a[i];
            }

            int* b = new int [n*n];
            for (int i = 0 ; i < n*n ; i++)
                copy(a[0], b[n-1], b[i*n]);

            int num = 0;
            for (int i = 0 ; i < n*n ; i++)
                if (b[i] == min){
                    for (int j = i+1 ; j < n*n ; j++){
                        if (b[j] > b[i]){
                            num++;
                            j = i;
                        }
                    break;
                    }
                }
            cout << num << endl;
            t--;
        }
    }
Zohal
  • 25
  • 5
  • So when you get this message, what are you actually trying to do? It help to explain where the error message comes from., e.g. what tools you are using to compile and run that program. The only problem with the code I can quickly see, is that you are missing `#include `, which is necessary to use `copy`. – john Mar 21 '20 at 17:13
  • That error can't be produced by that program. Are you launching from an IDE, but there were compilation errors? – molbdnilo Mar 21 '20 at 17:14
  • Im using visual studio 2012, and when I posted this answer in code forces I got a compilation error @molbdnilo – Zohal Mar 21 '20 at 17:22
  • I dont think #include is needed since Im not getting any syntax errors, but I added it anyway, didnt solve the problem @john – Zohal Mar 21 '20 at 17:24
  • 2
    Your code has nothing related to file manipulation, so it's a problem related to the compiler/linker. if possible, post an image that shows the actual error and the command you used to procuce it. – jweyrich Mar 21 '20 at 17:31
  • @jweyrich I just added an image, Im using visual studio 2012 and when I posted the code on codeforces, I got a compilation error – Zohal Mar 21 '20 at 18:33
  • 1
    you code isn't compiling so there is no executable to run, see "0 succeeded, 1 failed" in the build output. You probably had a message like "build failed, do you want to run the last successful build". Look in the build output for the error causing your build to fail – Alan Birtles Mar 21 '20 at 18:36
  • I'm not sure what `copy(a[0], b[n-1], b[i*n])` is supposed to do but it is probably the cause of your compilation failure, `std::copy` takes iterators or pointers, you are passing numbers. – Alan Birtles Mar 21 '20 at 18:40
  • @AlanBirtles how am I using numbers? they are arrays, please give me an example of how to use them as pointers. copy function is supposed to take the begining and ending of an array and the begining of another array and then copy the first one in the second one. – Zohal Mar 21 '20 at 19:11
  • `a` is an array, `a[0]` is a number in that array. If you want a pointer to an array element at index `x` you can use `&a[x]` or `a + x`. Also note that `std::copy` takes 2 input iterators and 1 output iterator, looks like you're trying to pass 1 input and 2 outputs – Alan Birtles Mar 21 '20 at 19:35
  • @AlanBirtles that was the problem! Thank u – Zohal Mar 21 '20 at 20:02

0 Answers0