Submission #751689

#TimeUsernameProblemLanguageResultExecution timeMemory
751689sofija6Xylophone (JOI18_xylophone)C++14
47 / 100
2751 ms712 KiB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;
static int A[5000];

void solve(int N) {
    int diff2[N+2],diff3[N+2];
    for (int i=1;i<N;i++)
    {
        if (i<N-1)
            diff3[i]=query(i,i+2);
        diff2[i]=query(i,i+1);
    }
    for (int i=1;i<=N;i++)
    {
        int cur=1;
        A[1]=i;
        for (int j=2;j<=N;j++)
        {
            if (j>2 && N>2 && diff3[j-2]!=diff2[j-2]+diff2[j-1])
                cur*=(-1);
            A[j]=A[j-1]+diff2[j-1]*cur;
        }
        set<int> s;
        bool yes=true;
        for (int j=1;j<=N;j++)
        {
            if (A[j]<=N && A[j]>=1)
            {
                if (A[j]==N && !s.count(1))
                    yes=false;
                s.insert(A[j]);
            }
        }
        if (s.size()==N && yes)
        {
            for (int j=1;j<=N;j++)
                answer(j,A[j]);
            return;
        }
        yes=true;
        s.clear();
        cur=-1;
        for (int j=2;j<=N;j++)
        {
            if (j>2 && N>2 && diff3[j-2]!=diff2[j-2]+diff2[j-1])
                cur*=(-1);
            A[j]=A[j-1]+diff2[j-1]*cur;
        }
        for (int j=1;j<=N;j++)
        {
            if (A[j]<=N && A[j]>=1)
            {
                if (A[j]==N && !s.count(1))
                    yes=false;
                s.insert(A[j]);
            }
        }
        if (s.size()==N && yes)
        {
            for (int j=1;j<=N;j++)
                answer(j,A[j]);
            return;
        }
    }
}

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:36:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |         if (s.size()==N && yes)
      |             ~~~~~~~~^~~
xylophone.cpp:60:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |         if (s.size()==N && yes)
      |             ~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...