Submission #1015792

# Submission time Handle Problem Language Result Execution time Memory
1015792 2024-07-06T19:28:34 Z ivaziva Xylophone (JOI18_xylophone) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#define MAXN 5010

int razlike[MAXN];
int ans1[MAXN],ans2[MAXN];

void solve(int N)
{
    for (int i=1;i<N;i++) razlike[i]=query(i,i+1);
    ans1[1]=0,ans2[1]=0;ans1[2]=razlike[1],ans2[2]=razlike[1]*(-1);
    for (int i=3;i<=N;i++)
    {
        int sol=query(i-2,i);
        if (sol==razlike[i-2]+razlike[i-1])
        {
            if (ans1[i-2]>ans1[i-1]) ans1[i]=ans1[i-1]-razlike[i-1];
            else ans1[i]=ans1[i-1]+razlike[i-1];
            if (ans2[i-2]>ans2[i-1]) ans2[i]=ans2[i-1]-razlike[i-1];
            else ans2[i]=ans2[i-1]+razlike[i-1];
        }
        else
        {
            if (ans1[i-2]>ans1[i-1]) ans1[i]=ans1[i-1]+razlike[i-1];
            else ans1[i]=ans1[i-1]-razlike[i-1];
            if (ans2[i-2]>ans2[i-1]) ans2[i]=ans2[i-1]+razlike[i-1];
            else ans2[i]=ans2[i-1]-razlike[i-1];
        }
    }
    int mini1=INT_MAX,mini2=INT_MAX;
    for (int i=1;i<=N;i++) mini1=min(mini1,ans1[i]);
    for (int i=1;i<=N;i++) mini2=min(mini2,ans2[i]);
    int dodajemo1=1-mini1,dodajemo2=1-mini2;
    for (int i=1;i<=N;i++) ans1[i]+=dodajemo1;
    for (int i=1;i<=N;i++) ans2[i]+=dodajemo2;
    int maksi1=-INT_MAX,maksi2=-INT_MAX;
    for (int i=1;i<=N;i++) maksi1=max(maksi1,ans1[i]);
    for (int i=1;i<=N;i++) maksi2=max(maksi2,ans2[i]);
    if (maksi1==N)
    {
        int poz1,pozN;
        for (int i=1;i<=N;i++)
        {
            if (ans1[i]==1) poz1=i;
            if (ans1[i]==N) pozN=i;
        }
        if (poz1>pozN)
        {
            for (int i=1;i<=N;i++) ans1[i]=N-ans1[i]+1;
        }
        for (int i=1;i<=N;i++) answer(i,ans1[i]);
    }
    else
    {
        int poz1,pozN;
        for (int i=1;i<=N;i++)
        {
            if (ans2[i]==1) poz1=i;
            if (ans2[i]==N) pozN=i;
        }
        if (poz1>pozN)
        {
            for (int i=1;i<=N;i++) ans2[i]=N-ans2[i]+1;
        }
        for (int i=1;i<=N;i++) answer(i,ans2[i]);
    }
};

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:12:38: error: 'query' was not declared in this scope
   12 |     for (int i=1;i<N;i++) razlike[i]=query(i,i+1);
      |                                      ^~~~~
xylophone.cpp:16:17: error: 'query' was not declared in this scope
   16 |         int sol=query(i-2,i);
      |                 ^~~~~
xylophone.cpp:53:32: error: 'answer' was not declared in this scope
   53 |         for (int i=1;i<=N;i++) answer(i,ans1[i]);
      |                                ^~~~~~
xylophone.cpp:67:32: error: 'answer' was not declared in this scope
   67 |         for (int i=1;i<=N;i++) answer(i,ans2[i]);
      |                                ^~~~~~