Submission #1175230

#TimeUsernameProblemLanguageResultExecution timeMemory
1175230nguyenkhangninh99Xylophone (JOI18_xylophone)C++17
100 / 100
26 ms460 KiB

#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std;

void solve(int N){
    int n = N;
    if(n == 2){
        answer(1, 1);
        answer(2, 2);
    }
    else{
        vector<int> diff(n + 1), ans(n + 1);
        for(int i = 1; i < n; i++) diff[i] = query(i, i + 1);
        
        ans[2] = diff[1];
        
        int pos = -1, mn = n + 1, cur = 1;

        for(int i = 3; i <= n; i++){
            if(query(i - 2, i) != diff[i - 1] + diff[i - 2]) cur *= -1;
            ans[i] = ans[i - 1] + diff[i - 1] * cur;
        }
        
        for(int i = 1; i <= n; i++){
            if(ans[i] < mn){
                mn = ans[i];
                pos = i;
            }
        }

        bool ok = 0;
        for(int i = pos + 1; i <= n; i++) ok |= (ans[i] == mn + n - 1);
        if(!ok){
            mn = n + 1;
            for(int i = 1; i <= n; i++) mn = min(mn, -ans[i]);
        }
    
        for(int i = 1; i <= n; i++){
          if(!ok) ans[i] = -ans[i];
          answer(i,  ans[i] - mn + 1);
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...