Submission #566111

#TimeUsernameProblemLanguageResultExecution timeMemory
566111RifalXylophone (JOI18_xylophone)C++14
100 / 100
94 ms1076 KiB
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 32768
#define INF 100000000000000
//#define ll long long
//#define cin fin
//#define cout fout
using namespace std;
//ofstream fout("convention.out");
//ifstream fin("convention.in");
#include "xylophone.h"
static int A[5000];
map<pair<int,int>,int> mp;
void dif(int n)
{
    for(int i = 1; i < n; i++)
    {
        mp[{i,i+1}] = query(i,i+1);
    }
    for(int i = 1; i < n-1; i++)
    {
        mp[{i,i+2}] = query(i,i+2);
    }
}
void solve(int N) {

    dif(N);
	int arr[N+1];
	int mn = 1;
	arr[1] = 1;
	arr[2] = mp[{1,2}]+1;
	for(int i = 3; i <= N; i++)
    {
        if(mp[{i-2,i-1}]+mp[{i-1,i}] == mp[{i-2,i}])
        {
            if(arr[i-2] < arr[i-1])
            {
                arr[i] = arr[i-1]+mp[{i-1,i}];
            }
            else
            {
                arr[i] = arr[i-1]-mp[{i-1,i}];
            }
        }
        else
        {
            if(arr[i-2] < arr[i-1])
            {
                arr[i] = arr[i-1]-mp[{i-1,i}];
            }
            else
            {
                arr[i] = arr[i-1]+mp[{i-1,i}];
            }
        }
        mn = min(mn,arr[i]);
    }
    for(int i = 1; i <= N; i++)
    {
        if(mn == 1)
            break;
        arr[i] += abs(mn)+1;
    }
    bool good = false;
    for(int i = 1; i <= N; i++)
    {
        if(arr[i] == 1)
        {
            good = true;
            break;
        }
        else if(arr[i] == N)
        {
            break;
        }
    }
    if(!good)
    {
       for(int i = 1; i <= N; i++)
       {
           arr[i] = abs(arr[i]-N)+1;
       }
    }
    for(int i = 1; i <= N; i++)
    {
        answer(i,arr[i]);
    }

}

Compilation message (stderr)

xylophone.cpp:13:12: warning: 'A' defined but not used [-Wunused-variable]
   13 | static int A[5000];
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...