Submission #374846

#TimeUsernameProblemLanguageResultExecution timeMemory
374846valerikkXylophone (JOI18_xylophone)C++17
100 / 100
130 ms620 KiB
/* doing virtual contest start: 10:00 finish: 14:00 */ #include <bits/stdc++.h> using namespace std; int query(int s, int t); void answer(int i, int a); #ifndef EVAL const int N_ = 5007; int n_; int a_[N_], ans_[N_]; int query(int s, int t) { int mn = n_, mx = 1; for (int i = s; i <= t; ++i) { mn = min(mn, a_[i]); mx = max(mx, a_[i]); } return mx - mn; } void answer(int i, int a) { if (i < 1 || i > n_) { cout << "incorrect index " << i << endl; exit(0); } if (ans_[i] != -1) { cout << i << " used twice" << endl; exit(0); } ans_[i] = a; } void check_ans() { bool corr = 1; for (int i = 1; i <= n_; ++i) corr &= a_[i] == ans_[i]; if (!corr) { cout << "incorrect" << endl; for (int i = 1; i <= n_; ++i) cout << a_[i] << " "; cout << endl; for (int i = 1; i <= n_; ++i) cout << ans_[i] << " "; cout << endl; } else { cout << "correct\n"; } } void init(int n, vector<int> a) { n_ = n; for (int i = 1; i <= n; ++i) { a_[i] = a[i - 1]; ans_[i] = -1; } } #endif void solve(int n) { vector<int> a(n + 1, -1); a[1] = 0; if (2 <= n) a[2] = query(1, 2); for (int i = 3; i <= n; ++i) { int x = a[i - 2], y = a[i - 1]; int d = query(i - 1, i); if (abs(x - y) + d == query(i - 2, i)) { a[i] = y < x ? y - d : y + d; } else { a[i] = y < x ? y + d : y - d; } } int mn = (int)1e9; for (int i = 1; i <= n; ++i) mn = min(mn, a[i]); for (int i = 1; i <= n; ++i) a[i] += -mn + 1; int pos1 = -1, posn = -1; for (int i = 1; i <= n; ++i) { if (a[i] == 1) pos1 = i; if (a[i] == n) posn = i; } if (pos1 > posn) { for (int i = 1; i <= n; ++i) a[i] = n - a[i] + 1; } for (int i = 1; i <= n; ++i) answer(i, a[i]); } #ifndef EVAL int main() { freopen("input.txt", "r", stdin); ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; init(n, a); solve(n); check_ans(); return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...