Submission #394162

# Submission time Handle Problem Language Result Execution time Memory
394162 2021-04-26T02:23:06 Z Osama_Alkhodairy Xylophone (JOI18_xylophone) C++17
0 / 100
1 ms 200 KB
#include <bits/stdc++.h>
#include "xylophone.h"
//~ #include "grader.cpp"
using namespace std;

static int A[5000];

int ask(int s, int t){
    return query(s + 1, t + 1);
}
void solve(int n){
    vector <int> a(n);
    a[0] = 0;
    a[1] = a[0] + ask(0, 1);
    for(int i = 0 ; i + 2 < n ; i++){
        int cur = abs(a[i] - a[i + 1]);
        int c = ask(i, i + 2);
        if(c == cur){
            int d = ask(i + 1, i + 2);
            if(a[i + 1] > a[i]){
                a[i + 2] = a[i + 1] - d;
            }
            else{
                a[i + 2] = a[i + 1] + d;
            }
        }
        else{
            int d = ask(i + 1, i + 2);
            if(c == d){
                if(a[i + 1] > a[i]){
                    a[i + 2] = a[i + 1] - d;
                }
                else{
                    a[i + 2] = a[i + 1] + d;
                }
            }
            else{
                if(a[i] > a[i + 1]){
                    a[i + 2] = a[i] - d;
                }
                else{
                    a[i + 2] = a[i] + d;
                }
            }
        }
    }
    int mn = 0, mx = 0;
    for(int i = 0 ; i < n ; i++){
        if(a[i] < a[mn]) mn = i;
        if(a[i] > a[mx]) mx = i;
    }
    if(mx < mn){
        for(auto &i : a){
            i *= -1;
        }
    }
    mn = 1e9;
    for(auto &i : a) mn = min(mn, i);
    for(auto &i : a) i = i - mn + 1;
    for(int i = 0 ; i < n ; i++){
        answer(i + 1, a[i]);
    }
}

Compilation message

xylophone.cpp:6:12: warning: 'A' defined but not used [-Wunused-variable]
    6 | static int A[5000];
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Incorrect 1 ms 200 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Incorrect 1 ms 200 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Incorrect 1 ms 200 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -