Submission #381177

#TimeUsernameProblemLanguageResultExecution timeMemory
381177vishesh312Xylophone (JOI18_xylophone)C++17
100 / 100
193 ms98544 KiB
#include "bits/stdc++.h" #include "xylophone.h" using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; */ #define all(x) begin(x), end(x) #define sz(x) (int)x.size() using ll = long long; const int mod = 1e9+7; void solve(int n) { vector<vector<int>> diff(n+1, vector<int>(n+1)); for (int i = 1; i < n; ++i) { diff[i][i+1] = query(i, i+1); } for (int i = 1; i < n-1; ++i) { diff[i][i+2] = query(i, i+2); } vector<int> rel(n); rel[1] = diff[1][2]; bool inc = true; for (int i = 2; i < n; ++i) { inc ^= (diff[i-1][i] + diff[i][i+1] != diff[i-1][i+1]); rel[i] = rel[i-1] + diff[i][i+1] * (inc?1:-1); } array<int, 2> mx = {0, 0}, mn = {0, 0}; for (int i = 1; i < n; ++i) { if (rel[i] > mx[0]) { mx = {rel[i], i}; } if (rel[i] < mn[0]) { mn = {rel[i], i}; } } if (mn[1] < mx[1]) { for (int i = 0; i < n; ++i) { answer(i+1, rel[i] - mn[0] + 1); } } else { for (int i = 0; i < n; ++i) { answer(i+1, mx[0] - rel[i] + 1); } } } /* signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; //cin >> tc; for (int i = 1; i <= tc; ++i) solve(i); return 0; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...