Submission #210309

#TimeUsernameProblemLanguageResultExecution timeMemory
210309joylintpXylophone (JOI18_xylophone)C++14
100 / 100
105 ms412 KiB
#include"xylophone.h"
#include<bits/stdc++.h>
using namespace std;

void solve(int n)
{
    if (n == 2)
    {
        answer(1, 1), answer(2, 2);
        return;
    }

	int d[5001], e[5001];
	for (int i = 1; i <= n - 1; i++)
        d[i] = query(i, i + 1);
    for (int i = 1; i <= n - 2; i++)
        e[i] = query(i, i + 2);

    bool pp;
    int ans[5001];
    ans[1] = 1, ans[2] = ans[1] + d[1];
    if (d[1] + d[2] == e[1])
        ans[3] = ans[2] + d[2], pp = true;
    else
        ans[3] = ans[2] - d[2], pp = false;

    for (int i = 4; i <= n; i++)
        if (d[i - 2] + d[i - 1] == e[i - 2])
            if (pp)
                ans[i] = ans[i - 1] + d[i - 1];
            else
                ans[i] = ans[i - 1] - d[i - 1];
        else
            if (pp)
                ans[i] = ans[i - 1] - d[i - 1], pp = false;
            else
                ans[i] = ans[i - 1] + d[i - 1], pp = true;

    int mn = 1e9;
    for (int i = 1; i <= n; i++)
        mn = min(mn, ans[i]);
    for (int i = 1; i <= n; i++)
        ans[i] += -mn + 1;

    bool ok;
    for (int i = 1; i <= n; i++)
        if (ans[i] == 1)
        {
            ok = true;
            break;
        }
        else if (ans[i] == n)
        {
            ok = false;
            break;
        }
        else;

    if (!ok)
        for (int i = 1; i <= n; i++)
            ans[i] = n - ans[i] + 1;

    for (int i = 1; i <= n; i++)
        answer(i, ans[i]);
}

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:59:5: warning: 'ok' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if (!ok)
     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...