Submission #132253

#TimeUsernameProblemLanguageResultExecution timeMemory
132253RezwanArefin01Xylophone (JOI18_xylophone)C++17
0 / 100
3 ms248 KiB
#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std; 

const int MAX = 5010;
int a[MAX], d[MAX], t[MAX], dir[MAX];

void solve(int n) {
    for(int i = 1; i + 1 <= n; ++i) {
        d[i] = query(i, i + 1); 
    }
    for(int i = 1; i + 2 <= n; ++i) {
        t[i] = query(i, i + 2);
    }   

    d[0] = 1; 
    for(int i = 1; i <= n; ++i) {
        if(d[i] + d[i + 1] == t[i]) {
            dir[i + 1] = dir[i];
        } else {
            dir[i + 1] = dir[i] ^ 1;
        }
        a[i] = a[i - 1] + (dir[i] ? d[i - 1] : -d[i - 1]); 
    }

    int mn = 1, mx = 1; 
    for(int i = 1; i <= n; ++i) {
        if(a[i] < a[mn]) mn = i; 
        if(a[i] > a[mx]) mx = i;
    }   

    int x = a[mn];
    for(int i = 1; i <= n; ++i) {
        a[i] = a[i] - x + 1; 
    }

    if(mn > mx) {
        for(int i = 1; i <= n; ++i) {
            a[i] = n - a[i] + 1; 
        }
    }

    for(int i = 1; i <= n; ++i) {
        answer(i, a[i]);
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...