Submission #575062

#TimeUsernameProblemLanguageResultExecution timeMemory
575062MadokaMagicaFanXylophone (JOI18_xylophone)C++14
0 / 100
1 ms296 KiB
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
const ll inf = 1e9;
const int md1 = 1e9+7;
const int md2 = 998244353;

#define sz(v)                       ((int)v.size())
#define pb                          push_back

#define pry                         cout << "YES\n"
#define prn                         cout << "NO\n"
#define endl                        '\n'

#define fst                         first
#define scn                         second

int query(int s, int t);
void answer(int i, int a);

void
solve(int n)
{
    if (n < 3) {
        for (int i = 0; i < n; ++i)
            answer(i+1,i+1);
        return;
    }
    vector<int> ans(n,1);
    bool bigger = 1;

    int dif1 = query(1,2);
    int dif2 = query(1,3);
    int dif3;
    ans[0] += dif1;


    for (int i = 1; i < n-1; ++i) {
        dif3 = query(i+1,i+2);
        if (dif3 + dif1 != dif2) 
            bigger = !bigger;

        if (bigger) {
            ans[i+1] = ans[i]-dif3;
            if (ans[i+1] < 1) {
                dif1 = 1 - ans[i+1];
                for (int j = 0; j < i+2; ++j) {
                    ans[j] += dif1;
                }
            }
        } else {
            ans[i+1] = ans[i] + dif3;
        }

        dif1 = dif3;
        for (int i = 0; i < n; ++i) {
            cout << ans[i] << ' ';
        }
        cout << endl;
        if (i < n-1)
            dif2 = query(i+1,i+3);
    }

    int p1, pn;

    for (int i = 0; i < n; ++i) {
        if (ans[i] == 1)
            p1 = i;
        if (ans[i] == n)
            pn = i;
    }

    if (pn < p1) {
        for (int i = 0; i < n; ++i) {
            ans[i] = n + 1 - ans[i];
        }
    }

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

    return;
}


#ifdef ONPC
const int N = 5e3;
vector<int> ra;
bitset<N> c;

void
answer(int i, int a)
{
    cout << a << ' ';
    --i;
    if (ra[i] == a)
        c[i] = 1;
}

int
query(int s, int t)
{
    --s;
    int mn,mx;
    mn = inf;
    mx = 0;
    for (int i = s; i < t; ++i) {
        mn = min(mn,ra[i]);
        mx = max(mx,ra[i]);
    }

    printf("Query %d %d %d\n", s+1,t,mx-mn);
    return mx - mn;
}

void
rezolvare()
{
    int n;
    cin >> n;

    ra.resize(n);
    for (int i = 0; i < n; ++i)
        cin >> ra[i];

    solve(n);
}

int32_t
main(int argc, char **argv)
{
    if (argc >= 2) {
        freopen(argv[1], "r", stdin);
    } else
        ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    /* cin >> t; */
    while(t--)
        rezolvare();
}
#endif

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:75:5: warning: 'pn' may be used uninitialized in this function [-Wmaybe-uninitialized]
   75 |     if (pn < p1) {
      |     ^~
xylophone.cpp:75:5: warning: 'p1' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...