제출 #516093

#제출 시각아이디문제언어결과실행 시간메모리
516093lovrotXylophone (JOI18_xylophone)C++11
0 / 100
0 ms200 KiB
#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std;
 
vector<int> rj(5000);
 
int ask(int s, int t){
    return query(s + 1, t + 1);
}

void solve(int n){
    rj[0] = 0;
    rj[1] = rj[0] + ask(0, 1);

    for(int i = 0; i + 2 < n; i++){
        int cur = abs(rj[i] - rj[i + 1]);
        int c = ask(i, i + 2);
        if(c == cur){
            int d = ask(i + 1, i + 2);
            if(rj[i + 1] > rj[i]){
                rj[i + 2] = rj[i + 1] - d;
            }
            else{
                rj[i + 2] = rj[i + 1] + d;
            }
        }
        else{
            int d = ask(i + 1, i + 2);
            if(c == d){
                if(rj[i + 1] > rj[i]){
                    rj[i + 2] = rj[i + 1] - c;
                }
                else{
                    rj[i + 2] = rj[i + 1] + c;
                }
            }
            else{
                if(rj[i] > rj[i + 1]){
                    rj[i + 2] = rj[i] - c;
                }
                else{
                    rj[i + 2] = rj[i] + c;
                }
            }
        }
    }
    int mn = 0, mx = 0;
    for(int i = 0 ; i < n ; i++){
        if(rj[i] < rj[mn]) mn = i;
        if(rj[i] > rj[mx]) mx = i;
    }
    if(mx < mn){
        for(int i : rj){
            i *= -1;
        }
    }
    mn = 1e9;
    for(int i : rj) mn = min(mn, i);
    for(int i : rj) i = i - mn + 1;
    for(int i = 0 ; i < n ; i++){
        answer(i + 1, rj[i]);
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...