Submission #1254419

#TimeUsernameProblemLanguageResultExecution timeMemory
1254419badge881Xylophone (JOI18_xylophone)C++20
100 / 100
26 ms448 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; void solve(int N) { int t1, t2, t3, t4; vector<int> wentup; wentup.push_back(0); wentup.push_back(0); t1 = query(1, 2); wentup.push_back(t1); for (int a = 3; a <= N; a++) { t1 = query(a - 1, a); t2 = query(a - 2, a); if (abs(t1 - t2) == abs(wentup[a - 2] - wentup[a - 1])) t1 *= (wentup[a - 2] < wentup[a - 1] ? 1 : -1); else t1 *= (wentup[a - 2] < wentup[a - 1] ? -1 : 1); wentup.push_back(wentup[a - 1] + t1); } pair<int, int> maxval = make_pair(INT_MIN, 0), minval = make_pair(INT_MAX, 0); for (int a = 1; a <= N; a++) { maxval = max(maxval, make_pair(wentup[a], a)); minval = min(minval, make_pair(wentup[a], a)); } int smallest, mul; if (maxval.second < minval.second) { mul = -1; smallest = maxval.second; } else { mul = 1; smallest = minval.second; } for (int a = 1; a <= N; a++) wentup[a] *= mul; vector<int> ans(N + 1); for (int a = 1; a <= N; a++) { t1 = 1 + wentup[a] - wentup[smallest]; ans[a] = t1; } for (int a = 1; a <= N; a++) answer(a, ans[a]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...