CSES - Datatähti 2023 alku - Results
Submission details
Task:Kertoma
Sender:FenixHongell
Submission time:2022-11-02 13:40:20 +0200
Language:C++11
Status:COMPILE ERROR

Compiler report

input/code.cpp:18:19: error: 'n' was not declared in this scope; did you mean 'yn'?
   18 | int binary_search(n, T) {
      |                   ^
      |                   yn
input/code.cpp:18:22: error: 'T' was not declared in this scope
   18 | int binary_search(n, T) {
      |                      ^
input/code.cpp:18:23: error: expression list treated as compound expression in initializer [-fpermissive]
   18 | int binary_search(n, T) {
      |                       ^
input/code.cpp: In function 'int main()':
input/code.cpp:70:30: error: 'binary_search' cannot be used as a function
   70 |         cout << binary_search(count, count) << endl;
      |                 ~~~~~~~~~~~~~^~~~~~~~~~~~~~
input/code.cpp:58:13: warning: unused variable 'n' [-Wunused-variable]
   58 |         int n = 7;
      |             ^

Code

#include <iostream>
#include <tgmath.h>

using namespace std;

int Count(int a, int b, int c, int d, int e, int f, int g, int h, int j, int k) {
    int num = a+b+c+d+e+f+g+h+j+k;
    return num;
}
int calcd(int num) {
    double digits = 0;
    for (int i = 2; i <= num; i++)
        digits += log10(i);
 
    return floor(digits) + 1;
}

int binary_search(n, T) {
    int L = 0;
    int R = n - 1;
    while (L <= R) {
        int m = floor((L + R) / 2);
        if (calcd(m) < T) {
            L = m + 1;
        }
        else if (calcd(m) > T) {
            R = m - 1;
        }
        else {
            return m;
        }
    }

    return 0;
}


int main() {
    int a,b,c,d,e,f,g,h,j,k;
    cin >> a >> b >> c >> d >> e >> f >> g >> h >> j >> k;
    if (a == 0 && b == 0 && c == 1 && d == 0 && e == 1 && f == 0 && g == 0 && h == 0 && j == 0 && k == 0) {
        cout << "4" << endl;
    }
    else if (a == 1 && b == 1 && c == 1 && d == 0 && e == 0 && f == 0 && g == 0 && h == 0 && j == 0 && k == 0) {
        cout << "5" << endl;
    }
    else if (a == 1 && b == 0 && c == 1 && d == 0 && e == 0 && f == 0 && g == 0 && h == 1 && j == 0 && k == 0) {
        cout << "6" << endl;
    }
    else if (a == 0 && b == 0 && c == 1 && d == 0 && e == 0 && f == 0 && g == 0 && h == 0 && j == 0 && k == 0) {
        cout << "2" << endl;
    }
    else if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0 && f == 0 && g == 1 && h == 0 && j == 0 && k == 0) {
        cout << "3" << endl;
    }
    else {
        int count = Count(a,b,c,d,e,f,g,h,j,k);
        int n = 7;
        /*
        if (a > 100) {
           n = floor(count/2);
        }
        while (true) {
            if (calcd(n) == count) {
                cout << n << endl;
                break;
            }
            n += 1;
        }*/
        cout << binary_search(count, count) << endl;
    }
}