CSES - Aalto Competitive Programming 2024 - wk2 - Wed - Results
Submission details
Task:LibBot
Sender:aalto2024b_005
Submission time:2024-09-11 17:42:41 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:88:9: error: redeclaration of 'int l'
   88 |     int l=1, r=N;
      |         ^
input/code.cpp:76:9: note: 'int l' previously declared here
   76 |     int l=1, r=N;
      |         ^
input/code.cpp:88:14: error: redeclaration of 'int r'
   88 |     int l=1, r=N;
      |              ^
input/code.cpp:76:14: note: 'int r' previously declared here
   76 |     int l=1, r=N;
      |              ^
input/code.cpp: In function 'void Test()':
input/code.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("temp\\in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp: In function 'int Check(int)':
input/code.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
   62 | }
      | ^
input/code.cpp: In function 'int main()':
input/code.cpp:67:10: warning: ignoring r...

Code

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<sstream>
typedef long long LL;

using std::cin;
using std::cout;
using std::string;

void Test()
{
    freopen("temp\\in.txt", "r", stdin);
} 

int n, N;
string s, model;

void Input()
{
    cin.ignore(6);
    cin>>s;
}

int ToNum(string t)
{
    int x, ret;
    for(int i=1; i<=n; i++)
    {
        std::stringstream(t)>>x;    
        int t = 1;
        for(int j=1; j<=i; j++)
            t*=x;
        ret += t;
    }
    return ret;
}
string ToStr(int x)
{
    string ret;
    while(x)
    {
        int t = x%n;
        ret = ret+"."+std::to_string(t);
        x/=n;
    }
    return ret;
}

int Check(int num)
{
    cout<<"FETCH "+ToStr(num)<<std::endl;

    Input();
    if(s < model)
        return -1;
    if(s > model)
        return 1;
    if(s == model)
        return 0;
}

int main()
{
    // Test();
    scanf("SIZE %d\n", &n);
    N = 1;
    for(int i=1; i<=n; i++)
        N*=n;
    Input();
    model = s;

    int L, R;
    // find left
    int l=1, r=N;
    while(l<r)
    {
        int mid = (l+r)/2;
        if(Check(mid) == -1)
            l=mid+1;
        else
            r=mid;
    }
    L = l;

    // find right
    int l=1, r=N;
    while(l<r)
    {
        int mid = (l+r)/2;
        if(Check(mid) != 1)
            l=mid+1;
        else
            r=mid;
    }
    R = l-1;

    printf("%d", R-L);

    return 0;
}